2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 19:46:35 -04:00
|
|
|
class PersonalSnippetPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:public_snippet, scope: :subject) { @subject.public? }
|
|
|
|
condition(:is_author) { @user && @subject.author == @user }
|
|
|
|
condition(:internal_snippet, scope: :subject) { @subject.internal? }
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { public_snippet }.policy do
|
2020-01-23 07:08:38 -05:00
|
|
|
enable :read_snippet
|
2020-02-23 22:09:05 -05:00
|
|
|
enable :read_note
|
2019-05-02 06:13:42 -04:00
|
|
|
enable :create_note
|
2017-04-06 17:06:42 -04:00
|
|
|
end
|
2017-05-01 09:14:35 -04:00
|
|
|
|
2019-11-07 01:06:12 -05:00
|
|
|
rule { is_author | admin }.policy do
|
2020-01-23 07:08:38 -05:00
|
|
|
enable :read_snippet
|
|
|
|
enable :update_snippet
|
|
|
|
enable :admin_snippet
|
2020-02-23 22:09:05 -05:00
|
|
|
enable :read_note
|
2019-05-02 06:13:42 -04:00
|
|
|
enable :create_note
|
2017-04-06 17:06:42 -04:00
|
|
|
end
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { internal_snippet & ~external_user }.policy do
|
2020-01-23 07:08:38 -05:00
|
|
|
enable :read_snippet
|
2020-02-23 22:09:05 -05:00
|
|
|
enable :read_note
|
2019-05-02 06:13:42 -04:00
|
|
|
enable :create_note
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
2019-05-02 06:13:42 -04:00
|
|
|
rule { anonymous }.prevent :create_note
|
2018-04-06 14:19:37 -04:00
|
|
|
|
2019-05-02 06:13:42 -04:00
|
|
|
rule { can?(:create_note) }.enable :award_emoji
|
2019-01-24 07:44:46 -05:00
|
|
|
|
2020-01-23 07:08:38 -05:00
|
|
|
rule { can?(:read_all_resources) }.enable :read_snippet
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|