Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
81421262
Commit
81421262
authored
Mar 27, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose `last_activity_on` in the User API
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
d4da926f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
19 deletions
+66
-19
doc/api/users.md
doc/api/users.md
+14
-10
lib/api/entities.rb
lib/api/entities.rb
+3
-1
lib/api/users.rb
lib/api/users.rb
+6
-8
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+43
-0
No files found.
doc/api/users.md
View file @
81421262
...
...
@@ -72,6 +72,7 @@ GET /users
"organization"
:
""
,
"last_sign_in_at"
:
"2012-06-01T11:41:01Z"
,
"confirmed_at"
:
"2012-05-23T09:05:22Z"
,
"last_activity_on"
:
"2012-05-23"
,
"color_scheme_id"
:
2
,
"projects_limit"
:
100
,
"current_sign_in_at"
:
"2012-06-02T06:36:55Z"
,
...
...
@@ -104,6 +105,7 @@ GET /users
"organization"
:
""
,
"last_sign_in_at"
:
null
,
"confirmed_at"
:
"2012-05-30T16:53:06.148Z"
,
"last_activity_on"
:
"2012-05-23"
,
"color_scheme_id"
:
3
,
"projects_limit"
:
100
,
"current_sign_in_at"
:
"2014-03-19T17:54:13Z"
,
...
...
@@ -196,6 +198,7 @@ Parameters:
"organization"
:
""
,
"last_sign_in_at"
:
"2012-06-01T11:41:01Z"
,
"confirmed_at"
:
"2012-05-23T09:05:22Z"
,
"last_activity_on"
:
"2012-05-23"
,
"color_scheme_id"
:
2
,
"projects_limit"
:
100
,
"current_sign_in_at"
:
"2012-06-02T06:36:55Z"
,
...
...
@@ -320,6 +323,7 @@ GET /user
"organization"
:
""
,
"last_sign_in_at"
:
"2012-06-01T11:41:01Z"
,
"confirmed_at"
:
"2012-05-23T09:05:22Z"
,
"last_activity_on"
:
"2012-05-23"
,
"color_scheme_id"
:
2
,
"projects_limit"
:
100
,
"current_sign_in_at"
:
"2012-06-02T06:36:55Z"
,
...
...
@@ -365,6 +369,7 @@ GET /user
"organization"
:
""
,
"last_sign_in_at"
:
"2012-06-01T11:41:01Z"
,
"confirmed_at"
:
"2012-05-23T09:05:22Z"
,
"last_activity_on"
:
"2012-05-23"
,
"color_scheme_id"
:
2
,
"projects_limit"
:
100
,
"current_sign_in_at"
:
"2012-06-02T06:36:55Z"
,
...
...
@@ -998,16 +1003,9 @@ The activities that update the timestamp are:
-
Git HTTP/SSH activities (such as clone, push)
-
User logging in into GitLab
The data is stored in Redis and it depends on it for being recorded and displayed
over time. This means that we will lose the data if Redis gets flushed, or a custom
TTL is reached.
By default, it shows the activity for all users in the last 6 months, but this can be
amended by using the
`from`
parameter.
This function takes pagination parameters
`page`
and
`per_page`
to restrict the list of users.
```
GET /user/activities
```
...
...
@@ -1028,14 +1026,20 @@ Example response:
[
{
"username"
:
"user1"
,
"last_activity_at"
:
"2015-12-14 01:00:00"
"last_activity_on"
:
"2015-12-14"
,
"last_activity_at"
:
"2015-12-14"
},
{
"username"
:
"user2"
,
"last_activity_at"
:
"2015-12-15 01:00:00"
"last_activity_on"
:
"2015-12-15"
,
"last_activity_at"
:
"2015-12-15"
},
{
"username"
:
"user3"
,
"last_activity_at"
:
"2015-12-16 01:00:00"
"last_activity_on"
:
"2015-12-16"
,
"last_activity_at"
:
"2015-12-16"
}
]
```
Please note that
`last_activity_at`
is deprecated, please use
`last_activity_on`
.
lib/api/entities.rb
View file @
81421262
...
...
@@ -20,7 +20,8 @@ module API
class
UserActivity
<
Grape
::
Entity
expose
:username
expose
:last_activity_at
expose
:last_activity_on
expose
:last_activity_on
,
as: :last_activity_at
# Back-compat
end
class
Identity
<
Grape
::
Entity
...
...
@@ -30,6 +31,7 @@ module API
class
UserPublic
<
User
expose
:last_sign_in_at
expose
:confirmed_at
expose
:last_activity_on
expose
:email
expose
:color_scheme_id
,
:projects_limit
,
:current_sign_in_at
expose
:identities
,
using:
Entities
::
Identity
...
...
lib/api/users.rb
View file @
81421262
...
...
@@ -538,19 +538,17 @@ module API
desc
'Get a list of user activities'
params
do
optional
:from
,
type:
String
,
desc:
'Date string in the format YEAR-MONTH-DAY'
optional
:from
,
type:
DateTime
,
default:
6
.
months
.
ago
,
desc:
'Date string in the format YEAR-MONTH-DAY'
use
:pagination
end
get
"
:
activities"
do
get
"activities"
do
authenticated_as_admin!
activit
y_set
=
Gitlab
::
UserActivities
::
ActivitySet
.
new
(
from:
params
[
:from
],
page:
params
[
:page
],
per_page:
params
[
:per_page
]
)
activit
ies
=
User
.
where
(
User
.
arel_table
[
:last_activity_on
].
gteq
(
params
[
:from
])).
reorder
(
last_activity_on: :asc
)
add_pagination_headers
(
activity_set
)
present
activity_set
.
activities
,
with:
Entities
::
UserActivity
present
paginate
(
activities
),
with:
Entities
::
UserActivity
end
end
end
...
...
spec/requests/api/users_spec.rb
View file @
81421262
...
...
@@ -1158,6 +1158,49 @@ describe API::Users, api: true do
end
end
context
"user activities"
,
:redis
do
let!
(
:old_active_user
)
{
create
(
:user
,
last_activity_on:
Time
.
utc
(
2000
,
1
,
1
))
}
let!
(
:newly_active_user
)
{
create
(
:user
,
last_activity_on:
2
.
days
.
ago
.
midday
)
}
context
'last activity as normal user'
do
it
'has no permission'
do
get
api
(
"/user/activities"
,
user
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'as admin'
do
it
'returns the activities from the last 6 months'
do
get
api
(
"/user/activities"
,
admin
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
size
).
to
eq
(
1
)
activity
=
json_response
.
last
expect
(
activity
[
'username'
]).
to
eq
(
newly_active_user
.
username
)
expect
(
activity
[
'last_activity_on'
]).
to
eq
(
2
.
days
.
ago
.
to_date
.
to_s
)
expect
(
activity
[
'last_activity_at'
]).
to
eq
(
2
.
days
.
ago
.
to_date
.
to_s
)
end
context
'passing a :from parameter'
do
it
'returns the activities from the given date'
do
get
api
(
"/user/activities?from=2000-1-1"
,
admin
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
size
).
to
eq
(
2
)
activity
=
json_response
.
first
expect
(
activity
[
'username'
]).
to
eq
(
old_active_user
.
username
)
expect
(
activity
[
'last_activity_on'
]).
to
eq
(
Time
.
utc
(
2000
,
1
,
1
).
to_date
.
to_s
)
expect
(
activity
[
'last_activity_at'
]).
to
eq
(
Time
.
utc
(
2000
,
1
,
1
).
to_date
.
to_s
)
end
end
end
end
describe
'GET /users/:user_id/impersonation_tokens'
do
let!
(
:active_personal_access_token
)
{
create
(
:personal_access_token
,
user:
user
)
}
let!
(
:revoked_personal_access_token
)
{
create
(
:personal_access_token
,
:revoked
,
user:
user
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment