2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 14:10:34 -04:00
|
|
|
class IssuablePolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
delegate { @subject.project }
|
2016-08-16 14:10:34 -04:00
|
|
|
|
2017-09-01 08:03:57 -04:00
|
|
|
condition(:locked, scope: :subject, score: 0) { @subject.discussion_locked? }
|
2017-08-30 10:57:50 -04:00
|
|
|
condition(:is_project_member) { @user && @subject.project && @subject.project.team.member?(@user) }
|
2022-08-30 11:10:02 -04:00
|
|
|
condition(:can_read_issuable) { can?(:"read_#{@subject.to_ability_name}") }
|
2017-08-30 10:57:50 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "User is the assignee or author"
|
|
|
|
condition(:assignee_or_author) do
|
|
|
|
@user && @subject.assignee_or_author?(@user)
|
|
|
|
end
|
2016-08-16 14:10:34 -04:00
|
|
|
|
2021-10-28 14:14:18 -04:00
|
|
|
condition(:is_author) { @subject&.author == @user }
|
|
|
|
|
2022-05-20 08:08:50 -04:00
|
|
|
condition(:is_incident) { @subject.incident? }
|
|
|
|
|
|
|
|
rule { can?(:guest_access) & assignee_or_author & ~is_incident }.policy do
|
2017-04-06 17:06:42 -04:00
|
|
|
enable :read_issue
|
|
|
|
enable :update_issue
|
2018-08-19 15:43:41 -04:00
|
|
|
enable :reopen_issue
|
2021-12-06 22:12:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:read_merge_request) & assignee_or_author }.policy do
|
2017-04-06 17:06:42 -04:00
|
|
|
enable :update_merge_request
|
2019-03-08 03:34:20 -05:00
|
|
|
enable :reopen_merge_request
|
2016-08-16 14:10:34 -04:00
|
|
|
end
|
2017-08-30 10:57:50 -04:00
|
|
|
|
2021-10-28 14:14:18 -04:00
|
|
|
rule { is_author }.policy do
|
|
|
|
enable :resolve_note
|
|
|
|
end
|
|
|
|
|
2017-09-01 08:03:57 -04:00
|
|
|
rule { locked & ~is_project_member }.policy do
|
|
|
|
prevent :create_note
|
|
|
|
prevent :admin_note
|
|
|
|
prevent :resolve_note
|
2020-08-24 17:10:17 -04:00
|
|
|
prevent :award_emoji
|
2017-09-01 08:03:57 -04:00
|
|
|
end
|
2022-05-11 08:09:03 -04:00
|
|
|
|
|
|
|
rule { can?(:read_issue) }.policy do
|
|
|
|
enable :read_incident_management_timeline_event
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:read_issue) & can?(:developer_access) }.policy do
|
|
|
|
enable :admin_incident_management_timeline_event
|
|
|
|
end
|
2022-07-27 11:09:42 -04:00
|
|
|
|
|
|
|
rule { can?(:reporter_access) }.policy do
|
|
|
|
enable :create_timelog
|
|
|
|
end
|
2022-08-30 11:10:02 -04:00
|
|
|
|
|
|
|
rule { can_read_issuable }.policy do
|
|
|
|
enable :read_issuable
|
|
|
|
end
|
2016-08-16 14:10:34 -04:00
|
|
|
end
|
2020-11-20 07:09:35 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
IssuablePolicy.prepend_mod_with('IssuablePolicy')
|