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
5132825b
Commit
5132825b
authored
Feb 27, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoint for recent boards
Returns last 5 visited boards
parent
5819115a
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
105 additions
and
33 deletions
+105
-33
app/models/board_group_recent_visit.rb
app/models/board_group_recent_visit.rb
+5
-2
app/models/board_project_recent_visit.rb
app/models/board_project_recent_visit.rb
+5
-2
app/services/boards/visits/latest_service.rb
app/services/boards/visits/latest_service.rb
+1
-7
config/routes/group.rb
config/routes/group.rb
+1
-1
config/routes/project.rb
config/routes/project.rb
+1
-2
ee/app/controllers/ee/boards/boards_controller.rb
ee/app/controllers/ee/boards/boards_controller.rb
+7
-0
ee/config/routes/group.rb
ee/config/routes/group.rb
+5
-1
ee/config/routes/project.rb
ee/config/routes/project.rb
+6
-0
ee/spec/controllers/groups/boards_controller_spec.rb
ee/spec/controllers/groups/boards_controller_spec.rb
+6
-0
ee/spec/controllers/projects/boards_controller_spec.rb
ee/spec/controllers/projects/boards_controller_spec.rb
+6
-0
ee/spec/support/shared_examples/controllers/recent_boards.rb
ee/spec/support/shared_examples/controllers/recent_boards.rb
+36
-0
spec/models/board_group_recent_visit_spec.rb
spec/models/board_group_recent_visit_spec.rb
+12
-8
spec/models/board_project_recent_visit_spec.rb
spec/models/board_project_recent_visit_spec.rb
+12
-8
spec/services/boards/visits/latest_service_spec.rb
spec/services/boards/visits/latest_service_spec.rb
+2
-2
No files found.
app/models/board_group_recent_visit.rb
View file @
5132825b
...
@@ -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
,
count
=
nil
)
def
self
.
latest
(
user
,
group
,
count:
nil
)
by_user_group
(
user
,
group
).
order
(
updated_at: :desc
).
first
(
count
)
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 @
5132825b
...
@@ -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
,
count
=
nil
)
def
self
.
latest
(
user
,
project
,
count:
nil
)
by_user_project
(
user
,
project
).
order
(
updated_at: :desc
).
first
(
count
)
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 @
5132825b
...
@@ -6,13 +6,7 @@ module Boards
...
@@ -6,13 +6,7 @@ module Boards
def
execute
def
execute
return
nil
unless
current_user
return
nil
unless
current_user
relation
=
recent_visit_model
recent_visit_model
.
latest
(
current_user
,
parent
,
count:
params
[
:count
])
if
params
[
:count
]
&&
params
[
:count
]
>
1
relation
=
relation
.
preload
(
:board
)
end
relation
.
latest
(
current_user
,
parent
,
params
[
:count
])
end
end
private
private
...
...
config/routes/group.rb
View file @
5132825b
...
@@ -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 @
5132825b
...
@@ -475,8 +475,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
...
@@ -475,8 +475,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
,
:create
,
:update
,
:destroy
]
resources
:todos
,
only:
[
:create
]
resources
:todos
,
only:
[
:create
]
...
...
ee/app/controllers/ee/boards/boards_controller.rb
View file @
5132825b
...
@@ -12,6 +12,13 @@ module EE
...
@@ -12,6 +12,13 @@ module EE
before_action
:authorize_admin_board!
,
only:
[
:create
,
:update
,
:destroy
]
before_action
:authorize_admin_board!
,
only:
[
:create
,
:update
,
:destroy
]
end
end
def
recent
recent_visits
=
::
Boards
::
Visits
::
LatestService
.
new
(
parent
,
current_user
,
count:
5
).
execute
recent_boards
=
recent_visits
.
map
(
&
:board
)
render
json:
serialize_as_json
(
recent_boards
)
end
def
create
def
create
board
=
::
Boards
::
CreateService
.
new
(
parent
,
current_user
,
board_params
).
execute
board
=
::
Boards
::
CreateService
.
new
(
parent
,
current_user
,
board_params
).
execute
...
...
ee/config/routes/group.rb
View file @
5132825b
...
@@ -67,7 +67,11 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
...
@@ -67,7 +67,11 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
end
end
resources
:todos
,
only:
[
:create
]
resources
:todos
,
only:
[
:create
]
resources
:boards
,
only:
[
:create
,
:update
,
:destroy
]
resources
:boards
,
only:
[
:create
,
:update
,
:destroy
]
do
collection
do
get
:recent
end
end
namespace
:security
do
namespace
:security
do
resource
:dashboard
,
only:
[
:show
],
controller: :dashboard
resource
:dashboard
,
only:
[
:show
],
controller: :dashboard
...
...
ee/config/routes/project.rb
View file @
5132825b
...
@@ -17,6 +17,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
...
@@ -17,6 +17,12 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
end
end
end
resources
:boards
,
only:
[
:create
,
:update
,
:destroy
]
do
collection
do
get
:recent
end
end
resources
:web_ide_terminals
,
path: :ide_terminals
,
only:
[
:create
,
:show
],
constraints:
{
id:
/\d+/
,
format: :json
}
do
resources
:web_ide_terminals
,
path: :ide_terminals
,
only:
[
:create
,
:show
],
constraints:
{
id:
/\d+/
,
format: :json
}
do
member
do
member
do
post
:cancel
post
:cancel
...
...
ee/spec/controllers/groups/boards_controller_spec.rb
View file @
5132825b
...
@@ -52,6 +52,12 @@ describe Groups::BoardsController do
...
@@ -52,6 +52,12 @@ describe Groups::BoardsController do
end
end
end
end
describe
'GET recent'
do
let
(
:parent
)
{
group
}
it_behaves_like
'returns recently visited boards'
end
describe
'GET show'
do
describe
'GET show'
do
context
'for multiple issue boards'
do
context
'for multiple issue boards'
do
let
(
:parent
)
{
group
}
let
(
:parent
)
{
group
}
...
...
ee/spec/controllers/projects/boards_controller_spec.rb
View file @
5132825b
...
@@ -38,6 +38,12 @@ describe Projects::BoardsController do
...
@@ -38,6 +38,12 @@ describe Projects::BoardsController do
end
end
end
end
describe
'GET recent'
do
let
(
:parent
)
{
project
}
it_behaves_like
'returns recently visited boards'
end
describe
'GET show'
do
describe
'GET show'
do
let
(
:parent
)
{
project
}
let
(
:parent
)
{
project
}
...
...
ee/spec/support/shared_examples/controllers/recent_boards.rb
0 → 100644
View file @
5132825b
# frozen_string_literal: true
require
'spec_helper'
shared_examples
'returns recently visited boards'
do
let
(
:boards
)
{
create_list
(
:board
,
8
,
parent:
parent
)
}
it
'returns last 5 visited boards'
do
[
0
,
2
,
5
,
3
,
7
,
1
].
each_with_index
do
|
board_index
,
i
|
visit_board
(
boards
[
board_index
],
Time
.
now
+
i
.
minutes
)
end
get_recent_boards
expect
(
json_response
.
length
).
to
eq
(
5
)
expect
(
json_response
.
map
{
|
b
|
b
[
'id'
]
}).
to
eq
([
1
,
7
,
3
,
5
,
2
].
map
{
|
i
|
boards
[
i
].
id
})
end
def
visit_board
(
board
,
time
)
if
parent
.
is_a?
(
Group
)
create
(
:board_group_recent_visit
,
group:
parent
,
board:
board
,
user:
user
,
updated_at:
time
)
else
create
(
:board_project_recent_visit
,
project:
parent
,
board:
board
,
user:
user
,
updated_at:
time
)
end
end
def
get_recent_boards
params
=
if
parent
.
is_a?
(
Group
)
{
group_id:
parent
}
else
{
namespace_id:
parent
.
namespace
,
project_id:
parent
}
end
get
:recent
,
params:
params
end
end
spec/models/board_group_recent_visit_spec.rb
View file @
5132825b
...
@@ -50,21 +50,25 @@ describe BoardGroupRecentVisit do
...
@@ -50,21 +50,25 @@ describe BoardGroupRecentVisit do
end
end
describe
'#latest'
do
describe
'#latest'
do
def
create_visit
(
time
)
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
time
end
it
'returns the most recent visited'
do
it
'returns the most recent visited'
do
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
7
.
days
.
ago
create
_visit
(
7
.
days
.
ago
)
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
5
.
days
.
ago
create
_visit
(
5
.
days
.
ago
)
recent
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
1
.
day
.
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
it
'returns last 3 visited boards'
do
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
7
.
days
.
ago
create
_visit
(
7
.
days
.
ago
)
visit1
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
3
.
days
.
ago
visit1
=
create
_visit
(
3
.
days
.
ago
)
visit2
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
2
.
days
.
ago
visit2
=
create
_visit
(
2
.
days
.
ago
)
visit3
=
create
:board_group_recent_visit
,
group:
group
,
user:
user
,
updated_at:
5
.
days
.
ago
visit3
=
create
_visit
(
5
.
days
.
ago
)
expect
(
described_class
.
latest
(
user
,
group
,
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
expect
(
described_class
.
latest
(
user
,
group
,
count:
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
end
end
end
end
end
end
spec/models/board_project_recent_visit_spec.rb
View file @
5132825b
...
@@ -50,21 +50,25 @@ describe BoardProjectRecentVisit do
...
@@ -50,21 +50,25 @@ describe BoardProjectRecentVisit do
end
end
describe
'#latest'
do
describe
'#latest'
do
def
create_visit
(
time
)
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
time
end
it
'returns the most recent visited'
do
it
'returns the most recent visited'
do
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
7
.
days
.
ago
create
_visit
(
7
.
days
.
ago
)
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
5
.
days
.
ago
create
_visit
(
5
.
days
.
ago
)
recent
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
1
.
day
.
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
it
'returns last 3 visited boards'
do
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
7
.
days
.
ago
create
_visit
(
7
.
days
.
ago
)
visit1
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
3
.
days
.
ago
visit1
=
create
_visit
(
3
.
days
.
ago
)
visit2
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
2
.
days
.
ago
visit2
=
create
_visit
(
2
.
days
.
ago
)
visit3
=
create
:board_project_recent_visit
,
project:
project
,
user:
user
,
updated_at:
5
.
days
.
ago
visit3
=
create
_visit
(
5
.
days
.
ago
)
expect
(
described_class
.
latest
(
user
,
project
,
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
expect
(
described_class
.
latest
(
user
,
project
,
count:
3
)).
to
eq
([
visit2
,
visit1
,
visit3
])
end
end
end
end
end
end
spec/services/boards/visits/latest_service_spec.rb
View file @
5132825b
...
@@ -25,7 +25,7 @@ describe Boards::Visits::LatestService do
...
@@ -25,7 +25,7 @@ describe Boards::Visits::LatestService do
end
end
it
'queries for last N visits'
do
it
'queries for last N visits'
do
expect
(
BoardProjectRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
project
,
5
).
once
expect
(
BoardProjectRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
project
,
count:
5
).
once
described_class
.
new
(
project_board
.
parent
,
user
,
count:
5
).
execute
described_class
.
new
(
project_board
.
parent
,
user
,
count:
5
).
execute
end
end
...
@@ -50,7 +50,7 @@ describe Boards::Visits::LatestService do
...
@@ -50,7 +50,7 @@ describe Boards::Visits::LatestService do
end
end
it
'queries for last N visits'
do
it
'queries for last N visits'
do
expect
(
BoardGroupRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
group
,
5
).
once
expect
(
BoardGroupRecentVisit
).
to
receive
(
:latest
).
with
(
user
,
group
,
count:
5
).
once
described_class
.
new
(
group_board
.
parent
,
user
,
count:
5
).
execute
described_class
.
new
(
group_board
.
parent
,
user
,
count:
5
).
execute
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