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

[GH-84] Add the concept of plugin admins #93

Merged

Conversation

vespian
Copy link
Contributor

@vespian vespian commented Feb 16, 2020

Summary

This plugin adds the concept of plugin admin users. A new plugin configuratoin option was added which lists comma-separated usernames for which modifying the configuration of the plugin is allowed (no auto-compleate, see [3]). Please see below for the sample config window:

autolink_preview

and sample interaction with the plugin as a user who first did not have admin privileges, and then was granted ones:

autolink-error-non-admin

While working on this change I have also changed how the Config is handled/passed around. In Go, function arguments are passed by value [1], so if. e.g. the underlying array of the Config.Links changed (i.e. new entries were added, causing reallocation), the other copies would be still using the old underlying array which could lead to weird errors. Also, based on the plugin template[2], the thread-safety seems to be guaranteed by passing around the reference to the plugin's config, so that if one goroutine updates the config, the other still has the consistent view on the old configuration as it is holding the old reference. Happy to discuss!

Do we still need EnableAdminCommand config option in this plugin, now that we have plugin administrators? Do we want to allow also adding userIds in the new field?

[1] https://stackoverflow.com/a/47486724
[2] https://github.com/mattermost/mattermost-plugin-starter-template/blob/282a8cf227849a25e306caff11597a0e4ba4cd01/server/configuration.go
[3] #84 (comment)

Ticket Link

Fixes mattermost/mattermost#84
Fixes #84 (jfrerich 2/28/20)

@@ -77,34 +89,61 @@ func (p *Plugin) SaveLinks(links []autolink.Autolink) error {
return nil
}

func (p *Plugin) UpdateConfig(f func(conf *Config)) Config {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value was never used.

@@ -55,6 +57,259 @@ func TestPlugin(t *testing.T) {
assert.Equal(t, "Welcome to [Mattermost](https://mattermost.com)!", rpost.Message)
}

type SuiteAuthorization struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty of not being consistent with other tests in this file, as using testing suite approach IMO is cleaner and we are already using testing suites in e.g. mattermost-server repo.

@levb levb added 1: PM Review Requires review by a product manager 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Feb 17, 2020
plugin.json Outdated Show resolved Hide resolved
@vespian vespian changed the title Add the concept of plugin admins [GH-84] Add the concept of plugin admins Feb 17, 2020
@vespian vespian force-pushed the prozlach/GH-84_plugin_admin_users branch from 74f6058 to 0149686 Compare February 17, 2020 20:43
@vespian
Copy link
Contributor Author

vespian commented Feb 17, 2020

@crspeller Done, ready for another pass.

Copy link
Contributor

@jfrerich jfrerich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @vespian! I really appreciate the additional tests and descriptive nature of your discussion. I've only a few nit-picking suggestions to address before approving

plugin.json Outdated Show resolved Hide resolved
server/autolinkplugin/config.go Outdated Show resolved Hide resolved
server/autolinkplugin/config.go Outdated Show resolved Hide resolved
@vespian vespian force-pushed the prozlach/GH-84_plugin_admin_users branch from aaf42da to bb32075 Compare February 19, 2020 17:30
@vespian
Copy link
Contributor Author

vespian commented Feb 19, 2020

@jfrerich Done, changes in commit Review fixes #1.

@hanzei hanzei requested review from crspeller and jfrerich February 20, 2020 04:53
Copy link
Contributor

@jfrerich jfrerich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, @vespian!

@crspeller crspeller removed the 2: Dev Review Requires review by a core committer label Mar 2, 2020
@crspeller
Copy link
Contributor

@vespian
Copy link
Contributor Author

vespian commented Mar 7, 2020

@DHaussermann @aaronrothschild Ping

@crspeller
Copy link
Contributor

@vespian I pinged them on the community server. Sorry for the delay!

@aaronrothschild
Copy link

Sorry for the delay on this @vespian , thanks for your contribution!

@aaronrothschild aaronrothschild removed the 1: PM Review Requires review by a product manager label Mar 9, 2020
Copy link

@aaronrothschild aaronrothschild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, LGTM @vespian

@aaronrothschild
Copy link

Sorry @vespian is this a general addition for "Admins" on "Plugins" or just for the Autolink plugin?

Just want to make sure I'm understanding correctly.

If we have a general purpose "Admin Users" for plugins....we need to think this through a bit more. It likely would need to be limited to Enterprise Edition licences (ie: Only EE licenced MM servers would have a centralized plce for admins of plugins).

@vespian
Copy link
Contributor Author

vespian commented Mar 9, 2020

Sorry @vespian is this a general addition for "Admins" on "Plugins" or just for the Autolink plugin?

@aaronrothschild This is only for autolink plugin :)

