diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index 9ca75b503..eb9d3c6ef 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -47,12 +47,12 @@ module Manager end def add_administrateur - administrateur = Administrateur.by_email(params[:email]) + administrateur = Administrateur.by_email(current_super_admin.email) if administrateur - procedure.administrateurs << administrateur - flash[:notice] = "L'administrateur \"#{params[:email]}\" est ajouté à la démarche." + AdministrateursProcedure.create(procedure: procedure, administrateur: administrateur, manager: true) + flash[:notice] = "L’administrateur \"#{administrateur.email}\" est ajouté à la démarche pour la journée." else - flash[:alert] = "L'administrateur \"#{params[:email]}\" est introuvable." + flash[:alert] = "Vous n’êtes pas connecté en tant qu’administrateur." end redirect_to manager_procedure_path(procedure) end diff --git a/app/jobs/cron/purge_manager_administrateur_sessions_job.rb b/app/jobs/cron/purge_manager_administrateur_sessions_job.rb new file mode 100644 index 000000000..29de55b38 --- /dev/null +++ b/app/jobs/cron/purge_manager_administrateur_sessions_job.rb @@ -0,0 +1,7 @@ +class Cron::PurgeManagerAdministrateurSessionsJob < Cron::CronJob + self.schedule_expression = "every day at 3 am" + + def perform + AdministrateursProcedure.where(manager: true).destroy_all + end +end diff --git a/app/models/administrateurs_procedure.rb b/app/models/administrateurs_procedure.rb index f0a883b04..1fd2002dc 100644 --- a/app/models/administrateurs_procedure.rb +++ b/app/models/administrateurs_procedure.rb @@ -2,6 +2,7 @@ # # Table name: administrateurs_procedures # +# manager :boolean # created_at :datetime not null # updated_at :datetime not null # administrateur_id :bigint not null diff --git a/app/views/manager/procedures/show.html.erb b/app/views/manager/procedures/show.html.erb index da0724ee8..492b787d7 100644 --- a/app/views/manager/procedures/show.html.erb +++ b/app/views/manager/procedures/show.html.erb @@ -64,9 +64,12 @@ as well as a link to its edit page.
Vous êtes déjà administrateur sur cette démarche
+ <% else %> + <%= form_tag(add_administrateur_manager_procedure_path(procedure), style: 'margin-top: 1rem;') do %> + + <% end %> <% end %> <% end %>