debian-mirror-gitlab/app/policies/issue_policy.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
class IssuePolicy < IssuablePolicy
2016-11-24 13:41:30 +05:30
# 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-22 19:07:51 +05:30
include CrudPolicyHelpers
2019-09-04 21:01:54 +05:30
2017-09-10 17:25:29 +05:30
desc "User can read confidential issues"
condition(:can_read_confidential) do
@user && IssueCollection.new([@subject]).visible_to(@user).any?
2016-09-29 09:46:39 +05:30
end
2021-12-11 22:18:48 +05:30
desc "User can read contacts belonging to the issue group"
2022-05-07 20:08:51 +05:30
condition(:can_read_crm_contacts, scope: :subject) { @user.can?(:read_crm_contact, @subject.project.root_ancestor) }
2021-12-11 22:18:48 +05:30
2017-09-10 17:25:29 +05:30
desc "Issue is confidential"
condition(:confidential, scope: :subject) { @subject.confidential? }
2016-09-29 09:46:39 +05:30
2021-10-27 15:23:28 +05:30
desc "Issue is hidden"
condition(:hidden, scope: :subject) { @subject.hidden? }
2021-09-04 01:27:46 +05:30
desc "Issue is persisted"
condition(:persisted, scope: :subject) { @subject.persisted? }
2017-09-10 17:25:29 +05:30
rule { confidential & ~can_read_confidential }.policy do
2019-09-04 21:01:54 +05:30
prevent(*create_read_update_admin_destroy(:issue))
2018-03-27 19:54:05 +05:30
prevent :read_issue_iid
2016-09-29 09:46:39 +05:30
end
2018-11-20 20:47:30 +05:30
2021-10-27 15:23:28 +05:30
rule { hidden & ~admin }.policy do
prevent :read_issue
end
2019-09-04 21:01:54 +05:30
rule { ~can?(:read_issue) }.prevent :create_note
2018-11-20 20:47:30 +05:30
rule { locked }.policy do
prevent :reopen_issue
end
2019-12-04 20:38:33 +05:30
2020-05-24 23:13:21 +05:30
rule { ~can?(:read_issue) }.policy do
prevent :read_design
prevent :create_design
prevent :destroy_design
end
2020-10-24 23:57:45 +05:30
rule { ~can?(:read_design) }.policy do
prevent :move_design
end
2021-01-29 00:20:46 +05:30
rule { ~anonymous & can?(:read_issue) }.policy do
enable :create_todo
2021-09-04 01:27:46 +05:30
enable :update_subscription
end
# admin can set metadata on new issues
rule { ~persisted & admin }.policy do
enable :set_issue_metadata
end
# support bot needs to be able to set metadata on new issues when service desk is enabled
rule { ~persisted & support_bot & can?(:guest_access) }.policy do
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
enable :set_issue_metadata
end
rule { persisted & can?(:admin_issue) }.policy do
enable :set_issue_metadata
2021-01-29 00:20:46 +05:30
end
2021-11-11 11:23:49 +05:30
rule { can?(:set_issue_metadata) }.policy do
enable :set_confidentiality
end
rule { ~persisted & can?(:create_issue) }.policy do
enable :set_confidentiality
end
2021-12-11 22:18:48 +05:30
rule { can?(:set_issue_metadata) & can_read_crm_contacts }.policy do
enable :set_issue_crm_contacts
end
2020-05-24 23:13:21 +05:30
end
2020-10-24 23:57:45 +05:30
2021-06-08 01:23:25 +05:30
IssuePolicy.prepend_mod_with('IssuePolicy')