Class: LesliVault::RolesController
- Inherits:
-
ApplicationController
- Object
- Lesli::ApplicationLesliController
- ApplicationController
- LesliVault::RolesController
- Defined in:
- app/controllers/lesli_vault/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 ⇒ HTML|JSON
HTML view for listing all roles or a Json that contains a list of all roles associated to this account.
-
#new ⇒ HTML
HTML view for creating a new role.
- #options ⇒ JSON
-
#show ⇒ HTML|Json
HTML view showing the requested role or a Json that contains the information of the role.
-
#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.
106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 106 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.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 144 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.
92 93 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 92 def edit end |
#index ⇒ HTML|JSON
Returns HTML view for listing all roles or a Json that contains a list of all roles associated to this account.
47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 47 def index respond_to do |format| format.html { } format.json { respond_with_successful(RoleService.new(current_user, query).index) #respond_with_pagination(RoleService.new(current_user, query).index) } end end |
#new ⇒ HTML
Returns HTML view for creating a new role.
83 84 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 83 def new end |
#options ⇒ JSON
164 165 166 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 164 def respond_with_successful(RoleService.new(current_user).) end |
#show ⇒ HTML|Json
Returns HTML view showing the requested role or a Json that contains the information of the role. If there is an error, an explanation message is sent.
67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 67 def show respond_to do |format| format.html { } format.json { return respond_with_not_found unless @role.found? respond_with_successful(@role.show) } end 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.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/lesli_vault/roles_controller.rb', line 121 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 unless @role.successful? respond_with_error(@role.errors) end respond_with_successful(@role) end |