Class: UserPolicy

Inherits:
ApplicationPolicy show all
Defined in:
app/policies/user_policy.rb

Defined Under Namespace

Classes: Scope

Constant Summary

Constants inherited from ApplicationPolicy

ApplicationPolicy::STANDARD_EDIT_PERMISSIONS, ApplicationPolicy::STANDARD_VIEW_PERMISSIONS

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#record, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#destroy_all?, #edit?, #initialize, #new?

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#create? ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/policies/user_policy.rb', line 20

def create?
  all_of(
    SiteSettings.multiuser_enabled?,
    one_of(
      SiteSettings.registration_enabled?,
      user&.is_moderator?
    ),
    none_of(
      SiteSettings.demo_mode_enabled?
    )
  )
end

#destroy? ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/policies/user_policy.rb', line 40

def destroy?
  all_of(
    one_of(
      user == record,
      user&.is_administrator?
    ),
    SiteSettings.multiuser_enabled?,
    none_of(
      SiteSettings.demo_mode_enabled?
    )
  )
end

#index? ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
# File 'app/policies/user_policy.rb', line 2

def index?
  all_of(
    user&.is_moderator?,
    none_of(
      SiteSettings.demo_mode_enabled?
    )
  )
end

#show? ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'app/policies/user_policy.rb', line 11

def show?
  all_of(
    one_of(
      user == record,
      user&.is_moderator?
    )
  )
end

#update? ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'app/policies/user_policy.rb', line 33

def update?
  one_of(
    user == record,
    user&.is_moderator?
  )
end