Skip to content

Commit

Permalink
fix: check server role in direct message
Browse files Browse the repository at this point in the history
  • Loading branch information
namnhce committed Oct 9, 2024
1 parent 1955ebd commit f74b30b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/discord/command/mma/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/discord/command/project/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions pkg/discord/service/profile/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/discord/service/profile/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions pkg/discord/service/project/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions pkg/discord/service/project/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions pkg/model/brainery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit f74b30b

Please sign in to comment.