can remove a demarche

This commit is contained in:
simon lehericey 2024-01-30 09:57:43 +01:00
parent bc583e0fe2
commit 775e423914
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 23 additions and 5 deletions

View file

@ -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

View file

@ -69,6 +69,12 @@
- @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

View file

@ -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