BigW Consortium Gitlab

personal_snippet_policy.rb 878 Bytes
Newer Older
1
class PersonalSnippetPolicy < BasePolicy
2 3 4
  condition(:public_snippet, scope: :subject) { @subject.public? }
  condition(:is_author) { @user && @subject.author == @user }
  condition(:internal_snippet, scope: :subject) { @subject.internal? }
5

6 7 8 9
  rule { public_snippet }.policy do
    enable :read_personal_snippet
    enable :comment_personal_snippet
  end
10

11 12 13 14 15 16 17
  rule { is_author }.policy do
    enable :read_personal_snippet
    enable :update_personal_snippet
    enable :destroy_personal_snippet
    enable :admin_personal_snippet
    enable :comment_personal_snippet
  end
18

19 20
  rule { ~anonymous }.enable :create_personal_snippet
  rule { external_user }.prevent :create_personal_snippet
21

22 23 24
  rule { internal_snippet & ~external_user }.policy do
    enable :read_personal_snippet
    enable :comment_personal_snippet
25
  end
26 27

  rule { anonymous }.prevent :comment_personal_snippet
28
end