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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f1ddbea6
Commit
f1ddbea6
authored
Dec 13, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code to separate concerns
parent
3c5150a1
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
44 deletions
+67
-44
app/models/user.rb
app/models/user.rb
+1
-1
lib/api/users.rb
lib/api/users.rb
+4
-4
lib/gitlab/user/activity.rb
lib/gitlab/user/activity.rb
+20
-0
lib/gitlab/user/activity_set.rb
lib/gitlab/user/activity_set.rb
+37
-0
lib/gitlab/user_activities.rb
lib/gitlab/user_activities.rb
+0
-34
spec/lib/gitlab/user/activity_set_spec.rb
spec/lib/gitlab/user/activity_set_spec.rb
+1
-1
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+4
-4
No files found.
app/models/user.rb
View file @
f1ddbea6
...
...
@@ -948,7 +948,7 @@ class User < ActiveRecord::Base
end
def
record_activity
Gitlab
::
User
Activities
.
record
(
self
)
Gitlab
::
User
::
ActivitySet
.
record
(
self
)
end
private
...
...
lib/api/users.rb
View file @
f1ddbea6
...
...
@@ -467,11 +467,11 @@ module API
get
":activities"
do
authenticated_as_admin!
user_activities
=
Gitlab
::
UserActivities
.
query
(
from:
params
[
:from
],
raw_activities
=
Gitlab
::
User
::
ActivitySet
.
query
(
from:
params
[
:from
],
page:
params
[
:page
],
per_page:
params
[
:per_page
])
present
paginate
(
user
_activities
),
with:
Entities
::
UserActivity
present
Gitlab
::
User
::
Activity
.
from_array
(
raw
_activities
),
with:
Entities
::
UserActivity
end
end
end
...
...
lib/gitlab/user/activity.rb
0 → 100644
View file @
f1ddbea6
module
Gitlab
module
User
class
Activity
attr_reader
:username
def
self
.
from_array
(
activities
)
activities
.
map
{
|
activity
|
new
(
*
activity
)
}
end
def
initialize
(
username
,
time
)
@username
=
username
@time
=
time
end
def
date
@date
||=
Time
.
at
(
@time
).
utc
.
to_datetime
end
end
end
end
lib/gitlab/user/activity_set.rb
0 → 100644
View file @
f1ddbea6
module
Gitlab
module
User
class
ActivitySet
KEY
=
'user/activities'
DEFAULT_PAGE_SIZE
=
50
DEFAULT_FROM
=
1
.
year
.
ago
def
self
.
record
(
user
)
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zadd
(
KEY
,
Time
.
now
.
to_i
,
user
.
username
)
end
end
def
self
.
query
(
*
args
)
new
(
*
args
).
query
end
def
initialize
(
from
:,
page
:,
per_page
:)
@from
=
from
||
DEFAULT_FROM
@page
=
page
||
0
@per_page
=
per_page
||
DEFAULT_PAGE_SIZE
end
def
query
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zrangebyscore
(
KEY
,
@from
.
to_i
,
Time
.
now
.
to_i
,
with_scores:
true
,
limit:
[
offset
,
@per_page
])
end
end
private
def
offset
@page
*
@per_page
end
end
end
end
lib/gitlab/user_activities.rb
deleted
100644 → 0
View file @
3c5150a1
module
Gitlab
class
UserActivities
KEY
=
'user/activities'
DEFAULT_PAGE_SIZE
=
50
def
self
.
record
(
user
)
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zadd
(
KEY
,
Time
.
now
.
to_i
,
user
.
username
)
end
end
def
self
.
query
(
*
args
)
new
(
*
args
).
query
end
def
initialize
(
from:
6
.
months
.
ago
,
page:
0
,
per_page:
DEFAULT_PAGE_SIZE
)
@from
=
from
@page
=
page
@per_page
=
per_page
end
def
query
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
zrangebyscore
(
KEY
,
@from
.
to_i
,
Time
.
now
.
to_i
,
with_scores:
true
,
limit:
[
offset
,
@per_page
])
end
end
private
def
offset
@page
*
@per_page
end
end
end
spec/lib/gitlab/user
_activities
_spec.rb
→
spec/lib/gitlab/user
/activity_set
_spec.rb
View file @
f1ddbea6
require
'spec_helper'
describe
Gitlab
::
User
Activities
,
:redis
,
lib:
true
do
describe
Gitlab
::
User
::
ActivitySet
,
:redis
,
lib:
true
do
let
(
:user
)
{
create
(
:user
)
}
it
'shows the last user activities'
do
...
...
spec/requests/api/users_spec.rb
View file @
f1ddbea6
...
...
@@ -1103,18 +1103,18 @@ describe API::Users, api: true do
context
"user activities"
,
:redis
do
it_behaves_like
'a paginated resources'
do
let
(
:request
)
{
get
api
(
"/user
s/activities"
,
user
)
}
let
(
:request
)
{
get
api
(
"/user
/activities"
,
admin
)
}
end
context
'last activities'
do
it
'returns the last activities'
do
user
.
record_activity
get
api
(
"/user
s
/activities"
,
admin
)
get
api
(
"/user/activities"
,
admin
)
activity
=
json_response
.
first
activity
=
json_response
expect
(
activity
[
'project_id'
].
to_i
).
to
eq
(
project
.
id
)
expect
(
activity
).
to
eq
(
''
)
end
end
end
...
...
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