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
5819115a
Commit
5819115a
authored
Feb 27, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow querying of last N visits to issue boards
Adds additional count param to Boards::Visits::LatestService
parent
99a00859
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
22 deletions
+54
-22
app/models/board_group_recent_visit.rb
app/models/board_group_recent_visit.rb
+3
-3
app/models/board_project_recent_visit.rb
app/models/board_project_recent_visit.rb
+3
-3
app/services/boards/visits/latest_service.rb
app/services/boards/visits/latest_service.rb
+12
-4
spec/models/board_group_recent_visit_spec.rb
spec/models/board_group_recent_visit_spec.rb
+12
-6
spec/models/board_project_recent_visit_spec.rb
spec/models/board_project_recent_visit_spec.rb
+12
-6
spec/services/boards/visits/latest_service_spec.rb
spec/services/boards/visits/latest_service_spec.rb
+12
-0
No files found.
app/models/board_group_recent_visit.rb
View file @
5819115a
...
...
@@ -10,7 +10,7 @@ class BoardGroupRecentVisit < ActiveRecord::Base
validates
:group
,
presence:
true
validates
:board
,
presence:
true
scope
:by_user_group
,
->
(
user
,
group
)
{
where
(
user:
user
,
group:
group
)
.
order
(
:updated_at
)
}
scope
:by_user_group
,
->
(
user
,
group
)
{
where
(
user:
user
,
group:
group
)
}
def
self
.
visited!
(
user
,
board
)
visit
=
find_or_create_by
(
user:
user
,
group:
board
.
group
,
board:
board
)
...
...
@@ -19,7 +19,7 @@ class BoardGroupRecentVisit < ActiveRecord::Base
retry
end
def
self
.
latest
(
user
,
group
)
by_user_group
(
user
,
group
).
last
def
self
.
latest
(
user
,
group
,
count
=
nil
)
by_user_group
(
user
,
group
).
order
(
updated_at: :desc
).
first
(
count
)
end
end
app/models/board_project_recent_visit.rb
View file @
5819115a
...
...
@@ -10,7 +10,7 @@ class BoardProjectRecentVisit < ActiveRecord::Base
validates
:project
,
presence:
true
validates
:board
,
presence:
true
scope
:by_user_project
,
->
(
user
,
project
)
{
where
(
user:
user
,
project:
project
)
.
order
(
:updated_at
)
}
scope
:by_user_project
,
->
(
user
,
project
)
{
where
(
user:
user
,
project:
project
)
}
def
self
.
visited!
(
user
,
board
)
visit
=
find_or_create_by
(
user:
user
,
project:
board
.
project
,
board:
board
)
...
...
@@ -19,7 +19,7 @@ class BoardProjectRecentVisit < ActiveRecord::Base
retry
end
def
self
.
latest
(
user
,
project
)
by_user_project
(
user
,
project
).
last
def
self
.
latest
(
user
,
project
,
count
=
nil
)
by_user_project
(
user
,
project
).
order
(
updated_at: :desc
).
first
(
count
)
end
end
app/services/boards/visits/latest_service.rb
View file @
5819115a
...
...
@@ -6,11 +6,19 @@ module Boards
def
execute
return
nil
unless
current_user
if
parent
.
is_a?
(
Group
)
BoardGroupRecentVisit
.
latest
(
current_user
,
parent
)
else
BoardProjectRecentVisit
.
latest
(
current_user
,
parent
)
relation
=
recent_visit_model
if
params
[
:count
]
&&
params
[
:count
]
>
1
relation
=
relation
.
preload
(
:board
)
end
relation
.
latest
(
current_user
,
parent
,
params
[
:count
])
end
private
def
recent_visit_model
parent
.
is_a?
(
Group
)
?
BoardGroupRecentVisit
:
BoardProjectRecentVisit
end
end
end
...
...
spec/models/board_group_recent_visit_spec.rb
View file @
5819115a
...
...
@@ -51,14 +51,20 @@ describe BoardGroupRecentVisit do
describe
'#latest'
do
it
'returns the most recent visited'
do
board2
=
create
(
:board
,
group:
group
)
board3
=
create
(
:board
,
group:
group
)
create
:board_group_recent_visit
,
group:
board
.
group
,
board:
board
,
user:
user
,
updated_at:
7
.
days
.
ago
create
:board_group_recent_visit
,
group:
board2
.
group
,
board:
board2
,
user:
user
,
updated_at:
5
.
days
.
ago
recent
=
create
:board_group_recent_visit
,
group:
board3
.
group
,
board:
board3
,
user:
user
,
updated_at:
1
.
day
.
ago
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
7
.
days
.
ago
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
5
.
days
.
ago
recent
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
1
.
day
.
ago
expect
(
described_class
.
latest
(
user
,
group
)).
to
eq
recent
end
it
'returns last 3 visited boards'
do
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
7
.
days
.
ago
visit1
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
3
.
days
.
ago
visit2
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
2
.
days
.
ago
visit3
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
5
.
days
.
ago
expect
(
described_class
.
latest
(
user
,
group
,
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
end
end
end
spec/models/board_project_recent_visit_spec.rb
View file @
5819115a
...
...
@@ -51,14 +51,20 @@ describe BoardProjectRecentVisit do
describe
'#latest'
do
it
'returns the most recent visited'
do
board2
=
create
(
:board
,
project:
project
)
board3
=
create
(
:board
,
project:
project
)
create
:board_project_recent_visit
,
project:
board
.
project
,
board:
board
,
user:
user
,
updated_at:
7
.
days
.
ago
create
:board_project_recent_visit
,
project:
board2
.
project
,
board:
board2
,
user:
user
,
updated_at:
5
.
days
.
ago
recent
=
create
:board_project_recent_visit
,
project:
board3
.
project
,
board:
board3
,
user:
user
,
updated_at:
1
.
day
.
ago
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
7
.
days
.
ago
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
5
.
days
.
ago
recent
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
1
.
day
.
ago
expect
(
described_class
.
latest
(
user
,
project
)).
to
eq
recent
end
it
'returns last 3 visited boards'
do
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
7
.
days
.
ago
visit1
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
3
.
days
.
ago
visit2
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
2
.
days
.
ago
visit3
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
5
.
days
.
ago
expect
(
described_class
.
latest
(
user
,
project
,
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
end
end
end
spec/services/boards/visits/latest_service_spec.rb
View file @
5819115a
...
...
@@ -23,6 +23,12 @@ describe Boards::Visits::LatestService do
service
.
execute
end
it
'queries for last N visits'
do
expect
(
BoardProjectRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
project
,
5
).
once
described_class
.
new
(
project_board
.
parent
,
user
,
count:
5
).
execute
end
end
context
'when a group board'
do
...
...
@@ -42,6 +48,12 @@ describe Boards::Visits::LatestService do
service
.
execute
end
it
'queries for last N visits'
do
expect
(
BoardGroupRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
group
,
5
).
once
described_class
.
new
(
group_board
.
parent
,
user
,
count:
5
).
execute
end
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