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
f74b33cf
Commit
f74b33cf
authored
Aug 01, 2019
by
Igor
Committed by
Robert Speicher
Aug 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add can_merge option to autocomplete response
It's used only if merge_request_iid param is provided
parent
5b38fced
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
1 deletion
+62
-1
app/controllers/autocomplete_controller.rb
app/controllers/autocomplete_controller.rb
+1
-1
app/serializers/user_serializer.rb
app/serializers/user_serializer.rb
+17
-0
spec/controllers/autocomplete_controller_spec.rb
spec/controllers/autocomplete_controller_spec.rb
+14
-0
spec/serializers/user_serializer_spec.rb
spec/serializers/user_serializer_spec.rb
+30
-0
No files found.
app/controllers/autocomplete_controller.rb
View file @
f74b33cf
...
...
@@ -16,7 +16,7 @@ class AutocompleteController < ApplicationController
.
new
(
params:
params
,
current_user:
current_user
,
project:
project
,
group:
group
)
.
execute
render
json:
UserSerializer
.
new
.
represent
(
users
)
render
json:
UserSerializer
.
new
(
params
).
represent
(
users
,
project:
project
)
end
def
user
...
...
app/serializers/user_serializer.rb
View file @
f74b33cf
...
...
@@ -2,4 +2,21 @@
class
UserSerializer
<
BaseSerializer
entity
UserEntity
def
represent
(
resource
,
opts
=
{},
entity
=
nil
)
if
params
[
:merge_request_iid
]
merge_request
=
opts
[
:project
].
merge_requests
.
find_by_iid!
(
params
[
:merge_request_iid
])
preload_max_member_access
(
merge_request
.
project
,
Array
(
resource
))
super
(
resource
,
opts
.
merge
(
merge_request:
merge_request
),
MergeRequestAssigneeEntity
)
else
super
end
end
private
def
preload_max_member_access
(
project
,
users
)
project
.
team
.
max_member_access_for_user_ids
(
users
.
map
(
&
:id
))
end
end
spec/controllers/autocomplete_controller_spec.rb
View file @
f74b33cf
...
...
@@ -222,6 +222,20 @@ describe AutocompleteController do
expect
(
response_user_ids
).
to
contain_exactly
(
non_member
.
id
)
end
end
context
'merge_request_iid parameter included'
do
before
do
sign_in
(
user
)
end
it
'includes can_merge option to users'
do
merge_request
=
create
(
:merge_request
,
source_project:
project
)
get
(
:users
,
params:
{
merge_request_iid:
merge_request
.
iid
,
project_id:
project
.
id
})
expect
(
json_response
.
first
).
to
have_key
(
'can_merge'
)
end
end
end
context
'GET projects'
do
...
...
spec/serializers/user_serializer_spec.rb
0 → 100644
View file @
f74b33cf
# frozen_string_literal: true
require
'spec_helper'
describe
UserSerializer
do
let
(
:user1
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
context
'serializer with merge request context'
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:project
)
{
merge_request
.
project
}
let
(
:serializer
)
{
described_class
.
new
(
merge_request_iid:
merge_request
.
iid
)
}
before
do
allow
(
project
).
to
(
receive_message_chain
(
:merge_requests
,
:find_by_iid!
)
.
with
(
merge_request
.
iid
).
and_return
(
merge_request
)
)
project
.
add_maintainer
(
user1
)
end
it
'returns a user with can_merge option'
do
serialized_user1
,
serialized_user2
=
serializer
.
represent
([
user1
,
user2
],
project:
project
).
as_json
expect
(
serialized_user1
).
to
include
(
"id"
=>
user1
.
id
,
"can_merge"
=>
true
)
expect
(
serialized_user2
).
to
include
(
"id"
=>
user2
.
id
,
"can_merge"
=>
false
)
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