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

108 lines
3.2 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
2023-03-04 22:38:38 +05:30
@user && (@user.admin? || can?(:reporter_access) || assignee_or_author?) # rubocop:disable Cop/UserAdmin
2016-09-29 09:46:39 +05:30
end
2022-07-16 23:28:13 +05:30
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-07-23 23:45:48 +05:30
(@user&.can?(:read_crm_contact, @subject.project.root_ancestor) || @user&.support_bot?)
2022-07-16 23:28:13 +05:30
end
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? }
2023-03-04 22:38:38 +05:30
# accessing notes requires the notes widget to be available for work items(or issue)
condition(:notes_widget_enabled, scope: :subject) do
@subject.work_item_type.widgets.include?(::WorkItems::Widgets::Notes)
end
rule { ~notes_widget_enabled }.policy do
prevent :create_note
prevent :read_note
prevent :read_internal_note
prevent :set_note_created_at
prevent :mark_note_as_confidential
# these actions on notes are not available on issues/work items yet,
# but preventing any action on work item notes as long as there is no notes widget seems reasonable
prevent :resolve_note
prevent :reposition_note
end
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
2022-08-13 15:12:31 +05:30
rule { can?(:admin_issue) }.policy do
2021-09-04 01:27:46 +05:30
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
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
2022-07-16 23:28:13 +05:30
rule { can_read_crm_contacts }.policy do
enable :read_crm_contacts
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
2022-11-25 23:54:43 +05:30
rule { can?(:reporter_access) }.policy do
enable :mark_note_as_confidential
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')