From eb9736ca41f9ced4d1ac948a8c76188997f93608 Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Thu, 15 Feb 2024 12:31:22 -0600 Subject: [PATCH] Add missing integration to mm References: https://todo.code.netlandish.com/~netlandish/links/50 --- core/routes.go | 2 +- docs/mattermost_bot.md | 4 +++- mattermost/routes.go | 31 ++++++++++++++----------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/core/routes.go b/core/routes.go index c9fef38..6cf08ea 100644 --- a/core/routes.go +++ b/core/routes.go @@ -95,7 +95,7 @@ func (s *Service) InactiveDomain(c echo.Context) error { gctx := c.(*server.Context) lt := localizer.GetSessionLocalizer(c) pd := localizer.NewPageData(lt.Translate("Inactive Domain")) - pd.Data["msg"] = lt.Translate("The domain is inactive") + pd.Data["msg"] = lt.Translate("The domain is currently inactive") pd.Data["please_upgrade"] = lt.Translate("Please upgrade your account to reactivate it") slug := links.PullOrgSlug(c) gMap := gobwebs.Map{"pd": pd, "slug": slug} diff --git a/docs/mattermost_bot.md b/docs/mattermost_bot.md index 780c6c8..b76fa11 100644 --- a/docs/mattermost_bot.md +++ b/docs/mattermost_bot.md @@ -5,7 +5,9 @@ and `root-url=/mattermost` ## Install mattermost app -* As system admin run the following command in your mattermost instance `/apps install http /mattermost/manifest.json` +* As system admin run the following command in your mattermost instance `/apps install http /mattermost//manifest.json` * In the modal, grant the proper permissions to the app and click on install * Once the app is installed, run the following command `/link-connect`. You will receive a private message with a link to connect your current channel with one organization. Follow the instructions and click on save. +* Then, you will be allowed to use `link-add`, `link-add-short` and `link-search` +* In case you haven't connect your user with the current MM integration, you will receive a private message with a link. diff --git a/mattermost/routes.go b/mattermost/routes.go index 5a7f17b..86c41aa 100644 --- a/mattermost/routes.go +++ b/mattermost/routes.go @@ -243,8 +243,9 @@ func (s *Service) SearchCommand(c echo.Context) error { if err != nil { return err } + lt := localizer.GetSessionLocalizer(c) if len(mmConns) == 0 { - return c.JSON(http.StatusOK, apps.NewTextResponse("No slack connection found")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("No slack connection found"))) } mmConn := mmConns[0] @@ -273,7 +274,7 @@ func (s *Service) SearchCommand(c echo.Context) error { if err != nil { return err } - return c.JSON(http.StatusOK, apps.NewTextResponse("We sent you a private msg")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("We sent you a private msg"))) } opts = &database.FilterOptions{ Filter: sq.And{ @@ -291,7 +292,6 @@ func (s *Service) SearchCommand(c echo.Context) error { } org := orgs[0] if links.BillingEnabled(gctx.Server.Config) && org.IsRestricted([]int{models.BillingStatusFree}) { - lt := localizer.GetSessionLocalizer(c) msg := lt.Translate("Sorry, free accounts do not support Mattermost Integration. Please upgrade to continue") return c.JSON(http.StatusOK, apps.NewTextResponse(msg)) } @@ -300,8 +300,6 @@ func (s *Service) SearchCommand(c echo.Context) error { if len(orgs) == 0 { return fmt.Errorf("No user found") } - lang := user.Settings.Account.DefaultLang - lt := localizer.GetLocalizer(lang) text, ok := creq.Values["text"].(string) if !ok { return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("The text to be searched is required"))) @@ -380,12 +378,13 @@ func (s *Service) ShortCommand(c echo.Context) error { Filter: sq.Eq{"mc.team_id": teamID}, Limit: 1, } + lt := localizer.GetSessionLocalizer(c) mmConns, err := models.GetMattermostConnections(c.Request().Context(), opts) if err != nil { return err } if len(mmConns) == 0 { - return c.JSON(http.StatusOK, apps.NewTextResponse("No slack connection found")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("No slack connection found"))) } mmConn := mmConns[0] @@ -398,13 +397,12 @@ func (s *Service) ShortCommand(c echo.Context) error { return err } if len(orgs) == 0 { - return c.JSON(http.StatusOK, apps.NewTextResponse("No organization found")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("No organization found"))) } gctx := c.(*server.Context) org := orgs[0] if links.BillingEnabled(gctx.Server.Config) && org.IsRestricted([]int{models.BillingStatusFree}) { - lt := localizer.GetSessionLocalizer(c) msg := lt.Translate("Sorry, free accounts do not support Mattermost Integration. Please upgrade to continue") return c.JSON(http.StatusOK, apps.NewTextResponse(msg)) } @@ -433,14 +431,12 @@ func (s *Service) ShortCommand(c echo.Context) error { if err != nil { return err } - return c.JSON(http.StatusOK, apps.NewTextResponse("We sent you a private msg")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("We sent you a private msg"))) } user, err := models.GetUser(c.Request().Context(), mmUsers[0].UserID, true) if err != nil { return err } - lang := user.Settings.Account.DefaultLang - lt := localizer.GetLocalizer(lang) ctx := c.Request().Context() ctx = auth.Context(ctx, user) title, ok := creq.Values["title"].(string) @@ -527,8 +523,9 @@ func (s *Service) AddCommand(c echo.Context) error { if err != nil { return err } + lt := localizer.GetSessionLocalizer(c) if len(mmConns) == 0 { - return c.JSON(http.StatusOK, apps.NewTextResponse("No slack connection found")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("No slack connection found"))) } mmConn := mmConns[0] @@ -582,8 +579,6 @@ func (s *Service) AddCommand(c echo.Context) error { if err != nil { return err } - lang := user.Settings.Account.DefaultLang - lt := localizer.GetLocalizer(lang) linkURL, ok := creq.Values["url"].(string) if !ok { return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("Url is required"))) @@ -642,17 +637,19 @@ func (s *Service) ConnectCommand(c echo.Context) error { slug, creq.Context.Team.Id, ) - msg := fmt.Sprintf("Please click in the following link to tie a org %s", baseURL.String()) + lt := localizer.GetSessionLocalizer(c) + msg := lt.Translate("Please click in the following link to tie a org %s", baseURL.String()) post := &model.Post{ChannelId: channel.Id, Message: msg} _, err = botClient.CreatePost(post) if err != nil { return err } - return c.JSON(http.StatusOK, apps.NewTextResponse("We sent you a private msg")) + return c.JSON(http.StatusOK, apps.NewTextResponse(lt.Translate("We sent you a private msg"))) } func (s *Service) Ping(c echo.Context) error { - return c.JSON(http.StatusOK, apps.NewDataResponse("Installed successfully")) + lt := localizer.GetSessionLocalizer(c) + return c.JSON(http.StatusOK, apps.NewDataResponse(lt.Translate("Installed successfully"))) } func (s *Service) ServeBinding(c echo.Context) error { -- 2.45.2