Class: ApplicationPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/kowl/templates/app/policies/application_policy.rb

Direct Known Subclasses

LoginActivityPolicy, UserPolicy

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, record) ⇒ ApplicationPolicy

Returns a new instance of ApplicationPolicy.

Raises:

  • (Pundit::NotAuthorizedError)


6
7
8
9
10
11
# File 'lib/kowl/templates/app/policies/application_policy.rb', line 6

def initialize(current_user, record)
  raise Pundit::NotAuthorizedError, 'must be logged in' unless current_user

  @current_user = current_user
  @record = record
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



4
5
6
# File 'lib/kowl/templates/app/policies/application_policy.rb', line 4

def current_user
  @current_user
end

#recordObject (readonly)

Returns the value of attribute record.



4
5
6
# File 'lib/kowl/templates/app/policies/application_policy.rb', line 4

def record
  @record
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/kowl/templates/app/policies/application_policy.rb', line 13

def admin?
  current_user.admin? if current_user.present?
end

#staff?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/kowl/templates/app/policies/application_policy.rb', line 17

def staff?
  current_user.staff? if current_user.present?
end

#staff_member?Boolean

Used to verify if the persons role is set to either superuser or staff

Returns:

  • (Boolean)


22
23
24
# File 'lib/kowl/templates/app/policies/application_policy.rb', line 22

def staff_member?
  admin? || staff?
end