Class: Decidim::System::ApiUsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Decidim::System::ApiUsersController
- Defined in:
- app/controllers/decidim/system/api_users_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/decidim/system/api_users_controller.rb', line 43 def create @form = ::Decidim::System::ApiUserForm.from_params(params.merge!(name: params[:admin][:name], organization: organization)) CreateApiUser.call(@form, current_admin) do on(:ok) do |api_user, secret| flash[:notice] = I18n.t("api_user.create.success", scope: "decidim.system", user: api_user.api_key) session[:api_user] = { id: api_user.id, secret: secret } redirect_to action: :index end on(:invalid) do flash[:error] = I18n.t("api_user.create.error", scope: "decidim.system") render :new, status: :unprocessable_entity end end end |
#destroy ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/decidim/system/api_users_controller.rb', line 18 def destroy Decidim.traceability.perform_action!("delete", api_user, current_admin) do api_user.destroy! end flash[:notice] = I18n.t("api_user.destroy.success", scope: "decidim.system") redirect_to action: :index end |
#index ⇒ Object
9 10 11 12 |
# File 'app/controllers/decidim/system/api_users_controller.rb', line 9 def index @api_users = api_users @secret_user = session.delete(:api_user)&.with_indifferent_access end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/decidim/system/api_users_controller.rb', line 14 def new @form = form(::Decidim::System::ApiUserForm).instance end |
#update ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/decidim/system/api_users_controller.rb', line 28 def update RefreshApiUserSecret.call(api_user, current_admin) do on(:ok) do |secret| flash[:notice] = I18n.t("api_user.refresh.success", scope: "decidim.system", user: api_user.api_key) session[:api_user] = { id: api_user.id, secret: secret } redirect_to action: :index end on(:invalid) do flash[:notice] = I18n.t("api_user.refresh.error", scope: "decidim.system") redirect_to action: :index end end end |