From c76e660b5f02459745060dc9a458da6f27def2ad Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 17 May 2024 06:53:03 -0600 Subject: [PATCH] Default to domain when not specified in slack short add command --- docs/slack_bot.md | 5 +++-- docs/slack_bot_manifest.yaml | 2 +- slack/commands.go | 23 ++++++++++------------- slack/routes.go | 3 +-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/slack_bot.md b/docs/slack_bot.md index c6b5826..79afde4 100644 --- a/docs/slack_bot.md +++ b/docs/slack_bot.md @@ -4,5 +4,6 @@ * Create a new Slack App from a manifest and select you Workspace in https://api.slack.com/apps * Copy the manifest from `docs/slack_bot_manifest.yaml` and paste it in the creation wizard * Change `` values with the current link url -* From the `Basic Information` section copy the Client ID, Client Secret and Signing Secret into the slack section -of the config.ini file (`client-secret`, `client-id`, `signing-secret`) +* From the `Basic Information` section copy the Client ID, Client Secret and + Signing Secret into the slack section of the config.ini file + (`client-secret`, `client-id`, `signing-secret`) diff --git a/docs/slack_bot_manifest.yaml b/docs/slack_bot_manifest.yaml index 803d878..b148661 100644 --- a/docs/slack_bot_manifest.yaml +++ b/docs/slack_bot_manifest.yaml @@ -19,7 +19,7 @@ features: url: https:///slack/command - command: /link-add-short description: Add a new short link - usage_hint: code: domain: + usage_hint: url code: domain: url: https:///slack/command oauth_config: scopes: diff --git a/slack/commands.go b/slack/commands.go index 638b431..a8b9220 100644 --- a/slack/commands.go +++ b/slack/commands.go @@ -120,20 +120,8 @@ func linkAddShort(c echo.Context, surl, teamID, slackUser, text string) (*SlackC return commandResp, nil } - if domstr == "" { - block.Text.Text = lt.Translate("Wrong domain argument") - commandResp := &SlackCommandResponse{ - Text: "Error", - Blocks: []SlackBlock{block}, - } - return commandResp, nil - } - - // Check that the domain exists, it is a short service domain - // and belong to the slack connection organization opts = &database.FilterOptions{ Filter: sq.And{ - sq.Eq{"d.lookup_name": strings.ToLower(domstr)}, sq.Eq{"d.service": models.DomainServiceShort}, sq.Eq{"d.status": models.DomainStatusApproved}, sq.Eq{"d.is_active": true}, @@ -145,7 +133,16 @@ func linkAddShort(c echo.Context, surl, teamID, slackUser, text string) (*SlackC sq.Eq{"d.level": models.DomainLevelSystem}, }, }, - Limit: 1, + Limit: 1, + OrderBy: "d.level, id DESC", // Return org domains first + } + + if domstr != "" { + // If domain was specified, use it + opts.Filter = sq.And{ + opts.Filter, + sq.Eq{"d.lookup_name": strings.ToLower(domstr)}, + } } domains, err := models.GetDomains(ctx, opts) diff --git a/slack/routes.go b/slack/routes.go index 2c0b9c7..aeaa074 100644 --- a/slack/routes.go +++ b/slack/routes.go @@ -143,8 +143,8 @@ func (s *Service) ConnectUser(c echo.Context) error { req := c.Request() if req.Method == "POST" { - // Should not be reached, but just in case if !org.SlackConnID.Valid { + // Should not be reached, but just in case messages.Error(c, lt.Translate("Something went wrong. The user could not be linked.")) return links.Render(c, http.StatusOK, "connect_user.html", gmap) @@ -161,7 +161,6 @@ func (s *Service) ConnectUser(c echo.Context) error { } messages.Success(c, lt.Translate("User connected successfully")) return c.Redirect(http.StatusMovedPermanently, c.Echo().Reverse("accounts:settings")) - } return links.Render(c, http.StatusOK, "connect_user.html", gmap) -- 2.45.2