Assigne admins to procedure.administrateurs

This commit is contained in:
Paul Chavard 2019-01-29 11:49:28 +01:00
parent 8085704d9f
commit 84383fc3c1
5 changed files with 31 additions and 3 deletions

View file

@ -67,7 +67,7 @@ class Admin::ProceduresController < AdminController
end
def create
@procedure = Procedure.new(procedure_params)
@procedure = current_administrateur.admin_procedures.build(procedure_params)
@path = @procedure.path
@availability = Procedure.path_availability(current_administrateur, @procedure.path)

View file

@ -189,7 +189,7 @@ class Procedure < ApplicationRecord
end
def clone(admin, from_library)
is_different_admin = self.administrateur_id != admin.id
is_different_admin = !admin.owns?(self)
populate_champ_stable_ids
procedure = self.deep_clone(include:
@ -214,6 +214,12 @@ class Procedure < ApplicationRecord
procedure.types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
end
if is_different_admin
procedure.administrateurs = [admin]
else
procedure.administrateurs = administrateurs
end
procedure.administrateur = admin
procedure.initiated_mail = initiated_mail&.dup
procedure.received_mail = received_mail&.dup

View file

@ -26,6 +26,8 @@ namespace :support do
procedure = Procedure.find(procedure_id)
rake_puts("Changing owner of procedure ##{procedure_id} from ##{procedure.administrateur_id} to ##{new_owner.id}")
procedure.administrateurs.delete(procedure.administrateur)
procedure.administrateurs << new_owner
procedure.update(administrateur: new_owner)
end
@ -68,6 +70,10 @@ namespace :support do
fail "Must specify a new owner"
end
procedures.each do |procedure|
procedure.administrateurs.delete(procedure.administrateur)
procedure.administrateurs << new_owner
end
procedures.update_all(administrateur_id: new_owner.id)
end

View file

@ -12,6 +12,10 @@ FactoryBot.define do
duree_conservation_dossiers_hors_ds { 6 }
ask_birthday { false }
after(:build) do |procedure|
procedure.administrateurs = [procedure.administrateur]
end
factory :procedure_with_dossiers do
transient do
dossiers_count { 1 }

View file

@ -404,7 +404,9 @@ describe Procedure do
context 'when the procedure is cloned from the library' do
let(:from_library) { true }
it { expect(subject.cloned_from_library).to be(true) }
it 'should set cloned_from_library to true' do
expect(subject.cloned_from_library).to be(true)
end
it 'should set service_id to nil' do
expect(subject.service).to eq(nil)
@ -415,6 +417,11 @@ describe Procedure do
expect(stc.old_pj).to be_nil
end
end
it 'should have one administrateur' do
expect(subject.administrateur).to eq(administrateur)
expect(subject.administrateurs).to eq([administrateur])
end
end
it 'should keep service_id' do
@ -435,6 +442,11 @@ describe Procedure do
expect(stc.old_pj).to be_nil
end
end
it 'should have one administrateur' do
expect(subject.administrateur).to eq(administrateur)
expect(subject.administrateurs).to eq([administrateur])
end
end
it 'should duplicate existing mail_templates' do