Module: Motor::LoadAndAuthorizeDynamicResource
- Extended by:
- ActiveSupport::Concern
- Included in:
- DataController
- Defined in:
- app/controllers/concerns/motor/load_and_authorize_dynamic_resource.rb
Constant Summary collapse
- MUTEX =
Mutex.new
- INSTANCE_VARIABLE_NAME =
'resource'
- ASSOCIATION_INSTANCE_VARIABLE_NAME =
'associated_resource'
Instance Method Summary collapse
- #load_and_authorize_association ⇒ Object
- #load_and_authorize_resource ⇒ Object
- #resource_class ⇒ Object
- #resource_name_prefix ⇒ Object
Instance Method Details
#load_and_authorize_association ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/concerns/motor/load_and_authorize_dynamic_resource.rb', line 52 def return if params[:association].blank? association = resource_class.reflections[params[:association]] if association CanCan::ControllerResource.new( self, class: association.klass, parent: false, through: :resource, through_association: params[:association].to_sym, instance_name: params[:action] == 'create' ? ASSOCIATION_INSTANCE_VARIABLE_NAME : INSTANCE_VARIABLE_NAME ). else render json: { message: 'Unknown association' }, status: :not_found end rescue ActiveRecord::RecordNotFound head :not_found end |
#load_and_authorize_resource ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/concerns/motor/load_and_authorize_dynamic_resource.rb', line 30 def = { class: resource_class, parent: params[:association].present?, instance_name: INSTANCE_VARIABLE_NAME } if params[:resource_id].present? = .merge( parent: true, id_param: :resource_id ) end CanCan::ControllerResource.new( self, ). rescue ActiveRecord::RecordNotFound head :not_found end |
#resource_class ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/controllers/concerns/motor/load_and_authorize_dynamic_resource.rb', line 17 def resource_class @resource_class ||= MUTEX.synchronize do Motor::Resources::FetchConfiguredModel.call( Motor::BuildSchema::Utils.classify_slug(resource_name_prefix + params[:resource]), cache_key: Motor::Resource.maximum(:updated_at) ) end end |
#resource_name_prefix ⇒ Object
26 27 28 |
# File 'app/controllers/concerns/motor/load_and_authorize_dynamic_resource.rb', line 26 def resource_name_prefix '' end |