Class: Renalware::BasePolicy

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

Overview

Responsible for determining if a user can manage the provided record. It provides the Base policy for Renalware.

It collaborates with a permission configuration object to determine if the record is is an instance of a model that is #restricted? and if the user #has_permission? to manage the record.

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#record, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#edit?, #new?, #scope

Constructor Details

#initialize(user, record, permission_configuration = nil) ⇒ BasePolicy

Returns a new instance of BasePolicy.



12
13
14
15
# File 'app/policies/renalware/base_policy.rb', line 12

def initialize(user, record, permission_configuration = nil)
  super(user, record)
  @permission_configuration = permission_configuration || default_permission_configuration
end

Instance Method Details

#contact_added?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/policies/renalware/base_policy.rb', line 47

def contact_added?
  update?
end

#create?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'app/policies/renalware/base_policy.rb', line 28

def create?
  return true if user_is_devops? || user_is_super_admin?
  return permission_for_restricted? if restricted?

  has_write_privileges?
end

#debug?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/policies/renalware/base_policy.rb', line 51

def debug?
  user_is_super_admin?
end

#destroy?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/policies/renalware/base_policy.rb', line 39

def destroy?
  create?
end

#index?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'app/policies/renalware/base_policy.rb', line 17

def index?
  return true if user_is_devops? || user_is_super_admin?
  return permission_for_restricted? if restricted?

  has_any_role?
end

#show?Boolean

Returns:

  • (Boolean)


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

def show?
  has_any_role?
end

#sort?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/policies/renalware/base_policy.rb', line 43

def sort?
  update?
end

#update?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/policies/renalware/base_policy.rb', line 35

def update?
  create?
end