Class: LesliShield::RolesController
- Inherits:
-
ApplicationController
- Object
- Lesli::ApplicationLesliController
- ApplicationController
- LesliShield::RolesController
- Defined in:
- app/controllers/lesli_shield/roles_controller.rb
Instance Method Summary collapse
-
#create ⇒ Json
Json that contains wheter the creation of the role was successful or not.
-
#destroy ⇒ Json
Json that contains wheter the role was successfully deleted or not.
-
#edit ⇒ HTML
HTML view for editing the role.
- #index ⇒ Object
-
#new ⇒ HTML
HTML view for creating a new role.
- #options ⇒ JSON
- #show ⇒ Object
-
#update ⇒ Json
Json that contains wheter the role was successfully updated or not.
Instance Method Details
#create ⇒ Json
Returns Json that contains wheter the creation of the role was successful or not. If it is not successful, it returns an error message.
74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 74 def create role = RoleService.new(current_user).create(role_params) if role.successful? respond_with_successful(role.result) else respond_with_error(role.errors_as_sentence) end end |
#destroy ⇒ Json
Returns Json that contains wheter the role was successfully deleted or not. If it it not successful, it returns an error message.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 116 def destroy return respond_with_not_found unless @role.found? # Validation: check if the role has still associated users if @role.has_users? return respond_with_error(I18n.t("core.roles.messages_danger_users_assigned_validation")) end @role.destroy # Check if the deletion went ok unless @role.successful? return respond_with_error(@role.errors) end respond_with_successful end |
#edit ⇒ HTML
Returns HTML view for editing the role.
60 61 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 60 def edit end |
#index ⇒ Object
37 38 39 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 37 def index @roles = respond_as_pagination(Lesli::RoleService.new(current_user, query).index) end |
#new ⇒ HTML
Returns HTML view for creating a new role.
51 52 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 51 def new end |
#options ⇒ JSON
136 137 138 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 136 def respond_with_successful(RoleService.new(current_user).) end |
#show ⇒ Object
41 42 43 44 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 41 def show @role = @role.show @role_actions = Lesli::Role::ActionService.new(current_user, query).index(@role.id) end |
#update ⇒ Json
Returns Json that contains wheter the role was successfully updated or not. If it it not successful, it returns an error message.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/lesli_shield/roles_controller.rb', line 89 def update # Respond with 404 if role was not found return respond_with_not_found unless @role.found? # check if current user can work with role # unless current_user.can_work_with_role?(@role.resource) # return respond_with_error(I18n.t("core.roles.messages_danger_updating_role_object_level_permission_too_high")) # end # Update role information @role.update(role_params) # check if the update went OK if @role.successful? success("Role updated successfully!") respond_to do |format| format.turbo_stream format.html { redirect_to @role } end else respond_with_error(@role.errors) end end |