diff options
author | Igor <idrozdov@gitlab.com> | 2019-08-01 19:51:14 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2019-08-01 19:51:14 +0300 |
commit | f74b33cf6e5ee415417d9f2ee255f97ab6fcf7ad (patch) | |
tree | e05c4aaaf46e2f8d080c49f5a3575f32d962bdc8 /app/serializers | |
parent | 5b38fced90e81241b4266bac78c8e53a432f5144 (diff) |
Add can_merge option to autocomplete response
It's used only if merge_request_iid param is provided
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/user_serializer.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 2111e1b5667..d988caea92d 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -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 |