summaryrefslogtreecommitdiff
path: root/app/policies/user_policy.rb
blob: 0181ddf85e0065c7e5f83de29d48d2c20b7fb343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class UserPolicy < BasePolicy
  include Gitlab::CurrentSettings

  desc "The application is restricted from public visibility"
  condition(:restricted_public_level, scope: :global) do
    current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC)
  end

  desc "The current user is the user in question"
  condition(:user_is_self, score: 0) { @subject == @user }

  desc "This is the ghost user"
  condition(:subject_ghost, scope: :subject, score: 0) { @subject.ghost? }

  rule { ~restricted_public_level }.enable :read_user
  rule { ~anonymous }.enable :read_user

  rule { user_is_self | admin }.enable :destroy_user
  rule { subject_ghost }.prevent :destroy_user
end