Admin can be transfer a clone of a procédure at an other admin
This commit is contained in:
parent
e7830deefa
commit
2ad816b6b3
9 changed files with 137 additions and 20 deletions
|
@ -22,7 +22,6 @@ function path_modal_action() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function path_validation_action() {
|
function path_validation_action() {
|
||||||
$("input[id='procedure_path']").keyup(function (key) {
|
$("input[id='procedure_path']").keyup(function (key) {
|
||||||
if (key.keyCode != 13)
|
if (key.keyCode != 13)
|
||||||
|
@ -58,7 +57,6 @@ function validatePath(path) {
|
||||||
return re.test(path);
|
return re.test(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function path_type_init() {
|
function path_type_init() {
|
||||||
display = 'label';
|
display = 'label';
|
||||||
|
|
||||||
|
@ -89,3 +87,12 @@ function path_type_init() {
|
||||||
togglePathMessage(true, suggestion['mine']);
|
togglePathMessage(true, suggestion['mine']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transfer_errors_message(show) {
|
||||||
|
if(show){
|
||||||
|
$("#not_found_admin").slideDown(100)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#not_found_admin").slideUp(100)
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,7 +36,6 @@ class Admin::ProceduresController < AdminController
|
||||||
render 'index'
|
render 'index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@facade = AdminProceduresShowFacades.new @procedure.decorate
|
@facade = AdminProceduresShowFacades.new @procedure.decorate
|
||||||
end
|
end
|
||||||
|
@ -122,6 +121,22 @@ class Admin::ProceduresController < AdminController
|
||||||
redirect_to admin_procedures_path
|
redirect_to admin_procedures_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def transfer
|
||||||
|
admin = Administrateur.find_by_email(params[:email_admin])
|
||||||
|
#
|
||||||
|
return render '/admin/procedures/transfer', formats: 'js', status: 404 if admin.nil?
|
||||||
|
#
|
||||||
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||||
|
|
||||||
|
clone_procedure = procedure.clone
|
||||||
|
clone_procedure.administrateur = admin
|
||||||
|
clone_procedure.save
|
||||||
|
|
||||||
|
flash.now.notice = "La procédure a correctement été cloné vers le nouvel administrateur."
|
||||||
|
|
||||||
|
render '/admin/procedures/transfer', formats: 'js', status: 200
|
||||||
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||||
procedure.archive
|
procedure.archive
|
||||||
|
@ -165,7 +180,7 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
def path_list
|
def path_list
|
||||||
render json: ProcedurePath.where("path LIKE '%#{params[:request]}%'").pluck(:path, :administrateur_id).inject([]) {
|
render json: ProcedurePath.where("path LIKE '%#{params[:request]}%'").pluck(:path, :administrateur_id).inject([]) {
|
||||||
|acc, value| acc.push({ label: value.first, mine: value.second == current_administrateur.id })
|
|acc, value| acc.push({label: value.first, mine: value.second == current_administrateur.id})
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -59,12 +59,16 @@ class Users::DossiersController < UsersController
|
||||||
|
|
||||||
update_current_user_siret! siret
|
update_current_user_siret! siret
|
||||||
|
|
||||||
DossierService.new(@facade.dossier, siret, current_user.france_connect_information).dossier_informations!
|
dossier = DossierService.new(@facade.dossier, siret, current_user.france_connect_information).dossier_informations!
|
||||||
|
|
||||||
|
if dossier.entreprise.nil?
|
||||||
|
return errors_valid_siret
|
||||||
|
end
|
||||||
|
|
||||||
@facade = facade params[:dossier_id]
|
@facade = facade params[:dossier_id]
|
||||||
render '/dossiers/new_siret', formats: 'js'
|
render '/dossiers/new_siret', formats: 'js'
|
||||||
|
|
||||||
rescue RestClient::ResourceNotFound
|
rescue RestClient::ResourceNotFound, RestClient::BadRequest
|
||||||
errors_valid_siret
|
errors_valid_siret
|
||||||
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
23
app/views/admin/procedures/_modal_transfer.html.haml
Normal file
23
app/views/admin/procedures/_modal_transfer.html.haml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#transferModal.modal.fade{"aria-labelledby" => "TransferProcedureModal", :role => "dialog", :tabindex => "-1"}
|
||||||
|
.modal-dialog.modal-md{:role => "document"}
|
||||||
|
= form_tag admin_procedure_transfer_path(procedure_id: @procedure.id), method: :post, remote: true do
|
||||||
|
.modal-content
|
||||||
|
.modal-header
|
||||||
|
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
|
||||||
|
%span{"aria-hidden" => "true"} ×
|
||||||
|
%h4#myModalLabel.modal-title
|
||||||
|
Petit transfert de procédure entre administrateur
|
||||||
|
.modal-body
|
||||||
|
%p
|
||||||
|
Cette fonctionnalité vous permet de transmettre un clone de votre procédure à un autre administrateur.
|
||||||
|
%div{style:'margin-top:20px'}
|
||||||
|
= text_field_tag :email_admin, '', {class: 'form-control',
|
||||||
|
type: 'email',
|
||||||
|
placeholder: 'Email administrateur cible',
|
||||||
|
maxlength: 30,
|
||||||
|
style: 'width: 300px; margin-left:auto; margin-right:auto'}
|
||||||
|
%div#not_found_admin.center.text-danger{style:'display:none; margin-top: 10px'}
|
||||||
|
Cet administrateur n'existe pas.
|
||||||
|
.modal-footer
|
||||||
|
= submit_tag "Envoyer", class: 'btn btn-success'
|
||||||
|
= button_tag 'Annuler', class: %w(btn btn btn-default), id: 'cancel', data: { dismiss: 'modal' }
|
|
@ -1,19 +1,26 @@
|
||||||
#procedure_show
|
#procedure_show
|
||||||
=render partial: 'head', locals: {active: 'Informations'}
|
=render partial: 'head', locals: {active: 'Informations'}
|
||||||
|
|
||||||
-if ! @facade.procedure.published?
|
-unless @facade.procedure.published?
|
||||||
%a#publish.btn.btn-success{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
%a#publish.btn.btn-success{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||||
%i.fa.fa-eraser
|
%i.fa.fa-eraser
|
||||||
Publier
|
Publier
|
||||||
%br
|
|
||||||
=render partial: '/admin/procedures/modal_publish'
|
=render partial: '/admin/procedures/modal_publish'
|
||||||
|
|
||||||
|
%a#reenable.btn.btn-small.btn-default{"data-target" => "#transferModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||||
|
%i.fa.fa-exchange
|
||||||
|
Transférer
|
||||||
|
|
||||||
|
=render partial: '/admin/procedures/modal_transfer'
|
||||||
|
|
||||||
-if @facade.procedure.archived?
|
-if @facade.procedure.archived?
|
||||||
%a#reenable.btn.btn-small.btn-default.text-info{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
%a#reenable.btn.btn-small.btn-default.text-info{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||||
%i.fa.fa-eraser
|
%i.fa.fa-eraser
|
||||||
Réactiver
|
Réactiver
|
||||||
%br
|
|
||||||
=render partial: '/admin/procedures/modal_publish'
|
=render partial: '/admin/procedures/modal_publish'
|
||||||
|
|
||||||
-elsif @facade.procedure.published?
|
-elsif @facade.procedure.published?
|
||||||
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do
|
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do
|
||||||
%button#archive.btn.btn-small.btn-default.text-info{type: :button}
|
%button#archive.btn.btn-small.btn-default.text-info{type: :button}
|
||||||
|
|
11
app/views/admin/procedures/transfer.js.erb
Normal file
11
app/views/admin/procedures/transfer.js.erb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<%- if response.status == 404 %>
|
||||||
|
transfer_errors_message(true);
|
||||||
|
<%- else %>
|
||||||
|
<% flash.each do |type, message| %>
|
||||||
|
$("#flash_message").html("<div class=\"alert alert-success\"> <%= message.html_safe %></div>")
|
||||||
|
<% end %>
|
||||||
|
<% flash.clear %>
|
||||||
|
transfer_errors_message(false);
|
||||||
|
$("#email_admin").val('');
|
||||||
|
$("button#cancel").click();
|
||||||
|
<%- end %>
|
|
@ -104,6 +104,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
put 'archive' => 'procedures#archive', as: :archive
|
put 'archive' => 'procedures#archive', as: :archive
|
||||||
put 'publish' => 'procedures#publish', as: :publish
|
put 'publish' => 'procedures#publish', as: :publish
|
||||||
|
post 'transfer' => 'procedures#transfer', as: :transfer
|
||||||
put 'clone' => 'procedures#clone', as: :clone
|
put 'clone' => 'procedures#clone', as: :clone
|
||||||
|
|
||||||
resource :accompagnateurs, only: [:show, :update]
|
resource :accompagnateurs, only: [:show, :update]
|
||||||
|
|
|
@ -77,7 +77,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect { subject }.to change{Procedure.count}.by(-1) }
|
it { expect { subject }.to change { Procedure.count }.by(-1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when procedure is published' do
|
context 'when procedure is published' do
|
||||||
|
@ -451,4 +451,38 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'POST transfer' do
|
||||||
|
let!(:procedure) { create :procedure, administrateur: admin }
|
||||||
|
|
||||||
|
subject { post :transfer, email_admin: email_admin, procedure_id: procedure.id }
|
||||||
|
|
||||||
|
context 'when admin is unknow' do
|
||||||
|
let(:email_admin) { 'plop' }
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 404 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when admin is know' do
|
||||||
|
let(:new_admin) { create :administrateur, email: 'new_admin@admin.com' }
|
||||||
|
let(:email_admin) { new_admin.email }
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 200 }
|
||||||
|
|
||||||
|
it 'procedure clone is called' do
|
||||||
|
expect_any_instance_of(Procedure).to receive(:clone)
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect {subject}.to change(Procedure, :count).by(1) }
|
||||||
|
|
||||||
|
context {
|
||||||
|
before do
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(Procedure.last.administrateur).to eq new_admin }
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -160,15 +160,17 @@ describe Users::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #siret_informations' do
|
describe 'POST #siret_informations' do
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
|
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
|
||||||
.to_return(status: 404, body: 'fake body')
|
.to_return(status: 404, body: 'fake body')
|
||||||
|
|
||||||
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}")
|
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}")
|
||||||
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
|
.to_return(status: status_entreprise_call, body: File.read('spec/support/files/etablissement.json'))
|
||||||
|
|
||||||
stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}")
|
stub_request(:get, "https://api-dev.apientreprise.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}")
|
||||||
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
|
.to_return(status: status_entreprise_call, body: File.read('spec/support/files/entreprise.json'))
|
||||||
|
|
||||||
stub_request(:get, "https://api-dev.apientreprise.fr/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
|
stub_request(:get, "https://api-dev.apientreprise.fr/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
|
||||||
.to_return(status: exercices_status, body: exercices_body)
|
.to_return(status: exercices_status, body: exercices_body)
|
||||||
|
@ -180,8 +182,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'dossier attributs' do
|
describe 'dossier attributs' do
|
||||||
let(:user) { create(:user) }
|
let(:status_entreprise_call) { 200 }
|
||||||
|
|
||||||
shared_examples 'with valid siret' do
|
shared_examples 'with valid siret' do
|
||||||
before do
|
before do
|
||||||
sign_in user
|
sign_in user
|
||||||
|
@ -322,6 +323,20 @@ describe Users::DossiersController, type: :controller do
|
||||||
it { expect(response.to_a[2]).to be_an_instance_of ActionDispatch::Response::RackBody }
|
it { expect(response.to_a[2]).to be_an_instance_of ActionDispatch::Response::RackBody }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when REST error 400 is return' do
|
||||||
|
let(:status_entreprise_call) { 400 }
|
||||||
|
|
||||||
|
subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: siret} }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in user
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response.status).to eq 200 }
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
|
|
Loading…
Reference in a new issue