Class: Integral::BasePolicy

Inherits:
Object
  • Object
show all
Defined in:
app/policies/integral/base_policy.rb

Overview

Sets base policy for all objects to inherit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, instance) ⇒ BasePolicy

Initializes a policy instance which is used to handle authorization

Parameters:

  • user (User)

    user policy is authorizing against

  • instance (Object)

    instance policy is authorizing against



10
11
12
13
# File 'app/policies/integral/base_policy.rb', line 10

def initialize(user, instance)
  @user = user
  @instance = instance
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'app/policies/integral/base_policy.rb', line 4

def instance
  @instance
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'app/policies/integral/base_policy.rb', line 4

def user
  @user
end

Instance Method Details

#manager?Boolean

Returns whether or not user has manager role.

Returns:

  • (Boolean)

    whether or not user has manager role



16
17
18
# File 'app/policies/integral/base_policy.rb', line 16

def manager?
  user.role?(role_name) || user.admin?
end

#permitted_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/policies/integral/base_policy.rb', line 20

def permitted_attribute?(attribute)
  permitted_attributes.include?(attribute)
end

#permitted_attributesArray

Returns attributes the user is authorized to edit.

Returns:

  • (Array)

    attributes the user is authorized to edit

Raises:

  • (NotImplementedError)


29
30
31
# File 'app/policies/integral/base_policy.rb', line 29

def permitted_attributes
  raise NotImplementedError
end

#unpermitted_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/policies/integral/base_policy.rb', line 24

def unpermitted_attribute?(attribute)
  !permitted_attribute?(attribute)
end