diff --git a/app/controllers/administrateurs/api_tokens_controller.rb b/app/controllers/administrateurs/api_tokens_controller.rb index 9d6403e9b..742f5916c 100644 --- a/app/controllers/administrateurs/api_tokens_controller.rb +++ b/app/controllers/administrateurs/api_tokens_controller.rb @@ -5,7 +5,7 @@ module Administrateurs include ActionView::RecordIdentifier before_action :authenticate_administrateur! - before_action :set_api_token, only: [:edit, :update, :destroy] + before_action :set_api_token, only: [:edit, :update, :destroy, :remove_procedure] def nom @name = name @@ -74,6 +74,15 @@ module Administrateurs render :edit end + def remove_procedure + procedure_id = params[:procedure_id].to_i + @api_token.allowed_procedure_ids = + @api_token.allowed_procedure_ids - [procedure_id] + @api_token.save! + + render turbo_stream: turbo_stream.remove("authorized_procedure_#{procedure_id}") + end + def destroy @api_token.destroy diff --git a/app/views/administrateurs/api_tokens/edit.html.haml b/app/views/administrateurs/api_tokens/edit.html.haml index 1d8e607a9..1d4635e43 100644 --- a/app/views/administrateurs/api_tokens/edit.html.haml +++ b/app/views/administrateurs/api_tokens/edit.html.haml @@ -65,10 +65,16 @@ %button.fr-btn.fr-btn--secondary.fr-ml-1w Ajouter - %ul.fr-mb-4w - - @api_token.procedures.each do |procedure| - %li{ id: dom_id(procedure, :authorized) } - = procedure.libelle + %ul.fr-mb-4w + - @api_token.procedures.each do |procedure| + %li{ id: dom_id(procedure, :authorized) } + = procedure.libelle + = button_to 'Supprimer', + remove_procedure_admin_api_token_path(@api_token, procedure_id: procedure.id), + class: 'fr-btn fr-btn--tertiary-no-outline fr-btn--sm fr-btn--icon-left fr-icon-delete-line', + form_class: 'inline', + method: :delete, + form: { data: { turbo: 'true' } } %ul.fr-btns-group.fr-btns-group--inline %li diff --git a/config/routes.rb b/config/routes.rb index e6440634a..4ecc68874 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -744,6 +744,9 @@ Rails.application.routes.draw do end resources :api_tokens, only: [:create, :destroy, :edit, :update] do + member do + delete 'remove_procedure' + end collection do get :nom get :autorisations