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

[MM-133] Added a feature of restricting bot messages to private channels and DM/GMs #337

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d3a7688
[MM-133] Work on zoom feature of restricting bot messages to private …
ayusht2810 Jan 17, 2024
672f29a
[MM-133] Add role on channel-settings slash command
ayusht2810 Jan 17, 2024
1fb2e67
[MM-133] Update readme and help text slash command on basis of user role
ayusht2810 Jan 17, 2024
0c51cfb
[MM-133] Fix lint issues
ayusht2810 Jan 17, 2024
fdc98fc
[MM-133] Update dialog text
ayusht2810 Jan 18, 2024
6837578
[MM-133] Review fixes: Update user statements and update if else cond…
ayusht2810 Jan 22, 2024
ecc3cf9
Merge branch 'master' into MM-133
ayusht2810 Feb 1, 2024
6c05f40
[MM-133] Update system console and some review fixes
ayusht2810 Feb 2, 2024
417a123
[MM-133] Add some test cases
ayusht2810 Feb 7, 2024
fe29a06
[MM-133] Updated a test case
ayusht2810 Feb 7, 2024
645f26f
Merge branch 'master' of github.com:mattermost/mattermost-plugin-zoom…
ayusht2810 Feb 27, 2024
2549a1e
[MM-133] Remove unused variable
ayusht2810 Feb 27, 2024
eb5981d
Merge branch 'master' of github.com:mattermost/mattermost-plugin-zoom…
ayusht2810 Apr 25, 2024
4c013a8
[MM-133]: review fixes
Kshitij-Katiyar Jun 6, 2024
ebc3bca
[MM-133]: fixed server testcases
Kshitij-Katiyar Jun 6, 2024
66fc89c
[MM-133]: updated the channel setting list values
Kshitij-Katiyar Jun 11, 2024
5ff77f7
[MM-133]: resolved conflict
Kshitij-Katiyar Jun 21, 2024
ad2e197
Merge branch 'master' of github.com:mattermost/mattermost-plugin-zoom…
raghavaggarwal2308 Jul 2, 2024
df05023
[MM-542] Review fixes:
raghavaggarwal2308 Jul 2, 2024
8583cac
[MM-542] Fixed confusion in channel settings modal
raghavaggarwal2308 Jul 2, 2024
5f0a6bf
[MM-546] Remove bin folder
raghavaggarwal2308 Jul 4, 2024
6eb844d
[MM-133] Fix issue of list empty incase of no setting is present
ayusht2810 Jul 15, 2024
8304f0a
Merge branch 'master' of github.com:mattermost/mattermost-plugin-zoom…
ayusht2810 Jul 15, 2024
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
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Select **Done** and then save your app.
* Select the **Regenerate** button next to the field **At Rest Token Encryption Key**.
* If you are using Webhooks or Deauthorization, make sure you select the **Regenerate** button on **Webhook Secret** field. Then set the **Zoom Webhook Secret** from the features page in your Zoom app.
* Select **Save**.
* Enable the **Restrict Bot Posting** configuration to restrict bot posting meeting links to only DM/GM and private channels.
* Enable the **Restrict User Posting** configuration to restrict user posting meeting links to only DM/GM and private channels.
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved

## User guide

Expand All @@ -218,21 +218,21 @@ Once enabled, selecting the video icon in a Mattermost channel invites team memb

### Slash commands

- `/zoom connect` :- This is used to connect your Mattermost account to your Zoom account.
- `/zoom connect` :- To connect your Mattermost account to your Zoom account.

- `/zoom disconnect` :- This is used to disconnect your Mattermost account from your Zoom account.
- `/zoom disconnect` :- To disconnect your Mattermost account from your Zoom account.

- `/zoom start [meeting topic]` :- This is used to start a Zoom meeting with the provided meeting topic.
- `/zoom start [meeting topic]` :- To start a Zoom meeting with the provided meeting topic.

- `/zoom settings` :- This is used to update Zoom meeting settings.
- `/zoom settings` :- To update Zoom meeting settings.

- `/zoom help` :- This is used to show help text for all the commands.
- `/zoom help` :- To show help text for all the commands.

### System admins only
##### System admins only

