Merge pull request #1178 from sgmap/create-from-published

Create from published
This commit is contained in:
gregoirenovel 2018-01-08 15:00:38 +01:00 committed by GitHub
commit 5f9f6d243f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 8 deletions

View file

@ -136,9 +136,8 @@ class Admin::ProceduresController < AdminController
render '/admin/procedures/transfer', formats: 'js', status: 404
else
procedure = current_administrateur.procedures.find(params[:procedure_id])
clone_procedure = procedure.clone
clone_procedure = procedure.clone(admin)
clone_procedure.administrateur = admin
clone_procedure.save
flash.now.notice = "La procédure a correctement été clonée vers le nouvel administrateur."
@ -160,9 +159,9 @@ class Admin::ProceduresController < AdminController
end
def clone
procedure = current_administrateur.procedures.find(params[:procedure_id])
procedure = Procedure.find(params[:procedure_id])
new_procedure = procedure.clone
new_procedure = procedure.clone(current_administrateur)
if new_procedure
flash.notice = 'Procédure clonée'
redirect_to edit_admin_procedure_path(id: new_procedure.id)
@ -176,6 +175,20 @@ class Admin::ProceduresController < AdminController
redirect_to admin_procedures_path
end
def new_from_existing
procedures_with_more_than_30_dossiers_ids = Procedure
.publiees_ou_archivees
.joins(:dossiers)
.group("procedures.id")
.having("count(dossiers.id) > ?", 30)
.pluck('procedures.id')
@grouped_procedures = Procedure
.where(id: procedures_with_more_than_30_dossiers_ids)
.group_by(&:administrateur)
.sort_by { |a, _| a.created_at }
end
def active_class
@active_class = 'active'
end

View file

@ -98,7 +98,7 @@ class Procedure < ActiveRecord::Base
publiee_ou_archivee?
end
def clone
def clone(admin)
procedure = self.deep_clone(include:
{
types_de_piece_justificative: nil,
@ -112,6 +112,7 @@ class Procedure < ActiveRecord::Base
procedure.logo_secure_token = nil
procedure.remote_logo_url = self.logo_url
procedure.administrateur = admin
procedure.initiated_mail = initiated_mail.try(:dup)
procedure.received_mail = received_mail.try(:dup)
procedure.closed_mail = closed_mail.try(:dup)

View file

@ -1,3 +1,7 @@
.row.white-back
%a{ href: '/admin/procedures/new_from_existing', class: 'btn-sm btn-primary' }
Créer une nouvelle procédure à partir d'une procédure existante
.row.white-back
%h2
= t('dynamics.admin.dossiers.tableau_de_bord.nouvelle_procedure')

View file

@ -0,0 +1,21 @@
.row.white-back
%h2
Créer une nouvelle procédure à partir d'une procédure existante
.section.section-label
Pour rechercher dans cette liste, utilisez la fonction "Recherche" de votre navigateur (CTRL+F ou command+F)
%br
%br
- @grouped_procedures.each do |_, procedures|
%b
= procedures.first.organisation
%table{ style: 'margin-bottom: 40px;' }
- procedures.sort_by(&:id).each do |procedure|
%tr{ style: 'height: 36px;' }
%td{ style: 'width: 750px;' }
= procedure.libelle
%td{ style: 'padding-right: 10px; padding-left: 10px; width: 60px;' }
- if !procedure.archivee?
= link_to('Tester', commencer_path(procedure_path: procedure.path), target: "_blank")
%td
= link_to('Cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-sm btn-primary clone-btn')

View file

@ -117,6 +117,10 @@ Rails.application.routes.draw do
patch 'change_dossier_state' => 'change_dossier_state#change'
resources :procedures do
collection do
get 'new_from_existing' => 'procedures#new_from_existing', as: :new_from_existing
end
member do
post :hide
end

View file

@ -444,8 +444,10 @@ describe Admin::ProceduresController, type: :controller do
subject
end
it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:alert]).to have_content 'Procédure inexistante' }
it 'creates a new procedure and redirect to it' do
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
expect(flash[:notice]).to have_content 'Procédure clonée'
end
end
end

View file

@ -174,7 +174,7 @@ describe Procedure do
@signature.close
end
subject { procedure.clone }
subject { procedure.clone(procedure.administrateur) }
it 'should duplicate specific objects with different id' do
expect(subject.id).not_to eq(procedure.id)