Merge pull request #7672 from betagouv/feat/7668

Manager : permet au super admin de se retirer d'une démarche
This commit is contained in:
Kara Diaby 2022-08-11 12:30:46 +02:00 committed by GitHub
commit 4bddb4dde9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View file

@ -67,6 +67,14 @@ module Manager
redirect_to manager_procedure_path(procedure)
end
def delete_administrateur
administrateur = procedure.administrateurs.find { |admin| admin.email == current_super_admin.email }
if administrateur.present?
procedure.administrateurs.delete(administrateur)
end
redirect_to manager_procedure_path(procedure)
end
def change_piece_justificative_template
if type_de_champ.update(type_de_champ_params)
flash[:notice] = "Le modèle est mis à jour."

View file

@ -70,6 +70,8 @@ as well as a link to its edit page.
<% end %>
<% if procedure.administrateurs.find { |admin| admin.email == current_super_admin.email } %>
<p style="margin-top: 20px;">Vous êtes déjà administrateur sur cette démarche</p>
<%= link_to 'Me retirer de cette démarche', delete_administrateur_manager_procedure_path(procedure), method: :put, class: 'button' %>
<% else %>
<%= form_tag(add_administrateur_manager_procedure_path(procedure), style: 'margin-top: 1rem;') do %>
<button>Devenir administrateur (pour la journée)</button>

View file

@ -16,6 +16,7 @@ Rails.application.routes.draw do
post 'discard', on: :member
post 'restore', on: :member
post 'add_administrateur', on: :member
put 'delete_administrateur', on: :member
post 'change_piece_justificative_template', on: :member
get 'export_mail_brouillons', on: :member
end

View file

@ -1,6 +1,7 @@
describe Manager::ProceduresController, type: :controller do
let(:super_admin) { create :super_admin }
let(:administrateur) { create(:administrateur, email: super_admin.email) }
let(:autre_administrateur) { create(:administrateur) }
before { sign_in super_admin }
describe '#whitelist' do
@ -68,4 +69,14 @@ describe Manager::ProceduresController, type: :controller do
it { expect(response.body).to include('1 dossier') }
end
end
describe '#delete_administrateur' do
let(:procedure) { create(:procedure, :with_service, administrateurs: [administrateur, autre_administrateur]) }
before do
put :delete_administrateur, params: { id: procedure.id }
end
it { expect(procedure.administrateurs).to eq([autre_administrateur]) }
end
end