2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 16:08:14 -04:00
|
|
|
class NotePolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
delegate { @subject.project }
|
2018-04-06 14:19:37 -04:00
|
|
|
delegate { @subject.noteable if DeclarativePolicy.has_policy?(@subject.noteable) }
|
2016-08-16 16:08:14 -04:00
|
|
|
|
2017-04-06 17:06:42 -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
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:editable, scope: :subject) { @subject.editable? }
|
2016-08-16 16:08:14 -04:00
|
|
|
|
2018-04-02 13:05:47 -04:00
|
|
|
rule { ~editable }.prevent :admin_note
|
2017-04-06 17:06:42 -04:00
|
|
|
|
|
|
|
rule { is_author }.policy do
|
|
|
|
enable :read_note
|
|
|
|
enable :admin_note
|
|
|
|
enable :resolve_note
|
|
|
|
end
|
|
|
|
|
2018-04-02 14:38:47 -04:00
|
|
|
rule { is_noteable_author }.policy do
|
2017-04-06 17:06:42 -04:00
|
|
|
enable :resolve_note
|
2016-08-16 16:08:14 -04:00
|
|
|
end
|
|
|
|
end
|