Admin can be transfer a clone of a procédure at an other admin

This commit is contained in:
Xavier J 2016-07-22 11:34:34 +02:00
parent e7830deefa
commit 2ad816b6b3
9 changed files with 137 additions and 20 deletions

View file

@ -22,7 +22,6 @@ function path_modal_action() {
})
}
function path_validation_action() {
$("input[id='procedure_path']").keyup(function (key) {
if (key.keyCode != 13)
@ -58,7 +57,6 @@ function validatePath(path) {
return re.test(path);
}
function path_type_init() {
display = 'label';
@ -89,3 +87,12 @@ function path_type_init() {
togglePathMessage(true, suggestion['mine']);
});
}
function transfer_errors_message(show) {
if(show){
$("#not_found_admin").slideDown(100)
}
else {
$("#not_found_admin").slideUp(100)
}
}

View file

@ -36,7 +36,6 @@ class Admin::ProceduresController < AdminController
render 'index'
end
def show
@facade = AdminProceduresShowFacades.new @procedure.decorate
end
@ -122,6 +121,22 @@ class Admin::ProceduresController < AdminController
redirect_to admin_procedures_path
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
procedure = current_administrateur.procedures.find(params[:procedure_id])
procedure.archive
@ -165,7 +180,7 @@ class Admin::ProceduresController < AdminController
def path_list
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
end

View file

@ -59,12 +59,16 @@ class Users::DossiersController < UsersController
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]
render '/dossiers/new_siret', formats: 'js'
rescue RestClient::ResourceNotFound
rescue RestClient::ResourceNotFound, RestClient::BadRequest
errors_valid_siret
rescue ActiveRecord::RecordNotFound

View 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' }

View file

@ -1,19 +1,26 @@
#procedure_show
=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'}
%i.fa.fa-eraser
Publier
%br
=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?
%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
Réactiver
%br
=render partial: '/admin/procedures/modal_publish'
-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
%button#archive.btn.btn-small.btn-default.text-info{type: :button}

View 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 %>

View file

@ -104,6 +104,7 @@ Rails.application.routes.draw do
put 'archive' => 'procedures#archive', as: :archive
put 'publish' => 'procedures#publish', as: :publish
post 'transfer' => 'procedures#transfer', as: :transfer
put 'clone' => 'procedures#clone', as: :clone
resource :accompagnateurs, only: [:show, :update]

View file

@ -77,7 +77,7 @@ describe Admin::ProceduresController, type: :controller do
subject
end
it { expect { subject }.to change{Procedure.count}.by(-1) }
it { expect { subject }.to change { Procedure.count }.by(-1) }
end
context 'when procedure is published' do
@ -451,4 +451,38 @@ describe Admin::ProceduresController, type: :controller do
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

View file

@ -160,15 +160,17 @@ describe Users::DossiersController, type: :controller do
end
describe 'POST #siret_informations' do
let(:user) { create(:user) }
before do
stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
.to_return(status: 404, body: 'fake body')
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}")
.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}")
.to_return(status: exercices_status, body: exercices_body)
@ -180,8 +182,7 @@ describe Users::DossiersController, type: :controller do
end
describe 'dossier attributs' do
let(:user) { create(:user) }
let(:status_entreprise_call) { 200 }
shared_examples 'with valid siret' do
before do
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 }
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
describe 'PUT #update' do