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.
<%= render_field attribute, page: page %> <% if attribute.name == 'administrateurs' %> - <%= form_tag(add_administrateur_manager_procedure_path(procedure), style: 'margin-top: 1rem;') do %> - <%= email_field_tag(:email, '', placeholder: 'Email', autocapitalize: 'off', autocorrect: 'off', spellcheck: 'false', style: 'margin-bottom: 1rem;width:24rem;') %> - + <% if procedure.administrateurs.find { |admin| admin.email == current_super_admin.email } %> +

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 %>
diff --git a/db/migrate/20211006164955_add_manager_to_administrateurs_procedures.rb b/db/migrate/20211006164955_add_manager_to_administrateurs_procedures.rb new file mode 100644 index 000000000..8e424a92b --- /dev/null +++ b/db/migrate/20211006164955_add_manager_to_administrateurs_procedures.rb @@ -0,0 +1,5 @@ +class AddManagerToAdministrateursProcedures < ActiveRecord::Migration[6.1] + def change + add_column :administrateurs_procedures, :manager, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c75e2aea..2d29640fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_01_143403) do +ActiveRecord::Schema.define(version: 2021_10_06_164955) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -76,6 +76,7 @@ ActiveRecord::Schema.define(version: 2021_10_01_143403) do t.bigint "procedure_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "manager" t.index ["administrateur_id", "procedure_id"], name: "index_unique_admin_proc_couple", unique: true t.index ["administrateur_id"], name: "index_administrateurs_procedures_on_administrateur_id" t.index ["procedure_id"], name: "index_administrateurs_procedures_on_procedure_id"