debian-mirror-gitlab/app/models/users/merge_request_interaction.rb

45 lines
874 B
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Users
class MergeRequestInteraction
def initialize(user:, merge_request:)
@user = user
@merge_request = merge_request
end
def declarative_policy_subject
merge_request
end
def can_merge?
merge_request.can_be_merged_by?(user)
end
def can_update?
user.can?(:update_merge_request, merge_request)
end
def review_state
reviewer&.state
end
def reviewed?
reviewer&.reviewed? == true
end
def approved?
merge_request.approvals.any? { |app| app.user_id == user.id }
end
private
def reviewer
@reviewer ||= merge_request.merge_request_reviewers.find { |r| r.user_id == user.id }
end
attr_reader :user, :merge_request
end
end
2021-06-08 01:23:25 +05:30
::Users::MergeRequestInteraction.prepend_mod_with('Users::MergeRequestInteraction')