Module: Glib::Auth::Policy
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/glib/auth/policy.rb
Defined Under Namespace
Modules: ClassMethods, Overrides
Classes: UnauthorizedError
Instance Method Summary
collapse
Instance Method Details
#assert_current_user_present ⇒ Object
20
21
22
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 20
def assert_current_user_present
raise UnauthorizedError unless current_user
end
|
#can?(action, record, context = nil) ⇒ Boolean
70
71
72
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 70
def can?(action, record, context = nil)
policy(record, nil, context).send("#{action}?")
end
|
#cannot?(action, record, context = nil) ⇒ Boolean
75
76
77
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 75
def cannot?(action, record, context = nil)
!policy(record, nil, context).send("#{action}?")
end
|
#glib_authorize_resource(*args) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 81
def glib_authorize_resource(*args)
options = args.
resource_name = args.first
resource_name ||= controller_name.split('/').last.singularize
if (resource_key = options[:class]).nil?
policy_name = resource_name.camelize.constantize
else
policy_name = case resource_key
when false
resource_name.to_sym
when Symbol, Class
resource_key
else
raise "Invalid resource class: #{resource_key}"
end
end
resource_instance = instance_variable_get("@#{resource_name}") || policy_name
query = "#{action_name}?"
policy_instance = policy(resource_instance, policy_name, options.fetch(:context, nil))
raise_access_denied(resource_instance, policy_instance) unless policy_instance.public_send(query)
end
|
#glib_raise_forbidden ⇒ Object
60
61
62
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 60
def glib_raise_forbidden
raise UnauthorizedError
end
|
#resource_name_from_controller ⇒ Object
161
162
163
|
# File 'app/controllers/concerns/glib/auth/policy.rb', line 161
def resource_name_from_controller
params[:controller].split('/').last.singularize
end
|