Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maisnamraju committed Jun 13, 2021
1 parent d9e74c2 commit c16867d
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ func (p *Plugin) hasSysadminRole(userID string) (bool, error) {
return true, nil
}

func (p *Plugin) hasChannelAdminRole(channelID string, userID string) (bool, error) {
channel, err := p.API.GetChannel(channelID)
if err != nil {
return false, err
}
if channel.CreatorId != userID {
return false, nil
}
return true, nil
}

func (p *Plugin) validateCommand(action string, parameters []string) string {
switch action {
case commandTriggerPreview:
Expand Down Expand Up @@ -225,14 +236,26 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
return &model.CommandResponse{}, nil
}

isSysadmin, err := p.hasSysadminRole(args.UserId)
if err != nil {
p.postCommandResponse(args, "authorization failed: %s", err)
return &model.CommandResponse{}, nil
}
if !isSysadmin {
p.postCommandResponse(args, "/welcomebot commands can only be executed by the user with system admin role")
return &model.CommandResponse{}, nil
if action == commandTriggerSetChannelWelcome || action == commandTriggerGetChannelWelcome || action == commandTriggerDeleteChannelWelcome {
isChannelAdmin, err := p.hasChannelAdminRole(args.ChannelId, args.UserId)
if err != nil {
p.postCommandResponse(args, "authorization failed: %s", err)
return &model.CommandResponse{}, nil
}
if !isChannelAdmin {
p.postCommandResponse(args, "/%s commands can only be executed by the user with channel admin role", action)
return &model.CommandResponse{}, nil
}
} else {
isSysadmin, err := p.hasSysadminRole(args.UserId)
if err != nil {
p.postCommandResponse(args, "authorization failed: %s", err)
return &model.CommandResponse{}, nil
}
if !isSysadmin {
p.postCommandResponse(args, "/welcomebot commands can only be executed by the user with system admin role")
return &model.CommandResponse{}, nil
}
}

switch action {
Expand Down

0 comments on commit c16867d

Please sign in to comment.