@DHaussermann
Copy link

DHaussermann commented Mar 10, 2020

@vespian I'm seeing an odd bug here. The list of authorized user is clearing itself out and it seem related maybe to when the functionality is used to change autolink settings. It seems like it only works once for a non-admin user and then the list empties.

Steps:

  • Login as sys admin
  • Pick a target non-system admin user and note the ID
  • Open autolink config and save the ID as an authorized user (optionally, can also add other data)
  • Login in a separate browser session as target user
  • Use commands like list and help repeatedly and note that it keeps working
  • Use a command that changes the data such as enable, disable or set WordMatch
  • Try using any other autolink command
    Observed:
    A. Users see's message about functionality being locked to sysadmin
    B. Return to admin browser session and refresh the list is now empty

Can you please see if you can also repro this? Please reach out if there is anymore clarification or details I can provide.

@vespian
Copy link
Contributor Author

vespian commented Mar 10, 2020

@DHaussermann Thanks a lot for checking my work, and a detailed bug report! I will take a closer look into it during the weekend, maybe earlier but no promises.

@jfrerich jfrerich mentioned this pull request Mar 19, 2020
3 tasks
@codecov-io
Copy link

codecov-io commented Mar 22, 2020

Codecov Report

Merging #93 into master will increase coverage by 3.85%.
The diff coverage is 78.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   36.43%   40.28%   +3.85%     
==========================================
  Files           6        6              
  Lines         538      561      +23     
==========================================
+ Hits          196      226      +30     
+ Misses        320      313       -7     
  Partials       22       22              
Impacted Files Coverage Δ
server/autolinkplugin/command.go 0.00% <0.00%> (ø)
server/autolinkplugin/config.go 68.49% <82.60%> (+6.19%) ⬆️
server/autolinkplugin/plugin.go 68.36% <100.00%> (+12.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e53e3f...daefa31. Read the comment docs.

@vespian vespian force-pushed the prozlach/GH-84_plugin_admin_users branch from 8991513 to daefa31 Compare March 22, 2020 16:35
@vespian
Copy link
Contributor Author

vespian commented Mar 22, 2020

@DHaussermann Fixed in commit daefa31

Let me know if you find anything more. Thanks!

@DHaussermann DHaussermann requested a review from jfrerich March 23, 2020 05:30
Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vespian for this fix! This is now working as expected.

  • Tested that designated plugin admin could use slash commands including those that modify data
  • Ensured previously found issue was resolved
  • No other issues found
    LGTM!
    Added test for this to release testing.

@DHaussermann DHaussermann added 4: Reviews Complete All reviewers have approved the pull request QA Review Done PR has been approved by QA and removed 3: QA Review Requires review by a QA tester 4: Reviews Complete All reviewers have approved the pull request labels Mar 23, 2020
@jfrerich jfrerich merged commit a10f0ee into mattermost-community:master Mar 23, 2020
@jfrerich jfrerich added the 4: Reviews Complete All reviewers have approved the pull request label Mar 23, 2020
@vespian vespian deleted the prozlach/GH-84_plugin_admin_users branch March 23, 2020 17:47
mo2menelzeiny pushed a commit to mo2menelzeiny/mattermost-plugin-autolink that referenced this pull request Mar 24, 2020
…ost-community#93)

* Add the concept of plugin admins

* Review fixes mattermost-community#1

Co-Authored-By: Jason Frerich <[email protected]>

* Review fixes mattermost-community#2

Co-authored-by: Jason Frerich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request QA Review Done PR has been approved by QA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the concept of plugin admin users
7 participants