2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 14:10:34 -04:00
|
|
|
class IssuePolicy < IssuablePolicy
|
2016-11-01 16:18:51 -04:00
|
|
|
# This class duplicates the same check of Issue#readable_by? for performance reasons
|
|
|
|
# Make sure to sync this class checks with issue.rb to avoid security problems.
|
|
|
|
# Check commit 002ad215818450d2cbbc5fa065850a953dc7ada8 for more information.
|
|
|
|
|
2020-04-13 11:09:20 -04:00
|
|
|
include CrudPolicyHelpers
|
2019-06-04 23:30:54 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "User can read confidential issues"
|
|
|
|
condition(:can_read_confidential) do
|
|
|
|
@user && IssueCollection.new([@subject]).visible_to(@user).any?
|
2016-08-16 14:10:34 -04:00
|
|
|
end
|
|
|
|
|
2022-04-29 17:10:44 -04:00
|
|
|
desc "Project belongs to a group, crm is enabled and user can read contacts in the root group"
|
|
|
|
condition(:can_read_crm_contacts, scope: :subject) do
|
|
|
|
subject.project.group&.crm_enabled? &&
|
2022-05-31 05:08:17 -04:00
|
|
|
(@user&.can?(:read_crm_contact, @subject.project.root_ancestor) || @user&.support_bot?)
|
2022-04-29 17:10:44 -04:00
|
|
|
end
|
2021-11-08 07:12:07 -05:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "Issue is confidential"
|
|
|
|
condition(:confidential, scope: :subject) { @subject.confidential? }
|
2016-08-16 14:10:34 -04:00
|
|
|
|
2021-08-12 14:10:45 -04:00
|
|
|
desc "Issue is hidden"
|
|
|
|
condition(:hidden, scope: :subject) { @subject.hidden? }
|
|
|
|
|
2021-06-11 14:10:13 -04:00
|
|
|
desc "Issue is persisted"
|
|
|
|
condition(:persisted, scope: :subject) { @subject.persisted? }
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { confidential & ~can_read_confidential }.policy do
|
2019-06-04 23:30:54 -04:00
|
|
|
prevent(*create_read_update_admin_destroy(:issue))
|
2017-12-11 09:21:06 -05:00
|
|
|
prevent :read_issue_iid
|
2016-08-16 14:10:34 -04:00
|
|
|
end
|
2018-08-19 15:43:41 -04:00
|
|
|
|
2021-08-12 14:10:45 -04:00
|
|
|
rule { hidden & ~admin }.policy do
|
|
|
|
prevent :read_issue
|
|
|
|
end
|
|
|
|
|
2019-06-04 23:30:54 -04:00
|
|
|
rule { ~can?(:read_issue) }.prevent :create_note
|
|
|
|
|
2018-08-19 15:43:41 -04:00
|
|
|
rule { locked }.policy do
|
|
|
|
prevent :reopen_issue
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2020-05-04 08:09:46 -04:00
|
|
|
rule { ~can?(:read_issue) }.policy do
|
|
|
|
prevent :read_design
|
|
|
|
prevent :create_design
|
|
|
|
prevent :destroy_design
|
|
|
|
end
|
|
|
|
|
2020-07-27 20:10:23 -04:00
|
|
|
rule { ~can?(:read_design) }.policy do
|
|
|
|
prevent :move_design
|
|
|
|
end
|
2020-10-30 14:08:56 -04:00
|
|
|
|
|
|
|
rule { ~anonymous & can?(:read_issue) }.policy do
|
|
|
|
enable :create_todo
|
2021-05-21 08:10:27 -04:00
|
|
|
enable :update_subscription
|
2020-10-30 14:08:56 -04:00
|
|
|
end
|
2021-06-11 14:10:13 -04:00
|
|
|
|
2022-06-29 17:09:23 -04:00
|
|
|
rule { can?(:admin_issue) }.policy do
|
2021-08-03 17:09:39 -04:00
|
|
|
enable :set_issue_metadata
|
|
|
|
end
|
|
|
|
|
|
|
|
# guest members need to be able to set issue metadata per https://gitlab.com/gitlab-org/gitlab/-/issues/300100
|
|
|
|
rule { ~persisted & is_project_member & can?(:guest_access) }.policy do
|
2021-06-11 14:10:13 -04:00
|
|
|
enable :set_issue_metadata
|
|
|
|
end
|
|
|
|
|
2021-08-25 05:10:52 -04:00
|
|
|
rule { can?(:set_issue_metadata) }.policy do
|
|
|
|
enable :set_confidentiality
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { ~persisted & can?(:create_issue) }.policy do
|
|
|
|
enable :set_confidentiality
|
|
|
|
end
|
2021-11-08 07:12:07 -05:00
|
|
|
|
2022-04-29 17:10:44 -04:00
|
|
|
rule { can_read_crm_contacts }.policy do
|
|
|
|
enable :read_crm_contacts
|
|
|
|
end
|
|
|
|
|
2021-11-08 07:12:07 -05:00
|
|
|
rule { can?(:set_issue_metadata) & can_read_crm_contacts }.policy do
|
|
|
|
enable :set_issue_crm_contacts
|
|
|
|
end
|
2022-10-12 08:09:35 -04:00
|
|
|
|
|
|
|
rule { can?(:reporter_access) }.policy do
|
|
|
|
enable :mark_note_as_confidential
|
|
|
|
end
|
2020-05-04 08:09:46 -04:00
|
|
|
end
|
2020-07-23 14:10:06 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
IssuePolicy.prepend_mod_with('IssuePolicy')
|