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

/autolink command to edit configuration #71

Merged
merged 10 commits into from
Aug 13, 2019
Merged

/autolink command to edit configuration #71

merged 10 commits into from
Aug 13, 2019

Conversation

levb
Copy link
Contributor

@levb levb commented Aug 2, 2019

This PR was prompted by a plethora of tickets for autolink config changes on the community servers. Since there is no UI in the foreseeable future, and modifying configuration otherwise is difficult, I figured these would be useful tools for the more advanced administrators.

The command can be turned off entirely with a config setting in the system console.

/autolink help output:

Mattermost Autolink Plugin Administration

is either the Name of a link, or its number in the /autolink list output. A partial Name can be specified, but some commands require it to be uniquely resolved.

  • /autolink list - list all configured links.
  • /autolink list <linkref> - list a specific link.
  • /autolink test <linkref> test-text... - test a link on a sample.
  • /autolink enable <linkref> - enable a link.
  • /autolink disable <linkref> - disable a link.
  • /autolink add <name> - add a new link, named .
  • /autolink delete <linkref> - delete a link.
  • /autolink set <linkref> <field> value... - sets a link's field to a value. The entire command line - after is used for the value, unescaped, leading/trailing whitespace trimmed.

Example:

/autolink add Visa
/autolink disable Visa
/autolink set Visa Pattern (?P<VISA>(?P<part1>4\d{3})[ -]?(?P<part2>\d{4})[ -]?(?P<part3>\d{4})[ -]?(?P<LastFour>[0-9]{4}))
/autolink set Visa Template VISA XXXX-XXXX-XXXX-$LastFour
/autolink set Visa WordMatch true
/autolink test Visa 4356-7891-2345-1111 -- (4111222233334444)
/autolink enable Visa

Lev Brouk added 8 commits July 10, 2019 05:55
- Using `\b` instead of a homebrewed word separator list
- Since `\b` does not consume, removed the second pass ReplaceAll
- Made tests more realistic by running MessageWillBePosted,
  to cover markdown inspection
- Added word boundary tests
- Cleanup
Also
- fixed the help message
- fixed incorrect parsing of "false"
- moved command [un-]registration OnConfigurationChanged
@levb levb added 1: PM Review Requires review by a product manager 2: Dev Review Requires review by a core committer labels Aug 2, 2019
@levb levb requested review from aaronrothschild, lieut-data, crspeller, DHaussermann and jfrerich and removed request for lieut-data August 2, 2019 02:11
*conf = c
})

go func() {
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 go func() {} here is a suggestion to work around mattermost/mattermost#11780 which may not be available until mattermost-server 5.15 or later. Thanks @lieut-data for the suggestion.

server/link.go Outdated

pattern := l.Pattern
template := l.Template
multipass := false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (multipass) probably warrants a comment. Previously, word boundaries were defined as custom regexp's. These patterns consume characters, so they can not be used with ReplaceAll functions. Example, if the pattern is defined as "X", "foo X bar" the X will match, but in "foo X X bar" only the first X matches, the match consumes the subsequent space, and then the second X doesn't match.

see the Replace() method for more.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a comment in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With better naming, didn't need to comment as much

func saveConfigLinks(p *Plugin, links []Link) error {
conf := p.getConfig()
conf.Links = links
appErr := p.API.SavePluginConfig(conf.ToConfig())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.ToConfig() here converts the Link structs into a tree of map[string]interface{} and []interface{} for GOB/RPC compatibility.

@aaronrothschild
Copy link

aaronrothschild commented Aug 2, 2019

@levb I'm surprised there's no interactive regex editor. ;)

Is there a spinmint or test server I can try this code out on interactively?

@levb
Copy link
Contributor Author

levb commented Aug 2, 2019

@aaronrothschild I spun one up on the related PR, mattermost/mattermost#11780

@aaronrothschild
Copy link

@levb some questions/comments:

  • In /autolink list we should display if they are active or not
  • in /autolink help results there is /autolink test Vi 4356-7891-2345-1111 -- (4111222233334444) the Vi should presumably be Visa
  • What does "WordMatch" flag do?
  • What is "field" in this command used for? "/autolink set value... - sets a link's field to a value. The entire command line after is used for the value, unescaped, leading/trailing whitespace trimmed."

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.

Once @aaronrothschild is stratified please merge, I can test this post merge.

@jfrerich jfrerich requested review from lieut-data and removed request for jfrerich August 4, 2019 17:10
@aaronrothschild aaronrothschild removed the 1: PM Review Requires review by a product manager label Aug 7, 2019
@levb levb requested review from mickmister and removed request for lieut-data August 7, 2019 03:31
@levb
Copy link
Contributor Author

levb commented Aug 7, 2019

@aaronrothschild

  • In /autolink list we should display if they are active or not

it kind of does, the disabled links are crossed out

  • in /autolink help results there is /autolink test Vi 4356-7891-2345-1111 -- (4111222233334444) the Vi should presumably be Visa

Vi is a partial match, should work.

  • What does "WordMatch" flag do?

Uses the more standard \b word boundaries. "\b - at ASCII word boundary (\w on one side and \W, \A, or \z on the other)". We historically implemented a custom set for the left and right boundaries, and it can (has) lead to confusion. I think we should eventually move towards making \b the default, and deprecating the old-style separators, but not yet.

  • What is "field" in this command used for? "/autolink set value... - sets a link's field to a value. The entire command line after is used for the value, unescaped, leading/trailing whitespace trimmed."

The name of the field. Like, for Name, Pattern, or DisableNonWordPrefix

Copy link
Contributor

@mickmister mickmister left a comment

Choose a reason for hiding this comment

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

A big improvement in the UX of the plugin, great job @levb 👍

Copy link
Contributor

@crspeller crspeller left a comment

Choose a reason for hiding this comment

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

One non blocking nit.

server/link.go Outdated

pattern := l.Pattern
template := l.Template
multipass := false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a comment in the code?

@DHaussermann
Copy link

@levb or @aaronrothschild I see that this PR is still open. Can you please advise if we intend to package this for the 5.14 Release?

@hanzei hanzei added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels Aug 13, 2019
@levb
Copy link
Contributor Author

levb commented Aug 13, 2019

This is for after 5.14 @DHaussermann, but I am merging this now, and will cut a release shortly. I'd like to deploy it onto community this week, once we confirm it on ci-extensions.

@levb levb merged commit 39be0a4 into mattermost-community:master Aug 13, 2019
@levb levb deleted the lev-command-config branch August 13, 2019 13:02
rohanjulka19 added a commit to rohanjulka19/mattermost-plugin-autolink that referenced this pull request Sep 1, 2019
rohanjulka19 added a commit to rohanjulka19/mattermost-plugin-autolink that referenced this pull request Sep 1, 2019
levb pushed a commit that referenced this pull request Sep 6, 2019
* Update README for #43, #71

* Added Regular expression tips
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants