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
40ef0245
Commit
40ef0245
authored
6 years ago
by
Ryan Senior
Browse files
Options
Downloads
Patches
Plain Diff
Add an `updated_at` column to `core_user`
parent
3a64d2a1
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
resources/migrations/000_migrations.yaml
+14
-0
14 additions, 0 deletions
resources/migrations/000_migrations.yaml
src/metabase/models/user.clj
+2
-1
2 additions, 1 deletion
src/metabase/models/user.clj
test/metabase/api/user_test.clj
+41
-64
41 additions, 64 deletions
test/metabase/api/user_test.clj
with
57 additions
and
65 deletions
resources/migrations/000_migrations.yaml
+
14
−
0
View file @
40ef0245
...
...
@@ -4057,3 +4057,17 @@ databaseChangeLog:
name
:
read_permissions
type
:
text
remarks
:
'
Permissions
required
to
view
this
Card
and
run
its
query.'
-
changeSet
:
id
:
76
author
:
senior
comment
:
'
Added
0.30.0'
changes
:
-
addColumn
:
tableName
:
core_user
columns
:
name
:
updated_at
type
:
DATETIME
defaultValueComputed
:
'
current_timestamp'
remarks
:
'
When
was
the
user
last
updated.'
constraints
:
nullable
:
false
This diff is collapsed.
Click to expand it.
src/metabase/models/user.clj
+
2
−
1
View file @
40ef0245
...
...
@@ -101,13 +101,14 @@
(
def
all-user-fields
"Seq of all the columns stored for a user"
(
vec
(
concat
default-user-fields
[
:google_auth
:ldap_auth
:is_active
])))
(
vec
(
concat
default-user-fields
[
:google_auth
:ldap_auth
:is_active
:updated_at
])))
(
u/strict-extend
(
class
User
)
models/IModel
(
merge
models/IModelDefaults
{
:default-fields
(
constantly
default-user-fields
)
:hydration-keys
(
constantly
[
:author
:creator
:user
])
:properties
(
constantly
{
:updated-at-timestamped?
true
})
:pre-insert
pre-insert
:post-insert
post-insert
:pre-update
pre-update
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/user_test.clj
+
41
−
64
View file @
40ef0245
...
...
@@ -21,57 +21,46 @@
(
expect
(
get
middleware/response-unauthentic
:body
)
(
http/client
:get
401
"user"
))
(
expect
(
get
middleware/response-unauthentic
:body
)
(
http/client
:get
401
"user/current"
))
(
def
user-defaults
(
def
^
:private
user-defaults
{
:ldap_auth
false
:is_active
true
:is_superuser
false
:google_auth
false
:is_qbnewb
true
})
:is_qbnewb
true
:id
true
:last_login
nil
:updated_at
true
:date_joined
true
})
;; ## GET /api/user
;; Check that anyone can get a list of all active Users
(
expect
(
set
(
map
#
(
merge
user-defaults
%
)
[(
match-$
(
fetch-user
:trashbird
)
{
:email
"trashbird@metabase.com"
:first_name
"Trash"
:last_login
$
:is_active
false
:id
$
:last_name
"Bird"
:common_name
"Trash Bird"
:date_joined
$
})
(
match-$
(
fetch-user
:crowberto
)
{
:common_name
"Crowberto Corv"
:last_name
"Corv"
:id
$
:is_superuser
true
:last_login
$
:first_name
"Crowberto"
:email
"crowberto@metabase.com"
:date_joined
$
})
(
match-$
(
fetch-user
:lucky
)
{
:common_name
"Lucky Pigeon"
:last_name
"Pigeon"
:id
$
:last_login
$
:first_name
"Lucky"
:email
"lucky@metabase.com"
:date_joined
$
})
(
match-$
(
fetch-user
:rasta
)
{
:common_name
"Rasta Toucan"
:last_name
"Toucan"
:id
$
:last_login
$
:first_name
"Rasta"
:email
"rasta@metabase.com"
:date_joined
$
})]))
[{
:email
"trashbird@metabase.com"
:first_name
"Trash"
:is_active
false
:last_name
"Bird"
:common_name
"Trash Bird"
}
{
:common_name
"Crowberto Corv"
:last_name
"Corv"
:is_superuser
true
:first_name
"Crowberto"
:email
"crowberto@metabase.com"
}
{
:common_name
"Lucky Pigeon"
:last_name
"Pigeon"
:first_name
"Lucky"
:email
"lucky@metabase.com"
}
{
:common_name
"Rasta Toucan"
:last_name
"Toucan"
:first_name
"Rasta"
:email
"rasta@metabase.com"
}]))
(
do
;; Delete all the other random Users we've created so far
(
let
[
user-ids
(
set
(
map
user->id
[
:crowberto
:rasta
:lucky
:trashbird
]))]
(
db/delete!
User
:id
[
:not-in
user-ids
]))
;; Now do the request
(
set
((
user->client
:rasta
)
:get
200
"user"
))))
; as a set since we don't know what order the results will come back in
(
set
(
tu/boolean-ids-and-timestamps
((
user->client
:rasta
)
:get
200
"user"
))))
)
; as a set since we don't know what order the results will come back in
;; ## POST /api/user
...
...
@@ -157,30 +146,22 @@
;; Check that fetching current user will return extra fields like `is_active` and will return OrgPerms
(
expect
(
merge
user-defaults
(
match-$
(
fetch-user
:rasta
)
{
:email
"rasta@metabase.com"
:first_name
"Rasta"
:last_name
"Toucan"
:common_name
"Rasta Toucan"
:date_joined
$
:last_login
$
:id
$
}))
((
user->client
:rasta
)
:get
200
"user/current"
))
{
:email
"rasta@metabase.com"
:first_name
"Rasta"
:last_name
"Toucan"
:common_name
"Rasta Toucan"
})
(
tu/boolean-ids-and-timestamps
((
user->client
:rasta
)
:get
200
"user/current"
)))
;; ## GET /api/user/:id
;; Should return a smaller set of fields, and should *not* return OrgPerms
(
expect
(
merge
user-defaults
(
match-$
(
fetch-user
:rasta
)
{
:email
"rasta@metabase.com"
:first_name
"Rasta"
:last_login
$
:id
$
:last_name
"Toucan"
:date_joined
$
:common_name
"Rasta Toucan"
}))
((
user->client
:rasta
)
:get
200
(
str
"user/"
(
user->id
:rasta
))))
{
:email
"rasta@metabase.com"
:first_name
"Rasta"
:last_name
"Toucan"
:common_name
"Rasta Toucan"
})
(
tu/boolean-ids-and-timestamps
((
user->client
:rasta
)
:get
200
(
str
"user/"
(
user->id
:rasta
)))))
;; Check that a non-superuser CANNOT fetch someone else's user details
(
expect
"You don't have permissions to do that."
...
...
@@ -189,15 +170,11 @@
;; A superuser should be allowed to fetch another users data
(
expect
(
merge
user-defaults
(
match-$
(
fetch-user
:rasta
)
{
:email
"rasta@metabase.com"
:first_name
"Rasta"
:last_login
$
:id
$
:last_name
"Toucan"
:date_joined
$
:common_name
"Rasta Toucan"
}))
((
user->client
:crowberto
)
:get
200
(
str
"user/"
(
user->id
:rasta
))))
{
:email
"rasta@metabase.com"
:first_name
"Rasta"
:last_name
"Toucan"
:common_name
"Rasta Toucan"
})
(
tu/boolean-ids-and-timestamps
((
user->client
:crowberto
)
:get
200
(
str
"user/"
(
user->id
:rasta
)))))
;; We should get a 404 when trying to access a disabled account
(
expect
"Not found."
...
...
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