- `/zoom channel-settings` :- This is used to update channel preferences to restrict bot posting meetings to the current channel.
- `/zoom channel-settings` :- To update channel preferences to restrict user posting meetings to the current channel.
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved

- `/zoom channel-settings list` :- This is used to list the channel with updated preferences.
- `/zoom channel-settings list` :- To list the channel with updated preferences.


## Development
Expand Down
6 changes: 3 additions & 3 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
"default": null
},
{
"key": "RestrictBotPosting",
"display_name": "Restrict Bot Posting:",
"key": "RestrictUserPosting",
"display_name": "Restrict User Posting:",
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
"type": "bool",
"help_text": "Restrict bot posting meeting links to only DM/GM and private channels.",
"help_text": "Restrict user posting meeting links to only DM/GM and private channels.",
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
"regenerate_help_text": "",
"placeholder": "",
"default": false
Expand Down
33 changes: 19 additions & 14 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
settings = "settings"
actionChannelSettings = "channel-settings"
channelSettingsAction = "list"

actionUnkown = "Unknown Action"
)

func (p *Plugin) getCommand() (*model.Command, error) {
Expand Down Expand Up @@ -111,7 +113,7 @@ func (p *Plugin) executeCommand(c *plugin.Context, args *model.CommandArgs) (str
case actionChannelSettings:
return p.runChannelSettingsCommand(args, strings.Fields(args.Command)[2:], user)
default:
return fmt.Sprintf("Unknown action %v", action), nil
return fmt.Sprintf("%s %v", actionUnkown, action), nil
}
}

Expand Down Expand Up @@ -139,7 +141,7 @@ func (p *Plugin) runStartCommand(args *model.CommandArgs, user *model.User, topi
}

if restrict {
return "Creating zoom meeting is disabled for the channel.", nil
return "Creating zoom meeting is disabled for this channel.", nil
}

