Class: Role::DescriptorsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Role::DescriptorsController
- Defined in:
- app/controllers/lesli_guard/role/descriptors_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /role/descriptors.
-
#destroy ⇒ Object
DELETE /role/descriptors/1.
- #index ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
POST /role/descriptors
43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/lesli_guard/role/descriptors_controller.rb', line 43 def create system_descriptor = Lesli::Descriptor.find_by(:id => role_descriptor_params[:id]) role_power = @role.powers.with_deleted.find_or_create_by(:descriptor => system_descriptor) role_power.recover if role_power.deleted? respond_with_successful(role_power) end |
#destroy ⇒ Object
DELETE /role/descriptors/1
69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/lesli_guard/role/descriptors_controller.rb', line 69 def destroy return respond_with_not_found unless @role_descriptor if @role_descriptor.destroy #Role::Activity.log_destroy_descriptor(current_user, @role, @role_descriptor) respond_with_successful else respond_with_error(@role_descriptor.errors..to_sentence) end end |
#index ⇒ Object
38 39 40 |
# File 'app/controllers/lesli_guard/role/descriptors_controller.rb', line 38 def index respond_with_successful(RoleDescriptorService.new(current_user).index(@role)) end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/lesli_guard/role/descriptors_controller.rb', line 53 def update # Get the descriptor we want to take the privileges to be activated and added # into the role, this can be done through the role power table system_descriptor = Lesli::Descriptor.find_by(:id => role_descriptor_params[:id]) # Check if the descriptor is already added to the role, if not, we create the new record # assigning the descriptor to the role as power role_power = @role.powers.with_deleted.find_or_create_by(:descriptor => system_descriptor) # Now we update the privileges that the role wants to inherit from the privileges # available in the descriptor respond_with_successful(role_power.update(role_descriptor_params)) end |