2016-08-16 16:08:14 -04:00
|
|
|
class NotePolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
delegate { @subject.project }
|
2017-09-01 08:03:57 -04:00
|
|
|
delegate { @subject.noteable if @subject.noteable.lockable? }
|
2016-08-16 16:08:14 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
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 }
|
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
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { ~editable | anonymous }.prevent :edit_note
|
2017-08-30 10:57:50 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
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
|
2016-08-16 16:08:14 -04:00
|
|
|
end
|
|
|
|
end
|