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
bc57e929
Commit
bc57e929
authored
6 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add group_ids to User model and GET /api/user* endpoints
parent
91fe28b9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/user.clj
+4
-3
4 additions, 3 deletions
src/metabase/api/user.clj
src/metabase/models/user.clj
+13
-0
13 additions, 0 deletions
src/metabase/models/user.clj
with
17 additions
and
3 deletions
src/metabase/api/user.clj
+
4
−
3
View file @
bc57e929
...
...
@@ -41,7 +41,7 @@
(
hh/merge-where
(
when-not
include_deactivated
[
:=
:is_active
true
]))))
;; For admins, also include the IDs of the Users' Personal Collections
api/*is-superuser?*
(
hydrate
:personal_collection_id
)))
api/*is-superuser?*
(
hydrate
:personal_collection_id
:group_ids
)))
(
defn-
fetch-user
[
&
query-criteria
]
(
apply
db/select-one
(
vec
(
cons
User
user/admin-or-self-visible-columns
))
query-criteria
))
...
...
@@ -79,14 +79,15 @@
"Fetch the current `User`."
[]
(
->
(
api/check-404
@
api/*current-user*
)
(
hydrate
:personal_collection_id
)))
(
hydrate
:personal_collection_id
:group_ids
)))
(
api/defendpoint
GET
"/:id"
"Fetch a `User`. You must be fetching yourself *or* be a superuser."
[
id
]
(
check-self-or-superuser
id
)
(
api/check-404
(
fetch-user
:id
id,
:is_active
true
)))
(
->
(
api/check-404
(
fetch-user
:id
id,
:is_active
true
))
(
hydrate
:group_ids
)))
(
defn-
valid-email-update?
"This predicate tests whether or not the user is allowed to update the email address associated with this account."
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/user.clj
+
13
−
0
View file @
bc57e929
...
...
@@ -135,6 +135,19 @@
:pre-delete
pre-delete
:types
(
constantly
{
:login_attributes
:json-no-keywordization
})}))
(
defn
^
{
:hydrate
:group_ids
}
group-ids
"Fetch set of IDs of PermissionsGroup a User belongs to."
[
user-or-id
]
(
db/select-field
:group_id
PermissionsGroupMembership
:user_id
(
u/get-id
user-or-id
)))
(
defn
^
{
:batched-hydrate
:group_ids
}
add-group-ids
"Efficiently add PermissionsGroup `group_ids` to a collection of `users`."
[
users
]
(
let
[
user-id->memberships
(
when
(
seq
users
)
(
group-by
:user_id
(
db/select
[
PermissionsGroupMembership
:user_id
:group_id
]
:user_id
[
:in
(
set
(
map
u/get-id
users
))])))]
(
for
[
user
users
]
(
assoc
user
:group_ids
(
map
:group_id
(
user-id->memberships
(
u/get-id
user
)))))))
;;; --------------------------------------------------- Helper Fns ---------------------------------------------------
...
...
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