Module: ActionSentinel::Permissible
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/action_sentinel/permissible.rb
Overview
Provides methods for managing access permissions associated with a model.
This module is designed to be included in models that need to manage access permissions. It introduces methods for adding, removing, and checking permissions associated with a specific controller and actions.
Instance Method Summary collapse
-
#add_permissions_to(*actions, controller_path) ⇒ Boolean
Add permissions to the access_permissions association for a specific controller.
-
#has_permission_to?(action, controller_path) ⇒ Boolean
Check if the model has permission to perform a specific action in a controller.
-
#remove_permissions_to(*actions, controller_path) ⇒ Boolean?
Remove permissions from the access_permissions association for a specific controller.
Instance Method Details
#add_permissions_to(*actions, controller_path) ⇒ Boolean
Add permissions to the access_permissions association for a specific controller.
33 34 35 36 37 |
# File 'lib/action_sentinel/permissible.rb', line 33 def (*actions, controller_path) = .find_or_initialize_by(controller_path: controller_path) .assign_attributes(actions: (.actions + sanitize_actions_array(actions)).uniq) .save end |
#has_permission_to?(action, controller_path) ⇒ Boolean
Check if the model has permission to perform a specific action in a controller.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/action_sentinel/permissible.rb', line 57 def (action, controller_path) query = .where(controller_path: controller_path) query = if %w[sqlite sqlite3].include? self.class.connection.adapter_name.downcase query.where("actions LIKE ?", "%#{action}%") else query.where(':action = ANY("access_permissions"."actions")', action: action) end query.exists? end |
#remove_permissions_to(*actions, controller_path) ⇒ Boolean?
Remove permissions from the access_permissions association for a specific controller.
45 46 47 48 |
# File 'lib/action_sentinel/permissible.rb', line 45 def (*actions, controller_path) = .find_by(controller_path: controller_path) &.update(actions: (.actions - sanitize_actions_array(actions))) end |