From 3138543d108da321d2ce533fc5eff4e6fb8f6b96 Mon Sep 17 00:00:00 2001 From: Julien Tant <785518+JulienTant@users.noreply.github.com> Date: Tue, 23 Aug 2022 08:37:06 -0700 Subject: [PATCH] [MM-46468] Change /help and add /marketplace (#20850) --- api4/command_help_test.go | 4 +-- app/slashcommands/command_help.go | 7 +++- app/slashcommands/command_marketplace.go | 43 ++++++++++++++++++++++++ i18n/en.json | 18 +++++++++- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 app/slashcommands/command_marketplace.go diff --git a/api4/command_help_test.go b/api4/command_help_test.go index 1f0bf0fbbb..7fab1d5758 100644 --- a/api4/command_help_test.go +++ b/api4/command_help_test.go @@ -25,11 +25,11 @@ func TestHelpCommand(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.SupportSettings.HelpLink = "" }) rs1, _, _ := client.ExecuteCommand(channel.Id, "/help ") - assert.Equal(t, rs1.GotoLocation, model.SupportSettingsDefaultHelpLink, "failed to default help link") + assert.Contains(t, rs1.Text, model.SupportSettingsDefaultHelpLink, "failed to default help link") th.App.UpdateConfig(func(cfg *model.Config) { *cfg.SupportSettings.HelpLink = "https://docs.mattermost.com/guides/user.html" }) rs2, _, _ := client.ExecuteCommand(channel.Id, "/help ") - assert.Equal(t, rs2.GotoLocation, "https://docs.mattermost.com/guides/user.html", "failed to help link") + assert.Contains(t, rs2.Text, "https://docs.mattermost.com/guides/user.html", "failed to help link") } diff --git a/app/slashcommands/command_help.go b/app/slashcommands/command_help.go index a319e7f6be..0618760efe 100644 --- a/app/slashcommands/command_help.go +++ b/app/slashcommands/command_help.go @@ -41,5 +41,10 @@ func (h *HelpProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandA helpLink = model.SupportSettingsDefaultHelpLink } - return &model.CommandResponse{GotoLocation: helpLink} + return &model.CommandResponse{ + ResponseType: model.CommandResponseTypeEphemeral, + Text: args.T("api.command_help.success", map[string]any{ + "HelpLink": helpLink, + }), + } } diff --git a/app/slashcommands/command_marketplace.go b/app/slashcommands/command_marketplace.go new file mode 100644 index 0000000000..29600ce640 --- /dev/null +++ b/app/slashcommands/command_marketplace.go @@ -0,0 +1,43 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package slashcommands + +import ( + "github.com/mattermost/mattermost-server/v6/app" + "github.com/mattermost/mattermost-server/v6/app/request" + "github.com/mattermost/mattermost-server/v6/model" + "github.com/mattermost/mattermost-server/v6/shared/i18n" +) + +type MarketplaceProvider struct { +} + +const ( + CmdMarketplace = "marketplace" +) + +func init() { + app.RegisterCommandProvider(&MarketplaceProvider{}) +} + +func (h *MarketplaceProvider) GetTrigger() string { + return CmdMarketplace +} + +func (h *MarketplaceProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command { + return &model.Command{ + Trigger: CmdMarketplace, + AutoComplete: true, + AutoCompleteDesc: T("api.command_marketplace.desc"), + DisplayName: T("api.command_marketplace.name"), + } +} + +func (h *MarketplaceProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse { + // This command is handled client-side and shouldn't hit the server. + return &model.CommandResponse{ + Text: args.T("api.command_marketplace.unsupported.app_error"), + ResponseType: model.CommandResponseTypeEphemeral, + } +} diff --git a/i18n/en.json b/i18n/en.json index b69aaf6917..ed5d7f2726 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -856,12 +856,16 @@ }, { "id": "api.command_help.desc", - "translation": "Open the Mattermost help page" + "translation": "Show Mattermost help message" }, { "id": "api.command_help.name", "translation": "help" }, + { + "id": "api.command_help.success", + "translation": "Mattermost is an open source platform for secure communication, collaboration, and orchestration of work across tools and teams.\r\nMattermost contains three key tools:\r\n\r\n**Channels** - Stay connected with your team via 1:1 and group messaging.\r\n**[Playbooks](/playbooks)** - Build and configure repeatable processes to achieve specific and predictable outcomes.\r\n**[Boards](/boards)** - Manage projects and tasks in a Kanban board structure to help your team hit key milestones.\r\n\r\n[View documentation and guides]({{.HelpLink}})" + }, { "id": "api.command_invite.channel.app_error", "translation": "Error to retrieve the current channel." @@ -974,6 +978,18 @@ "id": "api.command_logout.name", "translation": "logout" }, + { + "id": "api.command_marketplace.desc", + "translation": "Open the Marketplace" + }, + { + "id": "api.command_marketplace.name", + "translation": "marketplace" + }, + { + "id": "api.command_marketplace.unsupported.app_error", + "translation": "The marketplace command is not supported on your device." + }, { "id": "api.command_me.desc", "translation": "Do an action"