diff --git a/pkg/discord/command/mma/base.go b/pkg/discord/command/mma/base.go index 38f0782..002e45c 100644 --- a/pkg/discord/command/mma/base.go +++ b/pkg/discord/command/mma/base.go @@ -56,6 +56,7 @@ func (e *MMACmd) DefaultCommand(message *model.DiscordMessage) error { } func (e *MMACmd) PermissionCheck(message *model.DiscordMessage) (bool, []string) { + if e.cfg.Env != "prod" { return true, nil } diff --git a/pkg/discord/command/project/base.go b/pkg/discord/command/project/base.go index 55b46f3..eef393a 100644 --- a/pkg/discord/command/project/base.go +++ b/pkg/discord/command/project/base.go @@ -57,5 +57,14 @@ func (e *ProjectCmd) PermissionCheck(message *model.DiscordMessage) (bool, []str return true, []string{} } - return permutil.CheckSmodOrAbove(message.Roles) + userRoles, err := e.svc.Profile().GetDiscordRoles(e.cfg.Discord.ID.DwarvesGuild, message.Author.ID) + if err != nil { + return false, []string{} + } + + var roles []string + roles = append(roles, userRoles...) + roles = append(roles, message.Roles...) + + return permutil.CheckSmodOrAbove(roles) } diff --git a/pkg/discord/service/profile/get.go b/pkg/discord/service/profile/get.go index 1d13629..c14cfac 100644 --- a/pkg/discord/service/profile/get.go +++ b/pkg/discord/service/profile/get.go @@ -23,3 +23,11 @@ func (e *Profile) GetEmployeeList(in EmployeeSearch) ([]model.Employee, error) { return rs, nil } + +func (e *Profile) GetDiscordRoles(guildID string, userID string) (rs []string, err error) { + gm, err := e.ses.GuildMember(guildID, userID) + if err != nil { + return nil, err + } + return gm.Roles, nil +} diff --git a/pkg/discord/service/profile/interface.go b/pkg/discord/service/profile/interface.go index 766a894..f3fe2fb 100644 --- a/pkg/discord/service/profile/interface.go +++ b/pkg/discord/service/profile/interface.go @@ -23,4 +23,5 @@ func New(adapter adapter.IAdapter, l logger.Logger, ses *discordgo.Session) Serv type Service interface { GetEmployeeList(in EmployeeSearch) (rs []model.Employee, err error) + GetDiscordRoles(guildID string, userID string) (rs []string, err error) } diff --git a/pkg/discord/service/project/interface.go b/pkg/discord/service/project/interface.go index d996525..0df6efb 100644 --- a/pkg/discord/service/project/interface.go +++ b/pkg/discord/service/project/interface.go @@ -5,4 +5,5 @@ import "github.com/dwarvesf/fortress-discord/pkg/model" type ProjectServicer interface { GetListMilestone(q string) ([]*model.ProjectMilestone, error) GetCommissionModels(projectID string) ([]model.ProjectCommissionModel, error) + GetProjectList() ([]model.Project, error) } diff --git a/pkg/discord/service/project/milestone.go b/pkg/discord/service/project/milestone.go index 00e3768..4e10d72 100644 --- a/pkg/discord/service/project/milestone.go +++ b/pkg/discord/service/project/milestone.go @@ -31,3 +31,7 @@ func (e *Project) GetListMilestone(q string) ([]*model.ProjectMilestone, error) return milestones, nil } + +func (e *Project) GetProjectList() ([]model.Project, error) { + return nil, nil +} diff --git a/pkg/model/brainery.go b/pkg/model/brainery.go index 6ff09ac..5bd8c27 100644 --- a/pkg/model/brainery.go +++ b/pkg/model/brainery.go @@ -74,3 +74,14 @@ type ProjectCommissionModel struct { type ProjectCommissionModelsResponse struct { Data []ProjectCommissionModel `json:"data"` } + +type Project struct { + ID string `json:"id"` + Name string `json:"name"` + Code string `json:"code"` + Status string `json:"status"` +} + +type ProjectListResponse struct { + Data []Project `json:"data"` +}