Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
c892b4b4
Unverified
Commit
c892b4b4
authored
2 years ago
by
Noah Moss
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
clear slack token if saved with a non-existant files channel (#29397)
parent
0896fc2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/slack.clj
+4
-0
4 additions, 0 deletions
src/metabase/api/slack.clj
src/metabase/integrations/slack.clj
+6
-5
6 additions, 5 deletions
src/metabase/integrations/slack.clj
test/metabase/api/slack_test.clj
+13
-7
13 additions, 7 deletions
test/metabase/api/slack_test.clj
with
23 additions
and
12 deletions
src/metabase/api/slack.clj
+
4
−
0
View file @
c892b4b4
...
...
@@ -40,6 +40,10 @@
(
slack/clear-channel-cache!
))
(
let
[
processed-files-channel
(
slack/process-files-channel-name
slack-files-channel
)]
(
when
(
and
processed-files-channel
(
not
(
slack/channel-exists?
processed-files-channel
)))
;; Files channel could not be found; clear the token we had previously set since the integration should not be
;; enabled.
(
slack/slack-token-valid?!
false
)
(
slack/slack-app-token!
nil
)
(
throw
(
ex-info
(
tru
"Slack channel not found."
)
{
:errors
{
:slack-files-channel
(
tru
"channel not found"
)}})))
(
slack/slack-files-channel!
processed-files-channel
))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/integrations/slack.clj
+
6
−
5
View file @
c892b4b4
...
...
@@ -192,12 +192,13 @@
params
)))
(
defn
channel-exists?
"Returns
true if the
channel it
exists
."
"Returns
a Boolean indicating whether a
channel
w
it
h a given name exists in the cache
."
[
channel-name
]
(
let
[
channel-names
(
into
#
{}
(
comp
(
map
(
juxt
:name
:id
))
cat
)
(
:channels
(
slack-cached-channels-and-usernames
)))]
(
and
channel-name
(
contains?
channel-names
channel-name
))))
(
boolean
(
let
[
channel-names
(
into
#
{}
(
comp
(
map
(
juxt
:name
:id
))
cat
)
(
:channels
(
slack-cached-channels-and-usernames
)))]
(
and
channel-name
(
contains?
channel-names
channel-name
)))))
(
s/defn
valid-token?
"Check whether a Slack token is valid by checking if the `conversations.list` Slack api accepts it."
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/slack_test.clj
+
13
−
7
View file @
c892b4b4
...
...
@@ -45,16 +45,22 @@
(
mt/user-http-request
:crowberto
:put
200
"slack/settings"
{
:slack-files-channel
"#fake-channel"
})
(
is
(
=
"fake-channel"
(
slack/slack-files-channel
))))))
(
testing
"An error is returned if the Slack files channel cannot be found"
(
with-redefs
[
slack/channel-exists?
(
constantly
nil
)]
(
testing
"An error is returned if the Slack files channel cannot be found, and the integration is not enabled"
(
with-redefs
[
slack/channel-exists?
(
constantly
nil
)
slack/valid-token?
(
constantly
true
)
slack/refresh-channels-and-usernames!
(
constantly
nil
)
slack/refresh-channels-and-usernames-when-needed!
(
constantly
nil
)]
(
let
[
response
(
mt/user-http-request
:crowberto
:put
400
"slack/settings"
{
:slack-files-channel
"fake-channel"
})]
(
is
(
=
{
:slack-files-channel
"channel not found"
}
(
:errors
response
))))))
{
:slack-files-channel
"fake-channel"
:slack-app-token
"fake-token"
})]
(
is
(
=
{
:slack-files-channel
"channel not found"
}
(
:errors
response
)))
(
is
(
nil?
(
slack/slack-app-token
)))
(
is
(
=
"metabase_files"
(
slack/slack-files-channel
))))))
(
testing
"The Slack app token or files channel settings are cleared if no value is sent in the request"
(
mt/with-temporary-setting-values
[
slack-app-token
"fake-token"
slack-files-channel
"fake-channel"
slack/slack-cached-channels-and-usernames
[
"fake_channel"
]
(
mt/with-temporary-setting-values
[
slack-app-token
"fake-token"
slack-files-channel
"fake-channel"
slack/slack-cached-channels-and-usernames
[
"fake_channel"
]
slack/slack-channels-and-usernames-last-updated
(
t/zoned-date-time
)]
(
mt/user-http-request
:crowberto
:put
200
"slack/settings"
{})
(
is
(
=
nil
(
slack/slack-app-token
)))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment