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
5d3f8279
Unverified
Commit
5d3f8279
authored
2 years ago
by
metamben
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Prevent modifying app permissions via the collection endpoint (#25684)
parent
e5c19bfe
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/collection/graph.clj
+14
-0
14 additions, 0 deletions
src/metabase/models/collection/graph.clj
test/metabase/models/collection/graph_test.clj
+10
-1
10 additions, 1 deletion
test/metabase/models/collection/graph_test.clj
with
24 additions
and
1 deletion
src/metabase/models/collection/graph.clj
+
14
−
0
View file @
5d3f8279
...
...
@@ -9,6 +9,7 @@
[
metabase.models.permissions-group
:refer
[
PermissionsGroup
]]
[
metabase.util
:as
u
]
[
metabase.util.honeysql-extensions
:as
hx
]
[
metabase.util.i18n
:as
i18n
:refer
[
tru
]]
[
metabase.util.schema
:as
su
]
[
schema.core
:as
s
]
[
toucan.db
:as
db
]))
...
...
@@ -93,6 +94,18 @@
;;; -------------------------------------------------- Update Graph --------------------------------------------------
(
defn-
check-no-app-collections
[
changes
]
(
let
[
coll-ids
(
into
#
{}
(
comp
(
mapcat
second
)
(
map
first
)
(
filter
int?
))
changes
)]
(
when-let
[
app-ids
(
and
(
seq
coll-ids
)
(
db/select-ids
'App
:collection_id
[
:in
coll-ids
]))]
(
throw
(
ex-info
(
tru
"Cannot set app permissions using this endpoint"
)
{
:status-code
400
:app-ids
app-ids
})))))
(
s/defn
^
:private
update-collection-permissions!
[
collection-namespace
:-
(
s/maybe
su/KeywordOrString
)
group-id
:-
su/IntGreaterThanZero
...
...
@@ -134,6 +147,7 @@
[
diff-old
changes
]
(
data/diff
old-perms
new-perms
)]
(
perms/log-permissions-changes
diff-old
changes
)
(
perms/check-revision-numbers
old-graph
new-graph
)
(
check-no-app-collections
changes
)
(
when
(
seq
changes
)
(
db/transaction
(
doseq
[[
group-id
changes
]
changes
]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/models/collection/graph_test.clj
+
10
−
1
View file @
5d3f8279
...
...
@@ -3,7 +3,7 @@
[
clojure.test
:refer
:all
]
[
medley.core
:as
m
]
[
metabase.api.common
:refer
[
*current-user-id*
]]
[
metabase.models
:refer
[
User
]]
[
metabase.models
:refer
[
App
User
]]
[
metabase.models.collection
:as
collection
:refer
[
Collection
]]
[
metabase.models.collection-permission-graph-revision
:as
c-perm-revision
:refer
[
CollectionPermissionGraphRevision
]]
...
...
@@ -434,3 +434,12 @@
(
with-n-temp-users-with-personal-collections
2000
(
is
(
>=
(
db/count
Collection
:personal_owner_id
[
:not=
nil
])
2000
))
(
is
(
map?
(
graph/graph
))))))
(
deftest
modify-perms-for-app-collections-test
(
testing
"that we cannot modify perms for app collections"
(
mt/with-temp*
[
Collection
[{
coll-id
:id
}]
App
[
_app
{
:collection_id
coll-id
}]]
(
is
(
thrown-with-msg?
clojure.lang.ExceptionInfo
#
"Cannot set app permissions using this endpoint"
(
graph/update-graph!
(
assoc-in
(
graph/graph
)
[
:groups
(
u/the-id
(
perms-group/all-users
))
coll-id
]
:read
)))))))
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