debian-mirror-gitlab/app/policies/personal_snippet_policy.rb

34 lines
846 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
class PersonalSnippetPolicy < BasePolicy
2017-09-10 17:25:29 +05:30
condition(:public_snippet, scope: :subject) { @subject.public? }
condition(:is_author) { @user && @subject.author == @user }
condition(:internal_snippet, scope: :subject) { @subject.internal? }
2016-09-29 09:46:39 +05:30
2017-09-10 17:25:29 +05:30
rule { public_snippet }.policy do
2020-03-09 13:42:32 +05:30
enable :read_snippet
2020-04-08 14:13:33 +05:30
enable :read_note
2019-07-31 22:56:46 +05:30
enable :create_note
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
2019-12-26 22:10:19 +05:30
rule { is_author | admin }.policy do
2020-03-09 13:42:32 +05:30
enable :read_snippet
enable :update_snippet
enable :admin_snippet
2020-04-08 14:13:33 +05:30
enable :read_note
2019-07-31 22:56:46 +05:30
enable :create_note
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
rule { internal_snippet & ~external_user }.policy do
2020-03-09 13:42:32 +05:30
enable :read_snippet
2020-04-08 14:13:33 +05:30
enable :read_note
2019-07-31 22:56:46 +05:30
enable :create_note
2016-09-29 09:46:39 +05:30
end
2017-09-10 17:25:29 +05:30
2019-07-31 22:56:46 +05:30
rule { anonymous }.prevent :create_note
2018-05-09 12:01:36 +05:30
2019-07-31 22:56:46 +05:30
rule { can?(:create_note) }.enable :award_emoji
2019-03-02 22:35:43 +05:30
2020-03-09 13:42:32 +05:30
rule { can?(:read_all_resources) }.enable :read_snippet
2016-09-29 09:46:39 +05:30
end