2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 14:32:08 -04:00
|
|
|
class MergeRequestPolicy < IssuablePolicy
|
2019-03-08 03:34:20 -05:00
|
|
|
rule { locked }.policy do
|
|
|
|
prevent :reopen_merge_request
|
|
|
|
end
|
2019-06-04 23:30:54 -04:00
|
|
|
|
|
|
|
# Only users who can read the merge request can comment.
|
|
|
|
# Although :read_merge_request is computed in the policy context,
|
|
|
|
# it would not be safe to prevent :create_note there, since
|
|
|
|
# note permissions are shared, and this would apply too broadly.
|
2021-03-08 19:09:23 -05:00
|
|
|
rule { ~can?(:read_merge_request) }.policy do
|
|
|
|
prevent :create_note
|
|
|
|
prevent :accept_merge_request
|
|
|
|
end
|
2020-07-10 14:09:45 -04:00
|
|
|
|
|
|
|
rule { can?(:update_merge_request) }.policy do
|
|
|
|
enable :approve_merge_request
|
|
|
|
end
|
2020-10-30 14:08:56 -04:00
|
|
|
|
|
|
|
rule { ~anonymous & can?(:read_merge_request) }.policy do
|
|
|
|
enable :create_todo
|
|
|
|
end
|
2021-03-08 19:09:23 -05:00
|
|
|
|
|
|
|
condition(:can_merge) { @subject.can_be_merged_by?(@user) }
|
|
|
|
|
|
|
|
rule { can_merge }.policy do
|
|
|
|
enable :accept_merge_request
|
|
|
|
end
|
2016-08-16 14:32:08 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
MergeRequestPolicy.prepend_if_ee('EE::MergeRequestPolicy')
|