Commit Graph

69 Commits

Author SHA1 Message Date
Jesús Espino
1f09d86f42 Moving slash-commands out of app package (#14979)
* Moving slash-commands out of app package

* Fixing golint checks

* Fixing golangci-lint

* Fixing golangci-lint errors
2020-08-12 18:29:58 +02:00
Christopher Poile
c5c6a5ce53 MM-26057 - Add CreateCommand plugin API (#14916)
Automatic Merge
2020-07-31 17:40:15 +02:00
Joshua Bezaleel Abednego
48f0b7fd76 MM-25476: Migrate AppError from command_store.go (#14643)
Automatic Merge
2020-07-16 15:26:07 +02:00
Christopher Speller
3e9ec51890 Mm 16292 support command overrides (#14951)
* Supporing plugins that override built-in commands.

* Test.

* Fix test.

* Fix override order for command autocomplete.

* Fix test copy paste errors

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-07-02 13:28:21 -07:00
Rodrigo Villablanca
85a69d6112 Migrate Get/GetFromMaster methods from ChannelStore to return error interface (#14688)
* Advances

* Migration finished

* Rename err to normalized error

* fix imports

* Renamed key

* Renamed key

* Suggestions

* Fix i18n

* Fix tests

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
2020-06-02 21:58:29 +05:30
Allen Lai
ace46443b3 MM-21343: Recognize multi-line slash commands without requiring trailing space after trigger word (#13646)
* change how we are parsing the args.command

* change comment

* atttempt to write unit test

* remove quotes

* use unicode.IsSpace

* MM-21343 fix panic

* use table

* test cases

* bad request, add test for missing '/'

* mispelled err

* Update app/command.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* Update app/command.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* use a map

* use subtest and add test case of empty command

* go fmt

* do not use t.fatal

* Update app/command.go

Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>

* fix missing unicode import

Co-authored-by: wiggin77 <wiggin77@warpmail.net>
Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>
2020-03-23 14:38:21 -03:00
Claudio Costa
1e53fe85ad [MM-21378] Add mutex to model.Post to guard against race conditions on Post.Props (#13884)
* Add mutex to model.Post to guard against race conditions on Post.Props

* Rename mutex

* Add GetProp() method to Post

* Fix more tests

* Fix flaky test

Benchmarks:

BenchmarkPostPropsGet_indirect
BenchmarkPostPropsGet_indirect-2     	85026746	        13.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_indirect-4     	90273747	        13.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_indirect-8     	88324293	        13.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_indirect-16    	91427720	        13.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct
BenchmarkPostPropsGet_direct-2       	1000000000	         0.242 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct-4       	1000000000	         0.241 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct-8       	1000000000	         0.240 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsGet_direct-16      	1000000000	         0.241 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_indirect
BenchmarkPostPropsAdd_indirect-2     	 5602224	       203 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_indirect-4     	 5959496	       206 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_indirect-8     	 5833999	       205 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_indirect-16    	 5802493	       225 ns/op	     336 B/op	       2 allocs/op
BenchmarkPostPropsAdd_direct
BenchmarkPostPropsAdd_direct-2       	100000000	        11.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_direct-4       	100000000	        11.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_direct-8       	100000000	        11.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsAdd_direct-16      	99840794	        11.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_indirect
BenchmarkPostPropsDel_indirect-2     	18824002	        61.9 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_indirect-4     	19470736	        63.8 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_indirect-8     	17640460	        65.3 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_indirect-16    	18692962	        65.4 ns/op	      48 B/op	       1 allocs/op
BenchmarkPostPropsDel_direct
BenchmarkPostPropsDel_direct-2       	516257440	         2.34 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_direct-4       	514865216	         2.43 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_direct-8       	511330477	         2.37 ns/op	       0 B/op	       0 allocs/op
BenchmarkPostPropsDel_direct-16      	499504010	         2.38 ns/op	       0 B/op	       0 allocs/op
2020-03-13 21:12:20 +01:00
Alejandro García Montoro
2bec92a404 MM-21987 Resolve mentions in slash commands (#13762)
* Create infrastructure to manage mentions

Two new files have been added (along with their tests); namely:

- model/at_mentions.go: utilities to parse and manage mentions; for the moment,
it just contains a regex and a couple of functions to parse possible mentions
and to post-process them, but it can be extended in the future.
- model/mention_map.go: it contains two new types (UserMentionMap and
ChannelMentionMap) that both have FromURLValues and ToURLValues. These types
can be used when adding the mentions to the payload of the plugin slash
commands.

* Extend custom commands payload with mentions

Two couples of new fields are added to the payload; namely:

- user_mentions and user_mentions_ids: two aligned arrays of the same length
containing all the different @-mentions found in the command: the i-th element
of user_mentions_ids is the user identifier of the i-th element of
user_mentions.
- channel_mentions and channel_mentions_ids: two aligned arrays of the same
length containing all the different ~-mentions found in the command: the i-th
element of channel_mentions_ids is the channel identifier of the i-th element
of channel_mentions.

* Fix shadowing of variables and redundant return

* Fix shadowing of variable

* Address review comments (HT @lieut-data)

- Improvements in mentionsToTeamMembers and mentionsToPublicChannels:
	- Scope implementation details inside the functions.
	- Improve goroutines synchronization by using a sync.WaitGroup.
	- Retry lookup of username only if the returned error is http.StatusCode,
	  so we can return early if the error is more severe.
- Invert check in PossibleAtMentions to improve readability.
- Make user and channel mention keys private to the module.
- Allow the specification of an empty map of mentions in
(Channel|User)MentionsFromURLValues when both mentions keys are absent.
- Replace custom functions in tests with require.Equal on maps.

* Test functions to parse mentions from messages

* Extend plugin commands payload with mentions

* Add functions to CommandArgs to add mentions

The functions make sure that the maps are initialized before adding any value.

* Address review comments (HT @lieut-data)

- Adds a mlog.Warn to avoid burying the error when the user is not found.
- Improve readability in loop populating the mention map by moving the
initialization of the map closer to the loop and by iterating over the channel
itself, not over its length.

* File was not gofmt-ed with -s

* Close channel when all goroutines are finished

* Again, all code should be checked with gofmt -s

* Refactor code out of a goroutine

This change helps improve the readability of the code and does not affect its
overall performance. Less complexity is always better.

* Close channel and iterate over its range

Adapt mentionsToPublicChannels to have the same structure in the management
of the mentions channel as in mentionsToTeamMembers.

* Adapt mentionsToTeamMembers to new App

Commit 17523fa changed the App structure, making the *Server field
private, which is now accessed through the Srv() function.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-03-11 11:50:12 +01:00
Miguel de la Cruz
182c29b456 MM-21898: Part 2. Add opentracing (#13904)
* initial implementation of opentracing

* app layer

* Revert Makefile

* .

* cleanup

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* [ci]

* autogenerate interface

* .

* missed vendor files

* updated interfaces

* updated store layers

* lint fixes

* .

* finishing layer generators and nested spans

* added errors and b3 support

* code review

* .

* .

* fixed build error due to misplased flag.Parse()

* code review addressed
2020-03-05 14:46:08 +01:00
Eli Yukelzon
17523fa5d9 MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
2020-02-13 13:26:58 +01:00
Someone
566f28be0a GH-12702 v2: Add new command response parameter: "skip_slack_p… (#13420)
Add new command response parameter: "skip_slack_parsing". Skips Slack magic if set to "true". (#12702)
2020-01-17 08:34:11 +01:00
Jesús Espino
b8ef62e502 Adding structuredLogging check and fix inconsistencies (#13370)
* Adding structuredLogging check and fix inconsistencies

* Addressing PR review comments

* Addressing PR review comments

* Addressing PR review comments

* Addressing PR review comments

* Addressing PR review comments
2019-12-16 13:57:21 +01:00
Jesús Espino
a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00
Miguel de la Cruz
2259b7f2a8 [MM-19948] Set version on module file and internal paths (#13186)
* [MM-19948] Set version on module file and internal paths

* Fixes after merge

* Fix i18n checker error
2019-11-28 14:39:38 +01:00
Christopher Poile
c12c585fb8 [MM-19526] /code is rendering HTML incorrectly (#12840)
* text from /code command needs to be treated differently when processed

* PR comments
2019-10-22 08:39:49 -04:00
Ogundele Olumide
1f9d14e24c chore: refactor to use structured logging (#12256) 2019-09-24 18:30:23 +02:00
Lev
9e6c5e8ea6 MM-17489: fixed racy tryExecutePluginCommand (#11780)
* MM-17489: fixed racy tryExecutePluginCommand

* PR feedback

* MM 7971 dockerhost -> localhost && docker -> docker-compose (#10872)

* replace dockerhost with localhost

* remove uneeded setup-max build step (no more dockerhost)

* changes as recommended by @cpanato

* make clean-docker with docker-compose

* added ports to docker-compose.yml (needed for osx).   ignore error for ldapadd (when already exists)

* add clean-old-docker to legacy.mk

* docker-compose stop instead of down for `make stop-docker`

* MM-17117: Updates einterface for FirstLoginSync. (#11737)

* update sampledata users passwords (#11769)

* update sampledata users passwords

* update makefile

* Tweak docker compose setup (#11785)

* fix stray dockerhost mention

* fix stray whitespace

* fix missing mattermost-redix cleanup in clean-old-docker

* absolute path to docker-compose, plus simpler ldap initialization

* allow ldapadd to fail on CI

* MM-16366 - Prevent attachment duplication on import (#11770)

* prevent attachment duplication

* improved tests

* corrected import into a new post

* WIP: a failed attempt to add tests

* remove debugging statements

* fix godoc

* enable plugins when testing

* rework reentrant unit tests
2019-09-10 12:28:12 -04:00
Puneeth Reddy
2d3fb4f426 MM-15288: Migrate CommandStore.Get to sync by default (#10739)
* MM-15288: Migrate Command.Get to sync by default

* addressing review comments, updating status code of err returned by Get Method
2019-05-06 18:12:41 +02:00
Puneeth Reddy
ebbfdf9e5c MM-15291: migrate commandStore.Delete to sync by default (#10742) 2019-05-01 09:10:27 +02:00
Puneeth Reddy
13403b2cc1 MM-15287: Migrate commandstore.save to sync by default (#10738)
* MM-15287: Migrate commandstore.save to sync by default

* MM-15287: Minor change to follow code consistency
2019-04-29 18:07:38 +02:00
Puneeth Reddy
5b70962f71 MM-15294: migrate commandstore.Update to sync by default (#10745)
* MM-15294: migrate commandstore.Update to sync by default

* minor change for code consistency
2019-04-29 07:22:44 -07:00
Puneeth Reddy
171058eb3d MM-15289 Migrate command.GetByTeam to sync by default (#10740) 2019-04-29 10:20:51 +02:00
tengis b
8252eab5da [MM-15274] Migrate "Team.Get" to Sync by default (#10694)
* Migrate Team.Get to Sync by default

* change parseRange return value to ok

* fix formatting

* remove err checks

* use require.nil

* require nil
2019-04-26 18:18:07 +02:00
Andres Orozco
928ecba2d4 MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default (#10667)
* MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default

* MM-15198 - Update store/storetest/post_store.go

fix error handling in post_store.go test case

Co-Authored-By: andresoro <ao15@my.fsu.edu>
2019-04-24 20:28:06 +01:00
Gabe Jackson
be4b473aee Move to the mattermost/go-i18n fork (#10669)
This change is being made to address an issue where the go-i18n
translation library would result in partial-translations when a
given language dictionary was missing a given plural keyword. The
improvement made here leads the translation library to try an
'other' keyword lookup if the first plural keyword fails to have
a value.

This change was not accepted upstream due to concern regarding
changing the behavior, so we are using a fork at this time to
address the issue.
2019-04-23 09:33:42 -04:00
Jesús Espino
12c50eb830 Initial migration of the store to be sync (#10592)
* Migrating audit store

* Final migration example for the audit store

* async example

* Ending migration

* Removing Async helper

* Fixing tests

* Fixing govet problems with the StoreResult instanstiation
2019-04-15 22:53:52 +02:00
Joram Wilander
2ca222033c MM-10658 Change config fields to pointers (#9033)
* MM 10658 Change config fields to pointers (#8898)

* Change fields of config structs to pointers and set defaults

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix tests that go broken during switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Apply changes of current master while switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix new config pointer uses

* Fix app tests

* Fix mail test

* remove debugging statement

* fix TestUpdateConfig

* assign config consistently

* initialize AmazonS3Region in TestS3TestConnection

* initialize fields for TestEmailTest

* fix TestCheckMandatoryS3Fields
2019-01-31 08:12:01 -05:00
Harrison Healey
1a3ccaf305 MM-13606 Remove consumeAndClose and clean up integration response handling (#10066)
* MM-13606 Remove consumeAndClose

* Allow overriding HTTPService's request timeout

* MM-13606 Clean up integration response handling

* Properly close httptest servers

* Address feedback

* Only call buf.Bytes when necessary

* Properly check for errors in doOutgoingWebhookRequest

* Add comment explaining ignored ioutil.ReadAll errors
2019-01-09 17:07:08 -05:00
Michael Kochell
e67fe4c89d handle errors in HandleCommandResponse method (#9888) 2019-01-09 15:41:53 -05:00
Michael Kochell
f94567c97b [MM-9937] Add support for sending a message to a different channel than where the slash command was issued from (#9878)
* add support for channel_id in a slash command response

* add test for HandleCommandResponsePost
2018-12-12 07:43:31 +01:00
Joram Wilander
8cfca681b0 MM-12843 Add interactive dialogs (#9816)
* Add interactive dialogs

* Fix unit test

* Updates per feedback

* Fix typo

* Updates per feedback, add icon_url and error returns

* Updates per feedback

* Update per feedback
2018-11-19 15:27:17 -05:00
Michael Kochell
a50e8ac5b9 [MM-9938] Add support for multiple responses from a slash command (#9836)
* slash command response now supports multiple posts

* change wording of Posts to ExtraResponses
2018-11-19 08:00:50 -08:00
Shobhit Gupta
c317d6f265 MM-12356 Add cli command "command delete" (#9553)
* Add cli command for deleting commands

* Add code/test for delete command

* Fix test

* Add confirm flag

* Update as per comments

* Uncomment test

* Fix test
2018-10-23 12:19:10 +01:00
Hanzei
050c9de0f0 Migrate to idiomatic error handling in app/command.go (#9675) 2018-10-17 14:24:31 +02:00
Charles Birk
a755bcdde6 [MM-11860]: Expose slack attachment parsing functions in the model package (#9351)
Refactored parseSlackAttachment functions from https://github.com/mattermost/mattermost-server/blob/master/app/post.go#L312
into model/slack_attachments.go so that plugins have access to them.
2018-09-17 10:15:28 -04:00
alezakos
d585f9d9a3 MM-11895: Don't crush user-provided GET parameters on slash command URLs (#9372) 2018-09-11 15:58:57 -04:00
Harrison Healey
0027d99855 MM-11855 Add App.HTTPService to allow mocking of HTTP client (#9359)
* MM-11855 Add App.HTTPService to allow mocking of HTTP client

* Initialize HTTPService earlier
2018-09-07 09:24:18 -04:00
Jesse Hallam
a1656dffa9 MM-10201: querystring for get slash commands (#8779)
* pass GET slash command payloads through query string

Previously, both GET and POST requests received the payload via the
body, but this was incorrect for GET requests. Now, the payloads for GET
requests is sent via the query string.

* reorder tests for clarity

* switch command tests to use httptest servers

* restore original test command endpoints
2018-05-14 13:24:22 -04:00
Christopher Speller
686c2fbab7 Structured logging (#8673)
* Implementing structured logging

* Changes to en.json to allow refactor to run.

* Fixing global logger

* Structured logger initalization.

* Add caller.

* Do some log redirection.

* Auto refactor

* Cleaning up l4g reference and removing dependancy.

* Removing junk.

* Copyright headers.

* Fixing tests

* Revert "Changes to en.json to allow refactor to run."

This reverts commit fd8249e99b.

* Fixing some auto refactor strangeness and typo.

* Making keys more human readable.
2018-04-27 12:49:45 -07:00
Jesse Hallam
6d50d836f5 MM-10232, MM-10259: Improve error handling from invalid json (#8668)
* MM-10232: improve error handling from malformed slash command responses

Switch to json.Unmarshal, which doesn't obscure JSON parse failures like
json.Decode. The latter is primarily designed for streams of JSON, not
necessarily unmarshalling just a single object.

* rework HumanizedJsonError to expose Line and Character discretely

* MM-10259: pinpoint line and character where json config error occurs

* tweak HumanizeJsonError to accept err first
2018-04-26 11:19:25 -04:00
Chris
b34384dbad set from_webhook if a builtin slash command overrides username or icon (#8143) 2018-01-23 11:26:31 -08:00
Chris
4c17bdff1b Add plugin slash command support (#7941)
* add plugin slash command support

* remove unused string

* rebase
2017-12-08 13:55:41 -06:00
Chris Duarte
7ac35548c8 Add token to header for commands (#7841)
* add token to header for commands

* Change Header value to Authorization: Token thecommandtoken
2017-11-24 12:56:10 -05:00
Chris
77a1dc1f2f HTTP client refactor (#7884)
* http client refactor

* simplification
2017-11-22 10:15:03 -05:00
Joey Lee
3836f99920 PLT-7824 Added support for mentions with <@userid> and <!here> (#7615) (#7737) 2017-11-17 11:17:59 -05:00
Chris
10c5a927cb more global config ref cleanup (#7802) 2017-11-09 14:46:20 -06:00
Chris
8e19ba029f Reduce utils.Cfg references (#7650)
* app.UpdateConfig method

* test fix

* another test fix

* the config override option as-was is just error prone, remove it for now

* derp
2017-10-18 15:36:43 -07:00
Joram Wilander
9adaf53e11 PLT-7818 Updates to post type (#7579)
* Updates to post type

* Update tests
2017-10-09 10:30:48 -07:00
George Goldberg
f3fc6d11fa PLT-7218: CLI to move slash commands between teams. (#7574) 2017-10-04 11:08:59 -07:00
Carlos Tadeu Panato Junior
35d56821ff [PLT-7787] remove an extra ephemeral message posted for slash commands (#7572) 2017-10-04 09:11:08 -07:00