debian-mirror-gitlab/app/serializers/merge_request_user_entity.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
1 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2021-02-22 17:27:13 +05:30
class MergeRequestUserEntity < ::API::Entities::UserBasic
2021-03-11 19:13:27 +05:30
include UserStatusTooltip
include RequestAwareEntity
2021-04-17 20:07:23 +05:30
def self.satisfies(*methods)
->(_, options) { methods.all? { |m| options[:merge_request].try(m) } }
end
2021-02-22 17:27:13 +05:30
expose :can_merge do |reviewer, options|
options[:merge_request]&.can_be_merged_by?(reviewer)
2018-11-08 19:23:39 +05:30
end
2021-03-11 19:13:27 +05:30
expose :can_update_merge_request do |reviewer, options|
request.current_user&.can?(:update_merge_request, options[:merge_request])
end
2021-12-11 22:18:48 +05:30
expose :reviewed, if: satisfies(:present?, :allows_reviewers?) do |user, options|
2022-10-11 01:57:18 +05:30
options[:merge_request].find_reviewer(user)&.reviewed?
2021-12-11 22:18:48 +05:30
end
2021-03-11 19:13:27 +05:30
2021-04-17 20:07:23 +05:30
expose :approved, if: satisfies(:present?) do |user, options|
# This approach is preferred over MergeRequest#approved_by? since this
# makes one query per merge request, whereas #approved_by? makes one per user
options[:merge_request].approvals.any? { |app| app.user_id == user.id }
end
2018-11-08 19:23:39 +05:30
end
2021-02-22 17:27:13 +05:30
2021-06-08 01:23:25 +05:30
MergeRequestUserEntity.prepend_mod_with('MergeRequestUserEntity')