Mattermost-server: Slash command autocomplete data - system user role should be assumed if nothing is specified

Created on 18 Dec 2020  路  4Comments  路  Source: mattermost/mattermost-server

Summary

Slash command autocomplete data is filtered based on the user's role and command's specified role. However, the default value of the empty string is not handled in Mattermost server code, thus causing such a slash command to never be displayed for a system user.

Steps to reproduce

  1. Register a slash command with autocomplete data from a plugin. Don't specify anything for RoleID.
  2. Install and enable the plugin.
  3. Log in to Mattermost from a system user account (not system admin).
  4. Try typing / in the message box to bring up the list of auto complete slash command suggestions. Notice that your slash command is not in the list.

Expected behavior

Slash command autocomplete data with no role specified should be assumed to be for the system user role. It should only be required to specify a role when the developer needs to restrict it.

Observed behavior (that appears unintentional)

Slash command autocomplete data with no role specified works only for system admins, not for system users.

Possible fixes

In the function getSuggestions() at this line -

https://github.com/mattermost/mattermost-server/blob/277f886b3ffb483cc1f1d9f077672bc8d687efa2/app/command_autocomplete.go#L56

we check if roleID == "", instead we should be checking for command.RoleID == "". The current check of roleID == "" will never succeed because at this line -

https://github.com/mattermost/mattermost-server/blob/e974b7b9be5ec499b2e48a86038b6edbb1fa8bbd/api4/command.go#L380

we always set it to something, so it can never be empty string.

Help Wanted

All 4 comments

I am able to reproduce this. @amyblais, can you confirm if this is a valid issue so I can fix this?

@haardikdharma10 I haven't tested it but it sounds like a valid issue. Would you like me to assign this to you?

Yes, sounds good:)

Was this page helpful?
0 / 5 - 0 ratings