2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-12-03 22:09:49 -05:00
|
|
|
class MergeRequestUserEntity < ::API::Entities::UserBasic
|
2021-01-28 13:09:27 -05:00
|
|
|
include UserStatusTooltip
|
2021-02-02 07:10:15 -05:00
|
|
|
include RequestAwareEntity
|
2021-01-28 13:09:27 -05:00
|
|
|
|
2021-03-01 13:11:21 -05:00
|
|
|
def self.satisfies(*methods)
|
|
|
|
->(_, options) { methods.all? { |m| options[:merge_request].try(m) } }
|
|
|
|
end
|
|
|
|
|
2020-12-03 22:09:49 -05:00
|
|
|
expose :can_merge do |reviewer, options|
|
|
|
|
options[:merge_request]&.can_be_merged_by?(reviewer)
|
2018-06-21 08:22:40 -04:00
|
|
|
end
|
2021-02-02 07:10:15 -05:00
|
|
|
|
|
|
|
expose :can_update_merge_request do |reviewer, options|
|
|
|
|
request.current_user&.can?(:update_merge_request, options[:merge_request])
|
|
|
|
end
|
|
|
|
|
2021-03-01 13:11:21 -05:00
|
|
|
expose :reviewed, if: satisfies(:present?, :allows_reviewers?) do |reviewer, options|
|
2021-02-02 07:10:15 -05:00
|
|
|
reviewer = options[:merge_request].find_reviewer(reviewer)
|
|
|
|
|
|
|
|
reviewer&.reviewed?
|
|
|
|
end
|
2021-03-01 13:11:21 -05:00
|
|
|
|
|
|
|
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-06-21 08:22:40 -04:00
|
|
|
end
|
2020-12-03 22:09:49 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
MergeRequestUserEntity.prepend_mod_with('MergeRequestUserEntity')
|