if _, appErr := p.API.GetChannelMember(args.ChannelId, user.Id); appErr != nil {
Expand Down Expand Up @@ -207,7 +209,7 @@ func (p *Plugin) runStartCommand(args *model.CommandArgs, user *model.User, topi

func (p *Plugin) runConnectCommand(user *model.User, extra *model.CommandArgs) (string, error) {
if !p.canConnect(user) {
return "Unknown action `connect`", nil
return fmt.Sprintf("%s `%s`", actionUnkown, actionConnect), nil
}

oauthMsg := fmt.Sprintf(
Expand Down Expand Up @@ -244,7 +246,7 @@ func (p *Plugin) runConnectCommand(user *model.User, extra *model.CommandArgs) (
// runDisconnectCommand runs command to disconnect from Zoom. Will fail if user cannot connect.
func (p *Plugin) runDisconnectCommand(user *model.User) (string, error) {
if !p.canConnect(user) {
return "Unknown action `disconnect`", nil
return fmt.Sprintf("%s `%s`", actionUnkown, actionDisconnect), nil
}

if p.configuration.AccountLevelApp {
Expand Down Expand Up @@ -289,24 +291,22 @@ func (p *Plugin) runSettingCommand(args *model.CommandArgs, params []string, use
}

if restrict {
return "Updating zoom settings is disabled for the current channel.", nil
return "Updating zoom settings is disabled for this current channel.", nil
}

if err := p.sendUserSettingForm(user.Id, args.ChannelId, args.RootId); err != nil {
return "", err
}
return "", nil
}
return fmt.Sprintf("Unknown Action %v", ""), nil
return actionUnkown, nil
}

func (p *Plugin) runChannelSettingsCommand(args *model.CommandArgs, params []string, user *model.User) (string, error) {
if !p.API.HasPermissionTo(args.UserId, model.PermissionManageSystem) {
return "Unable to execute the command, only system admins have access to execute this command.", nil
}

fmt.Print("\n\n ferf \n\n", p.botUserID)

if len(params) == 0 {
channel, appErr := p.API.GetChannel(args.ChannelId)
if appErr != nil {
Expand All @@ -328,7 +328,7 @@ func (p *Plugin) runChannelSettingsCommand(args *model.CommandArgs, params []str
Elements: []model.DialogElement{
{
DisplayName: fmt.Sprintf("Select your channel preference for ~%s", channel.DisplayName),
HelpText: "Enable to restrict bot posting meeting links to the channel.",
HelpText: "Enable to restrict creating meetings in this channel.",
Name: "preference",
Type: "radio",
Options: []*model.PostActionOptions{
Expand All @@ -341,7 +341,7 @@ func (p *Plugin) runChannelSettingsCommand(args *model.CommandArgs, params []str
Value: "disable",
},
{
Text: fmt.Sprintf("Default to plugin-wide settings (%t)", p.getConfiguration().RestrictBotPosting),
Text: fmt.Sprintf("Default to plugin-wide settings (%t)", p.getConfiguration().RestrictUserPosting),
Value: "default",
},
},
Expand All @@ -358,7 +358,7 @@ func (p *Plugin) runChannelSettingsCommand(args *model.CommandArgs, params []str

if err := client.OpenDialogRequest(&requestBody); err != nil {
p.API.LogError("Failed to fulfill the request to open preference dialog", "Error", err.Error())
return "Unable to open preference dialog for setting preference", nil
return "Unable to open the dialog for setting preference", nil
}

return "", nil
Expand All @@ -377,13 +377,18 @@ func (p *Plugin) runChannelSettingsCommand(args *model.CommandArgs, params []str
sb.WriteString("#### Channel preferences\n")
sb.WriteString("| Channel ID | Channel Name | Preference |\n| :----|:--------|:--------|")
for key, value := range zoomChannelSettingsMap {
sb.WriteString(fmt.Sprintf("\n|%s|%s|%s|", key, value.ChannelName, value.Preference))
preference := value.Preference
if value.Preference == ZoomChannelPreferences[DefaultPreference] {
preference = fmt.Sprintf("%s (%t)", preference, p.getConfiguration().RestrictUserPosting)
}

sb.WriteString(fmt.Sprintf("\n|%s|%s|%s|", key, value.ChannelName, preference))
}

return sb.String(), nil
}

return fmt.Sprintf("Unknown Action %v", ""), nil
return actionUnkown, nil
}

func (p *Plugin) updateUserPersonalSettings(usePMIValue, userID string) *model.AppError {
Expand Down Expand Up @@ -423,7 +428,7 @@ func (p *Plugin) getAutocompleteData() *model.AutocompleteData {
zoom.AddCommand(setting)

// channel-settings to update channel preferences
channelSettings := model.NewAutocompleteData("channel-settings", "", "Update current channel preferences")
channelSettings := model.NewAutocompleteData("channel-settings", "", "Update current channel preference")
channelSettingsList := model.NewAutocompleteData("list", "", "List all the channel preferences")
channelSettings.AddCommand(channelSettingsList)
channelSettings.RoleID = model.SystemAdminRoleId
Expand Down
2 changes: 1 addition & 1 deletion server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type configuration struct {
// ZoomWebhookSecret is the `Secret Token` taken from Zoom's webhook configuration page
ZoomWebhookSecret string

RestrictBotPosting bool
RestrictUserPosting bool
}

// Clone shallow copies the configuration. Your implementation may require a deep copy if
Expand Down
10 changes: 4 additions & 6 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func (p *Plugin) handleStartMeeting(w http.ResponseWriter, r *http.Request) {
}

if restrict {
if _, err = w.Write([]byte(`{"error": "Creating zoom meeting is disabled for the channel."}`)); err != nil {
if _, err = w.Write([]byte(`{"error": "Creating zoom meeting is disabled for this channel."}`)); err != nil {
mickmister marked this conversation as resolved.
Show resolved Hide resolved
p.API.LogWarn("failed to write the response", "error", err.Error())
}
return
Expand Down Expand Up @@ -956,14 +956,12 @@ func (p *Plugin) checkChannelPreference(channelID string) (bool, int, error) {
*/
if exist {
if val.Preference == ZoomChannelPreferences[DefaultPreference] {
mickmister marked this conversation as resolved.
Show resolved Hide resolved
preference = p.configuration.RestrictBotPosting
preference = p.configuration.RestrictUserPosting
} else if val.Preference == ZoomChannelPreferences[EnablePreference] {
preference = true
}
} else {
if channel.Type == model.ChannelTypeOpen {
preference = p.configuration.RestrictBotPosting
}
} else if channel.Type == model.ChannelTypeOpen {
preference = p.configuration.RestrictUserPosting
}

return preference, http.StatusOK, nil
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading