Merge pull request #3433 from tchak/multi-admin

[#1626] Duplicate administrateur in the administrateurs array
This commit is contained in:
Pierre de La Morinerie 2019-02-21 10:52:36 +01:00 committed by GitHub
commit 7eb53459a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 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

@ -0,0 +1,18 @@
namespace :after_party do
desc 'Deployment task: add_procedure_administrateur_to_administrateurs'
task add_procedure_administrateur_to_administrateurs: :environment do
rake_puts "Running deploy task: 'add_procedure_administrateur_to_administrateurs'"
procedures = Procedure.includes(:administrateurs)
progress = ProgressReport.new(procedures.count)
procedures.find_each do |procedure|
if !procedure.administrateurs.include?(procedure.administrateur)
procedure.administrateurs << procedure.administrateur
end
progress.inc
end
progress.finish
AfterParty::TaskRecord.create version: '20190214101524'
end
end

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