BigW Consortium Gitlab

note_policy.rb 799 Bytes
Newer Older
1
class NotePolicy < BasePolicy
2
  delegate { @subject.project }
3
  delegate { @subject.noteable if @subject.noteable.lockable? }
4

5 6 7
  condition(:is_author) { @user && @subject.author == @user }
  condition(:for_merge_request, scope: :subject) { @subject.for_merge_request? }
  condition(:is_noteable_author) { @user && @subject.noteable.author_id == @user.id }
8

9
  condition(:editable, scope: :subject) { @subject.editable? }
10

11
  rule { ~editable | anonymous }.prevent :edit_note
12

13 14 15 16 17 18 19 20 21 22 23 24
  rule { is_author | admin }.enable :edit_note
  rule { can?(:master_access) }.enable :edit_note

  rule { is_author }.policy do
    enable :read_note
    enable :update_note
    enable :admin_note
    enable :resolve_note
  end

  rule { for_merge_request & is_noteable_author }.policy do
    enable :resolve_note
25 26
  end
end