summaryrefslogtreecommitdiff
path: root/app/policies/issuable_policy.rb
blob: f0aa16d2ecf4297c07a9270d5b9926c9ce48a7a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class IssuablePolicy < BasePolicy
  delegate { @subject.project }

  condition(:locked, scope: :subject, score: 0) { @subject.discussion_locked? }

  condition(:is_project_member) { @user && @subject.project && @subject.project.team.member?(@user) }

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

  rule { assignee_or_author }.policy do
    enable :read_issue
    enable :update_issue
    enable :read_merge_request
    enable :update_merge_request
  end

  rule { locked & ~is_project_member }.policy do
    prevent :create_note
    prevent :update_note
    prevent :admin_note
    prevent :resolve_note
    prevent :edit_note
  end
end