feat(manager): add become administrateur button in manager (with 24h expiration)
This commit is contained in:
parent
91fbd3e97b
commit
4a947f9135
6 changed files with 25 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -64,9 +64,12 @@ as well as a link to its edit page.
|
|||
<dd class="attribute-data attribute-data--<%=attribute.html_class%>">
|
||||
<%= 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;') %>
|
||||
<button>Ajouter un administrateur</button>
|
||||
<% 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>
|
||||
<% else %>
|
||||
<%= form_tag(add_administrateur_manager_procedure_path(procedure), style: 'margin-top: 1rem;') do %>
|
||||
<button>Devenir administrateur (pour la journée)</button>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</dd>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddManagerToAdministrateursProcedures < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :administrateurs_procedures, :manager, :boolean
|
||||
end
|
||||
end
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue