Merge pull request #3786 from betagouv/multi-admin-ui
[#1626] Multi-admin UI
This commit is contained in:
commit
5477bd67ee
9 changed files with 109 additions and 1 deletions
|
@ -0,0 +1,46 @@
|
||||||
|
module NewAdministrateur
|
||||||
|
class ProcedureAdministrateursController < AdministrateurController
|
||||||
|
before_action :retrieve_procedure
|
||||||
|
|
||||||
|
def index
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
email = params.require(:administrateur)[:email]&.strip&.downcase
|
||||||
|
|
||||||
|
# Find the admin
|
||||||
|
administrateur = Administrateur.find_by(email: email)
|
||||||
|
if administrateur.nil?
|
||||||
|
flash.alert = "L’administrateur « #{email} » n’existe pas. Invitez-le à demander un compte administrateur à l’addresse <a href=#{new_demande_url}>#{new_demande_url}</a>."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Prevent duplicates (also enforced in the database in administrateurs_procedures)
|
||||||
|
if @procedure.administrateurs.include?(administrateur)
|
||||||
|
flash.alert = "L’administrateur « #{administrateur.email} » est déjà administrateur de « #{@procedure.libelle} »."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Actually add the admin
|
||||||
|
@procedure.administrateurs << administrateur
|
||||||
|
@administrateur = administrateur
|
||||||
|
flash.notice = "L’administrateur « #{administrateur.email} » a été ajouté à la démarche « #{@procedure.libelle} »."
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
administrateur = @procedure.administrateurs.find(params[:id])
|
||||||
|
|
||||||
|
# Prevent self-removal (Also enforced in the UI)
|
||||||
|
if administrateur == current_administrateur
|
||||||
|
flash.error = "Vous ne pouvez pas vous retirer vous-même d’une démarche."
|
||||||
|
end
|
||||||
|
|
||||||
|
# Actually remove the admin
|
||||||
|
@procedure.administrateurs.delete(administrateur)
|
||||||
|
@administrateur = administrateur
|
||||||
|
flash.notice = "L’administrateur \« #{administrateur.email} » a été retiré de la démarche « #{@procedure.libelle} »."
|
||||||
|
rescue ActiveRecord::ActiveRecordError => e
|
||||||
|
flash.alert = e.message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,8 @@
|
||||||
require Rails.root.join('lib', 'percentile')
|
require Rails.root.join('lib', 'percentile')
|
||||||
|
|
||||||
class Procedure < ApplicationRecord
|
class Procedure < ApplicationRecord
|
||||||
|
self.ignored_columns = [:administrateur_id]
|
||||||
|
|
||||||
MAX_DUREE_CONSERVATION = 36
|
MAX_DUREE_CONSERVATION = 36
|
||||||
|
|
||||||
has_many :types_de_piece_justificative, -> { ordered }, dependent: :destroy
|
has_many :types_de_piece_justificative, -> { ordered }, dependent: :destroy
|
||||||
|
@ -17,7 +19,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
has_many :assign_to, dependent: :destroy
|
has_many :assign_to, dependent: :destroy
|
||||||
has_many :administrateurs_procedures
|
has_many :administrateurs_procedures
|
||||||
has_many :administrateurs, through: :administrateurs_procedures
|
has_many :administrateurs, through: :administrateurs_procedures, after_remove: -> (procedure, _admin) { procedure.validate! }
|
||||||
has_many :gestionnaires, through: :assign_to
|
has_many :gestionnaires, through: :assign_to
|
||||||
|
|
||||||
has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy
|
has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy
|
||||||
|
@ -57,6 +59,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
validates :administrateurs, presence: true
|
||||||
validate :check_juridique
|
validate :check_juridique
|
||||||
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: :aasm_state, case_sensitive: false }, presence: true, allow_blank: false, allow_nil: true
|
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: :aasm_state, case_sensitive: false }, presence: true, allow_blank: false, allow_nil: true
|
||||||
# FIXME: remove duree_conservation_required flag once all procedures are converted to the new style
|
# FIXME: remove duree_conservation_required flag once all procedures are converted to the new style
|
||||||
|
|
|
@ -27,6 +27,10 @@
|
||||||
- if @procedure.missing_steps.include?(:service)
|
- if @procedure.missing_steps.include?(:service)
|
||||||
%p.missing-steps (à compléter)
|
%p.missing-steps (à compléter)
|
||||||
|
|
||||||
|
%a#onglet-administrateurs{ href: url_for(procedure_administrateurs_path(@procedure)) }
|
||||||
|
.procedure-list-element{ class: ('active' if active == 'Administrateurs') }
|
||||||
|
Administrateurs
|
||||||
|
|
||||||
%a#onglet-instructeurs{ href: url_for(admin_procedure_instructeurs_path(@procedure)) }
|
%a#onglet-instructeurs{ href: url_for(admin_procedure_instructeurs_path(@procedure)) }
|
||||||
.procedure-list-element{ class: ('active' if active == 'Instructeurs') }
|
.procedure-list-element{ class: ('active' if active == 'Instructeurs') }
|
||||||
Instructeurs
|
Instructeurs
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
%tr{ id: "procedure-#{@procedure.id}-administrateur-#{administrateur.id}" }
|
||||||
|
%td= administrateur.email
|
||||||
|
%td= administrateur.created_at.strftime('%d/%m/%Y %H:%M')
|
||||||
|
%td= administrateur.registration_state
|
||||||
|
%td
|
||||||
|
- if administrateur == current_administrateur
|
||||||
|
C’est vous !
|
||||||
|
- else
|
||||||
|
= link_to 'Retirer',
|
||||||
|
[@procedure, administrateur],
|
||||||
|
method: :delete,
|
||||||
|
'data-confirm': "Retirer « #{administrateur.email} » des administrateurs de « #{@procedure.libelle} » ?",
|
||||||
|
remote: true
|
|
@ -0,0 +1,6 @@
|
||||||
|
= render_flash(sticky: true)
|
||||||
|
- if @administrateur
|
||||||
|
= append_to_element("#procedure-#{@procedure.id}-administrateurs",
|
||||||
|
partial: 'administrateur',
|
||||||
|
locals: { administrateur: @administrateur })
|
||||||
|
document.getElementById('procedure-#{@procedure.id}-new_administrateur').reset()
|
|
@ -0,0 +1,4 @@
|
||||||
|
= render_flash(sticky: true)
|
||||||
|
- if @administrateur
|
||||||
|
= remove_element("#procedure-#{@procedure.id}-administrateur-#{@administrateur.id}")
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
= render partial: 'new_administrateur/breadcrumbs',
|
||||||
|
locals: { steps: [link_to('Démarches', admin_procedures_path),
|
||||||
|
link_to(@procedure.libelle, admin_procedure_path(@procedure)),
|
||||||
|
'Administrateurs'], preview: false }
|
||||||
|
|
||||||
|
.container
|
||||||
|
%h1 Administrateurs de « #{@procedure.libelle} »
|
||||||
|
%table.table
|
||||||
|
%thead
|
||||||
|
%th= 'Adresse email'
|
||||||
|
%th= 'Enregistré le'
|
||||||
|
%th= 'État'
|
||||||
|
%tbody{ id: "procedure-#{@procedure.id}-administrateurs" }
|
||||||
|
= render partial: 'administrateur', collection: @procedure.administrateurs.order(:email)
|
||||||
|
%tfoot
|
||||||
|
%tr
|
||||||
|
%th{ colspan: 4 }
|
||||||
|
= form_for @procedure.administrateurs.new,
|
||||||
|
url: { controller: 'procedure_administrateurs' },
|
||||||
|
html: { class: 'form', id: "procedure-#{@procedure.id}-new_administrateur" } ,
|
||||||
|
remote: true do |f|
|
||||||
|
= f.label :email do
|
||||||
|
Ajouter un administrateur
|
||||||
|
%span.notice= "Renseignez l’email d’un administrateur déjà enregistré sur demarches-simplifiees.fr pour lui permettre de modifier « #{@procedure.libelle} »."
|
||||||
|
= f.email_field :email, placeholder: 'marie.dupont@exemple.fr', required: true
|
||||||
|
= f.submit 'Ajouter comme administrateur', class: 'button primary send'
|
|
@ -374,6 +374,8 @@ Rails.application.routes.draw do
|
||||||
get 'annotations'
|
get 'annotations'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :administrateurs, controller: 'procedure_administrateurs', only: [:index, :create, :destroy]
|
||||||
|
|
||||||
resources :types_de_champ, only: [:create, :update, :destroy] do
|
resources :types_de_champ, only: [:create, :update, :destroy] do
|
||||||
member do
|
member do
|
||||||
patch :move
|
patch :move
|
||||||
|
|
|
@ -168,6 +168,10 @@ describe Procedure do
|
||||||
it { is_expected.to allow_value('URRSAF').for(:organisation) }
|
it { is_expected.to allow_value('URRSAF').for(:organisation) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'administrateurs' do
|
||||||
|
it { is_expected.not_to allow_value([]).for(:administrateurs) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'juridique' do
|
context 'juridique' do
|
||||||
it { is_expected.not_to allow_value(nil).for(:cadre_juridique) }
|
it { is_expected.not_to allow_value(nil).for(:cadre_juridique) }
|
||||||
it { is_expected.to allow_value('text').for(:cadre_juridique) }
|
it { is_expected.to allow_value('text').for(:cadre_juridique) }
|
||||||
|
|
Loading…
Reference in a new issue