Class: Guts::PermissionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Guts::PermissionsController
- Includes:
- ControllerPermissionConcern
- Defined in:
- app/controllers/guts/permissions_controller.rb
Overview
Permissions controller
Instance Method Summary collapse
-
#additional ⇒ Object
Fine-tuned permissions on an object level.
-
#additional_create ⇒ Object
Creates a permission for an object at a fine level.
-
#create ⇒ Object
Creates a permission for an object.
-
#destroy ⇒ Object
Revokes a permission.
-
#index ⇒ Object
Displays the permissions.
-
#new ⇒ Object
Assigning a permission to an object.
Methods inherited from ApplicationController
Methods included from MultisiteConcern
#current_site, #with_current_site
Instance Method Details
#additional ⇒ Object
Fine-tuned permissions on an object level
53 54 55 56 |
# File 'app/controllers/guts/permissions_controller.rb', line 53 def additional @permission = Permission.new @objects = "#{@authorization.subject_class}".constantize.all end |
#additional_create ⇒ Object
Note:
Redirects to #index if successfull or re-renders #additional if not
Creates a permission for an object at a fine level
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/guts/permissions_controller.rb', line 60 def additional_create # Check if authorization exists and create if it does not = Authorization.find_or_create_by( subject_class: @authorization.subject_class, action: @authorization.action, subject_id: params[:subject_id] ) do |auth| auth.description = @authorization.action end # Save the permission @permission = Permission.new .merge(authorization_id: .id) if @permission.save # Success, all done flash[:notice] = 'Permission was successfully granted.' redirect_to polymorphic_path([@object, :permissions]) else # Error redirect_to polymorphic_path([:additional, @object, :permissions]) end end |
#create ⇒ Object
Note:
Redirects to #index if successfull or re-renders #new if not
Creates a permission for an object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/guts/permissions_controller.rb', line 25 def create ActiveRecord::Base.transaction do # Takes the custom authorization field from the form and loops # and merges it into ther permission_params params[:authorization_ids].each do |id| = Permission.new .merge(authorization_id: id) .save! end end # Success, all done flash[:notice] = 'Permission was successfully granted.' redirect_to polymorphic_path([@object, :permissions]) rescue ActiveRecord::RecordInvalid => _ # Something did not validate redirect_to new_polymorphic_path([@object, :permission]) end |
#destroy ⇒ Object
Revokes a permission
44 45 46 47 48 49 50 |
# File 'app/controllers/guts/permissions_controller.rb', line 44 def destroy @permission = @object..find { |p| p.id == params[:id].to_i } @permission.destroy if @permission flash[:notice] = @permission ? 'Permission was revoked.' : 'Error revoking permission.' redirect_to polymorphic_path([@object, :permissions]) end |
#index ⇒ Object
Displays the permissions
13 14 |
# File 'app/controllers/guts/permissions_controller.rb', line 13 def index end |
#new ⇒ Object
Assigning a permission to an object
17 18 19 20 21 |
# File 'app/controllers/guts/permissions_controller.rb', line 17 def new @permission = Permission.new @authorizations = Authorization.where(subject_id: nil) @grouped_auths = @authorizations.group_by(&:subject_class) end |