issuable_policy.rb 731 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class IssuablePolicy < BasePolicy
4
  delegate { @subject.project }
5

6
  condition(:locked, scope: :subject, score: 0) { @subject.discussion_locked? }
7 8
  condition(:is_project_member) { @user && @subject.project && @subject.project.team.member?(@user) }

9 10 11 12
  desc "User is the assignee or author"
  condition(:assignee_or_author) do
    @user && @subject.assignee_or_author?(@user)
  end
13

14 15 16
  rule { assignee_or_author }.policy do
    enable :read_issue
    enable :update_issue
17
    enable :reopen_issue
18 19
    enable :read_merge_request
    enable :update_merge_request
20
  end
21

22 23 24 25 26
  rule { locked & ~is_project_member }.policy do
    prevent :create_note
    prevent :admin_note
    prevent :resolve_note
  end
27
end