gitlab-org--gitlab-foss/app/policies/note_policy.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-16 16:08:14 -04:00
class NotePolicy < BasePolicy
delegate { @subject.project }
delegate { @subject.noteable if DeclarativePolicy.has_policy?(@subject.noteable) }
2016-08-16 16:08:14 -04:00
condition(:is_author) { @user && @subject.author == @user }
condition(:is_noteable_author) { @user && @subject.noteable.author_id == @user.id }
2016-08-16 16:08:14 -04:00
condition(:editable, scope: :subject) { @subject.editable? }
2016-08-16 16:08:14 -04:00
condition(:can_read_noteable) { can?(:"read_#{@subject.noteable_ability_name}") }
condition(:is_visible) { @subject.visible_for?(@user) }
rule { ~editable }.prevent :admin_note
# If user can't read the issue/MR/etc then they should not be allowed to do anything to their own notes
rule { ~can_read_noteable }.policy do
prevent :read_note
prevent :admin_note
prevent :resolve_note
prevent :award_emoji
end
rule { is_author }.policy do
enable :read_note
enable :admin_note
enable :resolve_note
end
rule { ~is_visible }.policy do
prevent :read_note
prevent :admin_note
prevent :resolve_note
prevent :award_emoji
end
rule { is_noteable_author }.policy do
enable :resolve_note
2016-08-16 16:08:14 -04:00
end
end