Class: G5Authenticatable::BasePolicy
- Inherits:
-
Object
- Object
- G5Authenticatable::BasePolicy
show all
- Defined in:
- app/policies/g5_authenticatable/base_policy.rb
Overview
Base class for all pundit authorization policies Defaults to limiting every action to super admin users
Defined Under Namespace
Classes: BaseScope
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(user, record = nil) ⇒ BasePolicy
Returns a new instance of BasePolicy.
9
10
11
12
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 9
def initialize(user, record = nil)
@user = user
@record = record
end
|
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
7
8
9
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 7
def record
@record
end
|
#user ⇒ Object
Returns the value of attribute user.
7
8
9
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 7
def user
@user
end
|
Instance Method Details
#admin? ⇒ Boolean
74
75
76
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 74
def admin?
user.present? && user.has_role?(:admin)
end
|
#create? ⇒ Boolean
22
23
24
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 22
def create?
super_admin?
end
|
#destroy? ⇒ Boolean
38
39
40
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 38
def destroy?
super_admin?
end
|
#edit? ⇒ Boolean
34
35
36
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 34
def edit?
update?
end
|
#editor? ⇒ Boolean
78
79
80
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 78
def editor?
user.present? && user.has_role?(:editor)
end
|
#global_role? ⇒ Boolean
94
95
96
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 94
def global_role?
super_admin? || admin? || editor? || viewer?
end
|
#has_global_role? ⇒ Boolean
86
87
88
89
90
91
92
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 86
def has_global_role?
ActiveSupport::Deprecation.warn "[G5Authenticatable] the `has_global_role?` method is deprecated and\nwill be removed. Use `global_role?` instead.\n".strip_heredoc
global_role?
end
|
#index? ⇒ Boolean
14
15
16
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 14
def index?
super_admin?
end
|
#new? ⇒ Boolean
26
27
28
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 26
def new?
create?
end
|
#scope ⇒ Object
42
43
44
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 42
def scope
Pundit.policy_scope!(user, record.class)
end
|
#show? ⇒ Boolean
18
19
20
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 18
def show?
scope.where(id: record.id).exists?
end
|
#super_admin? ⇒ Boolean
70
71
72
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 70
def super_admin?
user.present? && user.has_role?(:super_admin)
end
|
#update? ⇒ Boolean
30
31
32
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 30
def update?
super_admin?
end
|
#viewer? ⇒ Boolean
82
83
84
|
# File 'app/policies/g5_authenticatable/base_policy.rb', line 82
def viewer?
user.present? && user.has_role?(:viewer)
end
|