Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MI-2697]:Fixed issue #41 to restrict user for channel related commands #1

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

const commandHelp = `* |/welcomebot preview [team-name] | - preview the welcome message for the given team name. The current user's username will be used to render the template.
* |/welcomebot list| - list the teams for which welcome messages were defined
* |/welcomebot list| - list the teams for which welcome messages were defined.
The following commands will only allowed to be run by system admins and users with permissions to manage channel roles. |set_channel_welcome|, |get_channel_welcome| and |delete_channel_welcome|.
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
* |/welcomebot set_channel_welcome [welcome-message]| - set the welcome message for the given channel. Direct channels are not supported.
* |/welcomebot get_channel_welcome| - print the welcome message set for the given channel (if any)
* |/welcomebot delete_channel_welcome| - delete the welcome message for the given channel (if any)
Expand Down Expand Up @@ -218,8 +219,14 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
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 {
hasPermissionTo := p.API.HasPermissionToChannel(args.UserId, args.ChannelId, model.PermissionManageChannelRoles)

Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
if !hasPermissionTo {
p.postCommandResponse(args, "The `/welcomebot %s` command can only be executed by system admins and channel admins.", action)
return &model.CommandResponse{}, nil
}
}
}

switch action {
Expand Down