summaryrefslogtreecommitdiff
path: root/app/serializers/user_serializer.rb
blob: 5e7dab31e8a1da81164ecd6435927353a38c932b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

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), MergeRequestUserEntity)
    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

UserSerializer.prepend_mod_with('UserSerializer')