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
c5b3b71e
Commit
c5b3b71e
authored
Feb 27, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CE-port for 7714-view-recent-boards
Adds additional count param to Boards::Visits::LatestService
parent
31353188
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
26 deletions
+65
-26
app/models/board_group_recent_visit.rb
app/models/board_group_recent_visit.rb
+6
-3
app/models/board_project_recent_visit.rb
app/models/board_project_recent_visit.rb
+6
-3
app/services/boards/visits/latest_service.rb
app/services/boards/visits/latest_service.rb
+7
-5
config/routes/group.rb
config/routes/group.rb
+1
-1
config/routes/project.rb
config/routes/project.rb
+1
-2
spec/models/board_group_recent_visit_spec.rb
spec/models/board_group_recent_visit_spec.rb
+16
-6
spec/models/board_project_recent_visit_spec.rb
spec/models/board_project_recent_visit_spec.rb
+16
-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 @
c5b3b71e
...
@@ -10,7 +10,7 @@ class BoardGroupRecentVisit < ActiveRecord::Base
...
@@ -10,7 +10,7 @@ class BoardGroupRecentVisit < ActiveRecord::Base
validates
:group
,
presence:
true
validates
:group
,
presence:
true
validates
:board
,
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
)
def
self
.
visited!
(
user
,
board
)
visit
=
find_or_create_by
(
user:
user
,
group:
board
.
group
,
board:
board
)
visit
=
find_or_create_by
(
user:
user
,
group:
board
.
group
,
board:
board
)
...
@@ -19,7 +19,10 @@ class BoardGroupRecentVisit < ActiveRecord::Base
...
@@ -19,7 +19,10 @@ class BoardGroupRecentVisit < ActiveRecord::Base
retry
retry
end
end
def
self
.
latest
(
user
,
group
)
def
self
.
latest
(
user
,
group
,
count:
nil
)
by_user_group
(
user
,
group
).
last
visits
=
by_user_group
(
user
,
group
).
order
(
updated_at: :desc
)
visits
=
visits
.
preload
(
:board
)
if
count
&&
count
>
1
visits
.
first
(
count
)
end
end
end
end
app/models/board_project_recent_visit.rb
View file @
c5b3b71e
...
@@ -10,7 +10,7 @@ class BoardProjectRecentVisit < ActiveRecord::Base
...
@@ -10,7 +10,7 @@ class BoardProjectRecentVisit < ActiveRecord::Base
validates
:project
,
presence:
true
validates
:project
,
presence:
true
validates
:board
,
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
)
def
self
.
visited!
(
user
,
board
)
visit
=
find_or_create_by
(
user:
user
,
project:
board
.
project
,
board:
board
)
visit
=
find_or_create_by
(
user:
user
,
project:
board
.
project
,
board:
board
)
...
@@ -19,7 +19,10 @@ class BoardProjectRecentVisit < ActiveRecord::Base
...
@@ -19,7 +19,10 @@ class BoardProjectRecentVisit < ActiveRecord::Base
retry
retry
end
end
def
self
.
latest
(
user
,
project
)
def
self
.
latest
(
user
,
project
,
count:
nil
)
by_user_project
(
user
,
project
).
last
visits
=
by_user_project
(
user
,
project
).
order
(
updated_at: :desc
)
visits
=
visits
.
preload
(
:board
)
if
count
&&
count
>
1
visits
.
first
(
count
)
end
end
end
end
app/services/boards/visits/latest_service.rb
View file @
c5b3b71e
...
@@ -6,11 +6,13 @@ module Boards
...
@@ -6,11 +6,13 @@ module Boards
def
execute
def
execute
return
nil
unless
current_user
return
nil
unless
current_user
if
parent
.
is_a?
(
Group
)
recent_visit_model
.
latest
(
current_user
,
parent
,
count:
params
[
:count
])
BoardGroupRecentVisit
.
latest
(
current_user
,
parent
)
end
else
BoardProjectRecentVisit
.
latest
(
current_user
,
parent
)
private
end
def
recent_visit_model
parent
.
is_a?
(
Group
)
?
BoardGroupRecentVisit
:
BoardProjectRecentVisit
end
end
end
end
end
end
...
...
config/routes/group.rb
View file @
c5b3b71e
...
@@ -67,7 +67,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
...
@@ -67,7 +67,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
end
end
end
end
resources
:boards
,
only:
[
:index
,
:show
]
resources
:boards
,
only:
[
:index
,
:show
]
,
constraints:
{
id:
/\d+/
}
resources
:runners
,
only:
[
:index
,
:edit
,
:update
,
:destroy
,
:show
]
do
resources
:runners
,
only:
[
:index
,
:edit
,
:update
,
:destroy
,
:show
]
do
member
do
member
do
...
...
config/routes/project.rb
View file @
c5b3b71e
...
@@ -394,8 +394,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
...
@@ -394,8 +394,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get
'noteable/:target_type/:target_id/notes'
=>
'notes#index'
,
as:
'noteable_notes'
get
'noteable/:target_type/:target_id/notes'
=>
'notes#index'
,
as:
'noteable_notes'
# On CE only index and show are needed
resources
:boards
,
only:
[
:index
,
:show
],
constraints:
{
id:
/\d+/
}
resources
:boards
,
only:
[
:index
,
:show
]
resources
:todos
,
only:
[
:create
]
resources
:todos
,
only:
[
:create
]
...
...
spec/models/board_group_recent_visit_spec.rb
View file @
c5b3b71e
...
@@ -50,15 +50,25 @@ describe BoardGroupRecentVisit do
...
@@ -50,15 +50,25 @@ describe BoardGroupRecentVisit do
end
end
describe
'#latest'
do
describe
'#latest'
do
it
'returns the most recent visited'
do
def
create_visit
(
time
)
board2
=
create
(
:board
,
group:
group
)
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
time
board3
=
create
(
:board
,
group:
group
)
end
create
:board_group_recent_visit
,
group:
board
.
group
,
board:
board
,
user:
user
,
updated_at:
7
.
days
.
ago
it
'returns the most recent visited'
do
create
:board_group_recent_visit
,
group:
board2
.
group
,
board:
board2
,
user:
user
,
updated_at:
5
.
days
.
ago
create_visit
(
7
.
days
.
ago
)
recent
=
create
:board_group_recent_visit
,
group:
board3
.
group
,
board:
board3
,
user:
user
,
updated_at:
1
.
day
.
ago
create_visit
(
5
.
days
.
ago
)
recent
=
create_visit
(
1
.
day
.
ago
)
expect
(
described_class
.
latest
(
user
,
group
)).
to
eq
recent
expect
(
described_class
.
latest
(
user
,
group
)).
to
eq
recent
end
end
it
'returns last 3 visited boards'
do
create_visit
(
7
.
days
.
ago
)
visit1
=
create_visit
(
3
.
days
.
ago
)
visit2
=
create_visit
(
2
.
days
.
ago
)
visit3
=
create_visit
(
5
.
days
.
ago
)
expect
(
described_class
.
latest
(
user
,
group
,
count:
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
end
end
end
end
end
spec/models/board_project_recent_visit_spec.rb
View file @
c5b3b71e
...
@@ -50,15 +50,25 @@ describe BoardProjectRecentVisit do
...
@@ -50,15 +50,25 @@ describe BoardProjectRecentVisit do
end
end
describe
'#latest'
do
describe
'#latest'
do
it
'returns the most recent visited'
do
def
create_visit
(
time
)
board2
=
create
(
:board
,
project:
project
)
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
time
board3
=
create
(
:board
,
project:
project
)
end
create
:board_project_recent_visit
,
project:
board
.
project
,
board:
board
,
user:
user
,
updated_at:
7
.
days
.
ago
it
'returns the most recent visited'
do
create
:board_project_recent_visit
,
project:
board2
.
project
,
board:
board2
,
user:
user
,
updated_at:
5
.
days
.
ago
create_visit
(
7
.
days
.
ago
)
recent
=
create
:board_project_recent_visit
,
project:
board3
.
project
,
board:
board3
,
user:
user
,
updated_at:
1
.
day
.
ago
create_visit
(
5
.
days
.
ago
)
recent
=
create_visit
(
1
.
day
.
ago
)
expect
(
described_class
.
latest
(
user
,
project
)).
to
eq
recent
expect
(
described_class
.
latest
(
user
,
project
)).
to
eq
recent
end
end
it
'returns last 3 visited boards'
do
create_visit
(
7
.
days
.
ago
)
visit1
=
create_visit
(
3
.
days
.
ago
)
visit2
=
create_visit
(
2
.
days
.
ago
)
visit3
=
create_visit
(
5
.
days
.
ago
)
expect
(
described_class
.
latest
(
user
,
project
,
count:
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
end
end
end
end
end
spec/services/boards/visits/latest_service_spec.rb
View file @
c5b3b71e
...
@@ -23,6 +23,12 @@ describe Boards::Visits::LatestService do
...
@@ -23,6 +23,12 @@ describe Boards::Visits::LatestService do
service
.
execute
service
.
execute
end
end
it
'queries for last N visits'
do
expect
(
BoardProjectRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
project
,
count:
5
).
once
described_class
.
new
(
project_board
.
parent
,
user
,
count:
5
).
execute
end
end
end
context
'when a group board'
do
context
'when a group board'
do
...
@@ -42,6 +48,12 @@ describe Boards::Visits::LatestService do
...
@@ -42,6 +48,12 @@ describe Boards::Visits::LatestService do
service
.
execute
service
.
execute
end
end
it
'queries for last N visits'
do
expect
(
BoardGroupRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
group
,
count:
5
).
once
described_class
.
new
(
group_board
.
parent
,
user
,
count:
5
).
execute
end
end
end
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