Class: Avo::ResourceComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Avo::ResourceComponent
show all
- Defined in:
- app/components/avo/resource_component.rb
Instance Method Summary
collapse
Instance Method Details
#authorize_association_for(policy_method) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/components/avo/resource_component.rb', line 10
def authorize_association_for(policy_method)
association_policy = true
if @reflection.present?
reflection_resource = ::Avo::App.get_resource_by_model_name(@reflection.active_record.name)
if reflection_resource.present?
method_name = "#{policy_method}_#{@reflection.name.to_s.underscore}?".to_sym
defined_policy_methods = reflection_resource.authorization.defined_methods(reflection_resource.model_class, raise_exception: false)
if defined_policy_methods.present? && defined_policy_methods.include?(method_name)
association_policy = reflection_resource.authorization.authorize_action(method_name, raise_exception: false)
end
end
end
association_policy
end
|
#can_create? ⇒ Boolean
2
3
4
|
# File 'app/components/avo/resource_component.rb', line 2
def can_create?
@resource.authorization.authorize_action(:create, raise_exception: false)
end
|
#can_delete? ⇒ Boolean
6
7
8
|
# File 'app/components/avo/resource_component.rb', line 6
def can_delete?
@resource.authorization.authorize_action(:destroy, raise_exception: false)
end
|