From d8253be4e5cbd4cce16cabe848a4e1763c1d4d90 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 15 Dec 2015 17:46:05 +0100 Subject: [PATCH 01/11] - Into views, replace words : - Gestionnaire by Accompagnateur - Entreprise by Organisation - Add procedure libelle on user dossier show page --- app/views/admin/procedures/show.html.haml | 4 ++-- app/views/dossiers/_infos_dossier.html.haml | 3 ++- app/views/dossiers/_infos_entreprise.html.haml | 2 +- app/views/dossiers/_show.html.haml | 2 +- app/views/gestionnaires/sessions/new.html.haml | 2 +- app/views/notification_mailer/dossier_validated.text.erb | 2 +- app/views/users/sessions/new.html.haml | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index b7c91d065..ca57f6258 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -44,11 +44,11 @@ %div = @facade.dossiers_total - %h4.text-danger Attente Gestionnaire + %h4.text-danger Attente Accompagnateur %div = @facade.dossiers_waiting_gestionnaire_total - %h4.text-info Attente User + %h4.text-info Attente Utilisateur %div = @facade.dossiers_waiting_user_total diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index f04b5ac11..852ffac67 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -4,7 +4,8 @@ .col-lg-6.col-md-6 %h3.text-info = @dossier.nom_projet - + %h4 + = @dossier.procedure.libelle .description - begin - @dossier.description.split(/(?:\n\r?|\r\n?')/).each do |line| diff --git a/app/views/dossiers/_infos_entreprise.html.haml b/app/views/dossiers/_infos_entreprise.html.haml index 4e6eaab81..c827acefb 100644 --- a/app/views/dossiers/_infos_entreprise.html.haml +++ b/app/views/dossiers/_infos_entreprise.html.haml @@ -24,7 +24,7 @@ %dt Date de création : %dd= Time.at(@entreprise.date_creation).strftime "%d-%m-%Y" - %dt Effectif entreprise : + %dt Effectif organisation : %dd= @entreprise.effectif %dt Code effectif : diff --git a/app/views/dossiers/_show.html.haml b/app/views/dossiers/_show.html.haml index 2ffdf472d..c04d248c7 100644 --- a/app/views/dossiers/_show.html.haml +++ b/app/views/dossiers/_show.html.haml @@ -8,6 +8,6 @@ = form_for @dossier, url: { controller: '/users/dossiers', action: :update } do |f| %label{ style:'font-weight:normal' } = f.check_box :autorisation_donnees - J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles. + J'autorise les organismes publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. %br = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante' \ No newline at end of file diff --git a/app/views/gestionnaires/sessions/new.html.haml b/app/views/gestionnaires/sessions/new.html.haml index 75162f9e4..88a775c77 100644 --- a/app/views/gestionnaires/sessions/new.html.haml +++ b/app/views/gestionnaires/sessions/new.html.haml @@ -1,7 +1,7 @@ #form_login = image_tag('logo-tps.png') %br - %h2#gestionnaire_login Gestionnaire + %h2#gestionnaire_login Accompagnateur %br %br diff --git a/app/views/notification_mailer/dossier_validated.text.erb b/app/views/notification_mailer/dossier_validated.text.erb index 7a1b0004a..d53e46c87 100644 --- a/app/views/notification_mailer/dossier_validated.text.erb +++ b/app/views/notification_mailer/dossier_validated.text.erb @@ -1,6 +1,6 @@ Bonjour <%= @user.email %>! -Votre dossier N°<%=@dossier.id%> a été validé par votre gestionnaire. +Votre dossier N°<%=@dossier.id%> a été validé par votre accompagnateur. Afin de finaliser son dépot, merci de vous rendre sur <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%> diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index 62f8f7de6..4f797acd8 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -37,7 +37,7 @@ \- %br %a{href: '/gestionnaires/sign_in'} - = 'Gestionnaire' + = 'Accompagnateur' %br %a{href: '/administrateurs/sign_in'} = 'Administrateur' From ed8b4ff083d1b2f9ac4b27108fbf31895086f071 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 17 Dec 2015 10:06:40 +0100 Subject: [PATCH 02/11] Add mailer submitted dossier. --- app/mailers/notification_mailer.rb | 4 ++++ .../notification_mailer/dossier_submitted.text.erb | 8 ++++++++ .../notification_mailer/dossier_validated.text.erb | 2 +- app/views/notification_mailer/new_answer.text.erb | 2 +- spec/mailers/notification_mailer_spec.rb | 12 ++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 app/views/notification_mailer/dossier_submitted.text.erb diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 7f5fb7243..eb609268b 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -7,6 +7,10 @@ class NotificationMailer < ApplicationMailer send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été validé" end + def dossier_submitted dossier + send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été déposé" + end + private def vars_mailer dossier diff --git a/app/views/notification_mailer/dossier_submitted.text.erb b/app/views/notification_mailer/dossier_submitted.text.erb new file mode 100644 index 000000000..ced433b16 --- /dev/null +++ b/app/views/notification_mailer/dossier_submitted.text.erb @@ -0,0 +1,8 @@ +Bonjour <%= @user.email %> + +Nous vous confirmons que votre dossier N°<%=@dossier.id%> a été déposé aurpès de <%= @dossier.procedure.organisation %> avec succès ce jour à <%= @dossier.updated_at %>. + +Bonne journée + +--- +L'équide TPS - tps@apientreprise.fr \ No newline at end of file diff --git a/app/views/notification_mailer/dossier_validated.text.erb b/app/views/notification_mailer/dossier_validated.text.erb index d53e46c87..f2a555ac4 100644 --- a/app/views/notification_mailer/dossier_validated.text.erb +++ b/app/views/notification_mailer/dossier_validated.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @user.email %>! +Bonjour <%= @user.email %> Votre dossier N°<%=@dossier.id%> a été validé par votre accompagnateur. diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index 85fa66ee7..947d7826d 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @user.email %>! +Bonjour <%= @user.email %> Un nouveau commentaire est disponible dans votre espace TPS. diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 779923ba9..deed3f916 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -22,4 +22,16 @@ RSpec.describe NotificationMailer, type: :mailer do it { expect(subject.body).to include("Afin de finaliser son dépot, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") } it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été validé") } end + + describe ".dossier_submitted" do + let(:user) { create(:user) } + let(:dossier) { create(:dossier, :with_procedure, user: user) } + + subject(:subject) { described_class.dossier_submitted(dossier) } + + it { expect(subject.body).to match("Nous vous confirmons que votre dossier N°#{dossier.id} a été déposé") } + it { expect(subject.body).to match("aurpès de #{dossier.procedure.organisation} avec succès") } + it { expect(subject.body).to match("ce jour à #{dossier.updated_at}.") } + it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été déposé") } + end end From 44554a9baa76b702c5343230ed8eee6661f431e3 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 17 Dec 2015 10:09:44 +0100 Subject: [PATCH 03/11] Send an email when user submitted his file --- app/controllers/users/recapitulatif_controller.rb | 2 ++ .../users/recapitulatif_controller_spec.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/recapitulatif_controller.rb b/app/controllers/users/recapitulatif_controller.rb index fb78e129e..91849e2b4 100644 --- a/app/controllers/users/recapitulatif_controller.rb +++ b/app/controllers/users/recapitulatif_controller.rb @@ -29,6 +29,8 @@ class Users::RecapitulatifController < UsersController @dossier.next_step! 'user', 'submit' flash.notice = 'Dossier déposé avec succès.' + NotificationMailer.dossier_submitted(@dossier).deliver_now! + render 'show' end end diff --git a/spec/controllers/users/recapitulatif_controller_spec.rb b/spec/controllers/users/recapitulatif_controller_spec.rb index 92661139e..6b1858ea3 100644 --- a/spec/controllers/users/recapitulatif_controller_spec.rb +++ b/spec/controllers/users/recapitulatif_controller_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Users::RecapitulatifController, type: :controller do - let(:dossier) { create(:dossier, :with_user) } + let(:dossier) { create(:dossier, :with_user, :with_procedure) } let(:bad_dossier_id) { Dossier.count + 100000 } before do @@ -55,6 +55,15 @@ describe Users::RecapitulatifController, type: :controller do it 'a message informe user what his dossier is initiated' do expect(flash[:notice]).to include('Dossier déposé avec succès.') end + + it 'Notification email is send' do + expect(NotificationMailer).to receive(:dossier_submitted).and_return(NotificationMailer) + expect(NotificationMailer).to receive(:deliver_now!) + + dossier.validated! + post :submit, dossier_id: dossier.id + end + end end From ace1629d5c034bc003a4e3ab72816b83d8dc7603 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 17 Dec 2015 10:41:00 +0100 Subject: [PATCH 04/11] Uploader storage change : - Before /public/upload - After /upload --- app/uploaders/cerfa_uploader.rb | 2 +- app/uploaders/piece_justificative_uploader.rb | 2 +- app/uploaders/procedure_logo_uploader.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/uploaders/cerfa_uploader.rb b/app/uploaders/cerfa_uploader.rb index 9222caafa..2755da6bd 100644 --- a/app/uploaders/cerfa_uploader.rb +++ b/app/uploaders/cerfa_uploader.rb @@ -13,7 +13,7 @@ class CerfaUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + "../uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # Provide a default URL as a default if there hasn't been a file uploaded: diff --git a/app/uploaders/piece_justificative_uploader.rb b/app/uploaders/piece_justificative_uploader.rb index ee38e3e40..1f3d8c317 100644 --- a/app/uploaders/piece_justificative_uploader.rb +++ b/app/uploaders/piece_justificative_uploader.rb @@ -13,7 +13,7 @@ class PieceJustificativeUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + "../uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # Provide a default URL as a default if there hasn't been a file uploaded: diff --git a/app/uploaders/procedure_logo_uploader.rb b/app/uploaders/procedure_logo_uploader.rb index 70787d524..4ba185059 100644 --- a/app/uploaders/procedure_logo_uploader.rb +++ b/app/uploaders/procedure_logo_uploader.rb @@ -13,7 +13,7 @@ class ProcedureLogoUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + "../uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # Provide a default URL as a default if there hasn't been a file uploaded: From 563e73995833f08a53319435d99945ae07ba5b3a Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 17 Dec 2015 12:53:43 +0100 Subject: [PATCH 05/11] Minor fix bug --- app/views/dossiers/_show.html.haml | 2 +- spec/mailers/notification_mailer_spec.rb | 2 +- spec/views/dossiers/show.html.haml_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/dossiers/_show.html.haml b/app/views/dossiers/_show.html.haml index c04d248c7..bd855c59e 100644 --- a/app/views/dossiers/_show.html.haml +++ b/app/views/dossiers/_show.html.haml @@ -8,6 +8,6 @@ = form_for @dossier, url: { controller: '/users/dossiers', action: :update } do |f| %label{ style:'font-weight:normal' } = f.check_box :autorisation_donnees - J'autorise les organismes publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. + J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. %br = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante' \ No newline at end of file diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index deed3f916..187f351c2 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -18,7 +18,7 @@ RSpec.describe NotificationMailer, type: :mailer do subject(:subject) { described_class.dossier_validated(dossier) } - it { expect(subject.body).to match("Votre dossier N°#{dossier.id} a été validé par votre gestionnaire.") } + it { expect(subject.body).to match("Votre dossier N°#{dossier.id} a été validé par votre accompagnateur.") } it { expect(subject.body).to include("Afin de finaliser son dépot, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") } it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été validé") } end diff --git a/spec/views/dossiers/show.html.haml_spec.rb b/spec/views/dossiers/show.html.haml_spec.rb index dcc04627e..b29939c5d 100644 --- a/spec/views/dossiers/show.html.haml_spec.rb +++ b/spec/views/dossiers/show.html.haml_spec.rb @@ -25,7 +25,7 @@ describe 'dossiers/show.html.haml', type: :view do end it "le texte d'information des droits est correct" do - expect(rendered).to have_content("J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.") + expect(rendered).to have_content("J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles.") end it "les informations de l'entreprise sont présents" do From 229973f14cf747b18f201e35656d957c1ad4682f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 18 Dec 2015 12:01:26 +0100 Subject: [PATCH 06/11] Rename FranceConnect to FranceConnect::Entreprise --- .../entreprise_controller.rb} | 6 +++--- app/controllers/users/sessions_controller.rb | 4 +--- app/models/france_connect_client.rb | 17 ----------------- app/models/france_connect_entreprise_client.rb | 17 +++++++++++++++++ app/services/france_connect_service.rb | 4 ++-- config/routes.rb | 6 ++++-- ...er_spec.rb => entreprise_controller_spec.rb} | 6 +++--- .../users/sessions_controller_spec.rb | 2 +- .../france_connect/france_connect_spec.rb | 12 ++++++------ ...=> france_connect_entreprise_client_spec.rb} | 2 +- spec/services/france_connect_service_spec.rb | 12 ++++++------ 11 files changed, 44 insertions(+), 44 deletions(-) rename app/controllers/{france_connect_controller.rb => france_connect/entreprise_controller.rb} (86%) delete mode 100644 app/models/france_connect_client.rb create mode 100644 app/models/france_connect_entreprise_client.rb rename spec/controllers/{france_connect_controller_spec.rb => entreprise_controller_spec.rb} (89%) rename spec/models/{france_connect_client_spec.rb => france_connect_entreprise_client_spec.rb} (91%) diff --git a/app/controllers/france_connect_controller.rb b/app/controllers/france_connect/entreprise_controller.rb similarity index 86% rename from app/controllers/france_connect_controller.rb rename to app/controllers/france_connect/entreprise_controller.rb index 48ea640e6..760f5bae4 100644 --- a/app/controllers/france_connect_controller.rb +++ b/app/controllers/france_connect/entreprise_controller.rb @@ -1,6 +1,6 @@ -class FranceConnectController < ApplicationController +class FranceConnect::EntrepriseController < ApplicationController def login - client = FranceConnectClient.new + client = FranceConnectEntrepriseClient.new session[:state] = SecureRandom.hex(16) session[:nonce] = SecureRandom.hex(16) @@ -16,7 +16,7 @@ class FranceConnectController < ApplicationController def callback return redirect_to new_user_session_path unless params.has_key?(:code) - user_infos = FranceConnectService.retrieve_user_informations(params[:code]) + user_infos = FranceConnectService.retrieve_user_informations_entreprise(params[:code]) unless user_infos.nil? @user = User.find_for_france_connect(user_infos.email, user_infos.siret) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index b4f85b7fb..e09a7e61b 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -18,14 +18,12 @@ class Users::SessionsController < Sessions::SessionsController connected_with_france_connect = current_user.loged_in_with_france_connect current_user.update_attributes(loged_in_with_france_connect: false) - signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) set_flash_message :notice, :signed_out if signed_out && is_flashing_format? yield if block_given? - if connected_with_france_connect - redirect_to FRANCE_CONNECT.logout_endpoint + redirect_to FRANCE_CONNECT.entreprise_logout_endpoint else respond_to_on_destroy end diff --git a/app/models/france_connect_client.rb b/app/models/france_connect_client.rb deleted file mode 100644 index 274db2f9c..000000000 --- a/app/models/france_connect_client.rb +++ /dev/null @@ -1,17 +0,0 @@ -class FranceConnectClient < OpenIDConnect::Client - - def initialize params={} - super( - identifier: FRANCE_CONNECT.identifier, - secret: FRANCE_CONNECT.secret, - - redirect_uri: FRANCE_CONNECT.redirect_uri, - - authorization_endpoint: FRANCE_CONNECT.authorization_endpoint, - token_endpoint: FRANCE_CONNECT.token_endpoint, - userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint, - logout_endpoint: FRANCE_CONNECT.logout_endpoint - ) - self.authorization_code = params[:code] if params.has_key? :code - end -end diff --git a/app/models/france_connect_entreprise_client.rb b/app/models/france_connect_entreprise_client.rb new file mode 100644 index 000000000..5d8f218a2 --- /dev/null +++ b/app/models/france_connect_entreprise_client.rb @@ -0,0 +1,17 @@ +class FranceConnectEntrepriseClient < OpenIDConnect::Client + + def initialize params={} + super( + identifier: FRANCE_CONNECT.identifier, + secret: FRANCE_CONNECT.secret, + + redirect_uri: FRANCE_CONNECT.entreprise_redirect_uri, + + authorization_endpoint: FRANCE_CONNECT.entreprise_authorization_endpoint, + token_endpoint: FRANCE_CONNECT.entreprise_token_endpoint, + userinfo_endpoint: FRANCE_CONNECT.entreprise_userinfo_endpoint, + logout_endpoint: FRANCE_CONNECT.entreprise_logout_endpoint + ) + self.authorization_code = params[:code] if params.has_key? :code + end +end diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index 167525bcf..93ae87eb0 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -1,6 +1,6 @@ class FranceConnectService - def self.retrieve_user_informations code - client = FranceConnectClient.new code: code + def self.retrieve_user_informations_entreprise code + client = FranceConnectEntrepriseClient.new code: code access_token = client.access_token!(client_auth_method: :secret) user_info = access_token.userinfo! diff --git a/config/routes.rb b/config/routes.rb index cc6085089..2f0b69329 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,8 +15,10 @@ Rails.application.routes.draw do root 'root#index' - get 'france_connect' => 'france_connect#login' - get 'france_connect/callback' => 'france_connect#callback' + namespace :france_connect do + get 'entreprise' => 'entreprise#login' + get 'entreprise/callback' => 'entreprise#callback' + end get 'demo' => 'demo#index' diff --git a/spec/controllers/france_connect_controller_spec.rb b/spec/controllers/entreprise_controller_spec.rb similarity index 89% rename from spec/controllers/france_connect_controller_spec.rb rename to spec/controllers/entreprise_controller_spec.rb index 84f9a0866..ba664fb1f 100644 --- a/spec/controllers/france_connect_controller_spec.rb +++ b/spec/controllers/entreprise_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe FranceConnectController, type: :controller do +describe FranceConnect::EntrepriseController, type: :controller do describe '.login' do it 'redirect to france connect serveur' do @@ -26,7 +26,7 @@ describe FranceConnectController, type: :controller do let(:current_user) { User.find_by_email(email) } before do - allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_info) + allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_info) get :callback, code: code end @@ -43,7 +43,7 @@ describe FranceConnectController, type: :controller do context 'when code is not correct' do before do - allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } + allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } get :callback, code: code end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index c4bcdaac3..11f138f2f 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -40,7 +40,7 @@ describe Users::SessionsController, type: :controller do context 'when user is connect with france connect' do it 'redirect to france connect logout page' do - expect(response).to redirect_to(FRANCE_CONNECT.logout_endpoint) + expect(response).to redirect_to(FRANCE_CONNECT.entreprise_logout_endpoint) end end diff --git a/spec/features/france_connect/france_connect_spec.rb b/spec/features/france_connect/france_connect_spec.rb index 148732178..8b9cfb1b9 100644 --- a/spec/features/france_connect/france_connect_spec.rb +++ b/spec/features/france_connect/france_connect_spec.rb @@ -16,8 +16,8 @@ feature 'France Connect Connexion' do # # context 'when authentification is ok' do # before do - # allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) - # allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com')) + # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) + # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(Hashie::Mash.new(email: 'patator@cake.com')) # page.find_by_id('btn_fc').click # end # @@ -28,8 +28,8 @@ feature 'France Connect Connexion' do # # context 'when authentification is not ok' do # before do - # allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) - # allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } + # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) + # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } # page.find_by_id('btn_fc').click # end # @@ -55,8 +55,8 @@ feature 'France Connect Connexion' do # let(:siret) { '00000000000000' } # let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) } # before do - # allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) - # allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_infos) + # allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) + # allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_infos) # page.find_by_id('btn_fc').click # end # context 'when starting page is dossiers list' do diff --git a/spec/models/france_connect_client_spec.rb b/spec/models/france_connect_entreprise_client_spec.rb similarity index 91% rename from spec/models/france_connect_client_spec.rb rename to spec/models/france_connect_entreprise_client_spec.rb index 174151ff5..2f1385747 100644 --- a/spec/models/france_connect_client_spec.rb +++ b/spec/models/france_connect_entreprise_client_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe FranceConnectClient do +describe FranceConnectEntrepriseClient do describe '.initialize' do it 'create an openid client' do expect(described_class).to be < OpenIDConnect::Client diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb index 25753fa96..3e962eb8d 100644 --- a/spec/services/france_connect_service_spec.rb +++ b/spec/services/france_connect_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe FranceConnectService do - describe '.retrieve_user_informations' do + describe '.retrieve_user_informations_entreprise' do let(:code) { 'plop' } let(:access_token) { 'my access_token' } @@ -10,15 +10,15 @@ describe FranceConnectService do let(:user_info_hash) { {'email' => email, 'siret' => siret} } let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash, email: email) } - subject { described_class.retrieve_user_informations code } + subject { described_class.retrieve_user_informations_entreprise code } before do - allow_any_instance_of(FranceConnectClient).to receive(:access_token!).and_return(access_token) + allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:access_token!).and_return(access_token) allow(access_token).to receive(:userinfo!).and_return(user_info) end - it 'set code for FranceConnectClient' do - expect_any_instance_of(FranceConnectClient).to receive(:authorization_code=).with(code) - described_class.retrieve_user_informations code + it 'set code for FranceConnectEntrepriseClient' do + expect_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_code=).with(code) + described_class.retrieve_user_informations_entreprise code end it 'returns user informations in a object' do From 506ce2dee4fb2b7d20e078498a397203db4807ca Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 21 Dec 2015 10:45:50 +0100 Subject: [PATCH 07/11] add parallels tests --- Gemfile | 4 ++++ Gemfile.lock | 7 +++++++ config/database.yml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2a1f1429c..a2f38d2b1 100644 --- a/Gemfile +++ b/Gemfile @@ -103,6 +103,10 @@ group :development, :test do gem 'rubocop-checkstyle_formatter', require: false gem 'rubocop-rspec', require: false + gem "nyan-cat-formatter" + + gem 'parallel_tests' + # Deploy gem 'mina', git: 'https://github.com/mina-deploy/mina.git' end diff --git a/Gemfile.lock b/Gemfile.lock index abfada111..26d45e769 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,6 +211,8 @@ GEM notiffany (0.0.8) nenv (~> 0.1) shellany (~> 0.0) + nyan-cat-formatter (0.11) + rspec (>= 2.99, >= 2.14.2, < 4) open4 (1.3.4) openid_connect (0.9.2) activemodel @@ -224,6 +226,9 @@ GEM validate_url webfinger (>= 1.0.1) orm_adapter (0.5.0) + parallel (1.6.1) + parallel_tests (1.9.0) + parallel parser (2.2.2.2) ast (>= 1.1, < 3.0) pg (0.18.2) @@ -452,7 +457,9 @@ DEPENDENCIES logstasher mailjet mina! + nyan-cat-formatter openid_connect + parallel_tests pg poltergeist pry-byebug diff --git a/config/database.yml b/config/database.yml index f37a296b5..2dd44b635 100644 --- a/config/database.yml +++ b/config/database.yml @@ -12,7 +12,7 @@ development: test: adapter: postgresql encoding: unicode - database: tps_test + database: tps_test<%= ENV['TEST_ENV_NUMBER'] %> host: localhost pool: 5 username: tps From 5d4a36e6c3d89919221694dcc385c03ec223cce2 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 21 Dec 2015 10:50:01 +0100 Subject: [PATCH 08/11] Move uploader logo procedure into public --- app/uploaders/procedure_logo_uploader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/uploaders/procedure_logo_uploader.rb b/app/uploaders/procedure_logo_uploader.rb index 4ba185059..70787d524 100644 --- a/app/uploaders/procedure_logo_uploader.rb +++ b/app/uploaders/procedure_logo_uploader.rb @@ -13,7 +13,7 @@ class ProcedureLogoUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - "../uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # Provide a default URL as a default if there hasn't been a file uploaded: From 43779aafeefc0cffaa11cee610289564191c6a8c Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 21 Dec 2015 12:02:53 +0100 Subject: [PATCH 09/11] Error 403 when admin would edit a procedure with at least one dossier --- .../admin/pieces_justificatives_controller.rb | 7 --- .../admin/procedures_controller.rb | 2 + .../admin/types_de_champ_controller.rb | 9 ---- app/controllers/admin_controller.rb | 13 ++++++ .../administrateurs/_login_banner.html.haml | 2 +- .../pieces_justificatives_controller_spec.rb | 8 ++++ .../admin/procedures_controller_spec.rb | 7 ++- .../admin/types_de_champ_controller_spec.rb | 43 ++++++++++++++----- spec/features/admin/add_type_de_champ_spec.rb | 2 +- .../admin/move_down_type_de_champ_spec.rb | 2 +- .../admin/move_up_type_de_champ_spec.rb | 2 +- 11 files changed, 65 insertions(+), 32 deletions(-) diff --git a/app/controllers/admin/pieces_justificatives_controller.rb b/app/controllers/admin/pieces_justificatives_controller.rb index 1348a5c57..193cc6657 100644 --- a/app/controllers/admin/pieces_justificatives_controller.rb +++ b/app/controllers/admin/pieces_justificatives_controller.rb @@ -23,11 +23,4 @@ class Admin::PiecesJustificativesController < AdminController .require(:procedure) .permit(types_de_piece_justificative_attributes: [:libelle, :description, :id]) end - - - def retrieve_procedure - @procedure = current_administrateur.procedures.find(params[:procedure_id]) - rescue ActiveRecord::RecordNotFound - render json: { message: 'Procedure not found' }, status: 404 - end end \ No newline at end of file diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 06546f8b6..91c5cd4ee 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -1,5 +1,7 @@ class Admin::ProceduresController < AdminController + before_action :retrieve_procedure, only: :edit + def index @procedures = current_administrateur.procedures.where(archived: false) .paginate(:page => params[:page]).decorate diff --git a/app/controllers/admin/types_de_champ_controller.rb b/app/controllers/admin/types_de_champ_controller.rb index 005b41271..85daf3666 100644 --- a/app/controllers/admin/types_de_champ_controller.rb +++ b/app/controllers/admin/types_de_champ_controller.rb @@ -1,5 +1,4 @@ class Admin::TypesDeChampController < AdminController - before_action :retrieve_procedure def destroy @@ -38,12 +37,4 @@ class Admin::TypesDeChampController < AdminController render json: {}, status: 400 end end - - private - - def retrieve_procedure - @procedure = Procedure.find(params[:procedure_id]) - rescue ActiveRecord::RecordNotFound - render json: { message: 'Procedure not found' }, status: 404 - end end \ No newline at end of file diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 4a32b6f6f..69a5ec030 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -4,4 +4,17 @@ class AdminController < ApplicationController def index redirect_to (admin_procedures_path) end + + def retrieve_procedure + id = params[:procedure_id] || params[:id ] + + @procedure = current_administrateur.procedures.find(id) + + unless @procedure.dossiers.count == 0 + render json: {message: 'Procedure locked'}, status: 403 + end + + rescue ActiveRecord::RecordNotFound + render json: {message: 'Procedure not found'}, status: 404 + end end diff --git a/app/views/administrateurs/_login_banner.html.haml b/app/views/administrateurs/_login_banner.html.haml index b1606452a..0115dccd2 100644 --- a/app/views/administrateurs/_login_banner.html.haml +++ b/app/views/administrateurs/_login_banner.html.haml @@ -1,6 +1,6 @@ %div{ style: "decorate:none; display: flex;box-shadow:none; float:right; display: flex" } %div{ style: "vertical-align: middle; margin-right: 10px; margin-top: auto; margin-bottom: auto;" } - mps-test@apientreprise.fr + = current_administrateur.email .dropdown#admin_menu %button.btn.btn-default.dropdown-toggle#dropdownMenuAdmin{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false} %i.fa.fa-cog diff --git a/spec/controllers/admin/pieces_justificatives_controller_spec.rb b/spec/controllers/admin/pieces_justificatives_controller_spec.rb index 773145e10..382d4208c 100644 --- a/spec/controllers/admin/pieces_justificatives_controller_spec.rb +++ b/spec/controllers/admin/pieces_justificatives_controller_spec.rb @@ -9,11 +9,19 @@ describe Admin::PiecesJustificativesController, type: :controller do describe 'GET #show' do let(:procedure) { create(:procedure, administrateur: admin) } let(:procedure_id) { procedure.id } + subject { get :show, procedure_id: procedure_id } + context 'when procedure is not found' do let(:procedure_id) { 9_999_999 } it { expect(subject.status).to eq(404) } end + + context 'when procedure have at least a file' do + let!(:dossier) { create(:dossier, :with_user, procedure: procedure) } + it { expect(subject.status).to eq(403) } + end + context 'when procedure does not belong to admin' do let(:admin_2) { create(:administrateur) } let(:procedure) { create(:procedure, administrateur: admin_2) } diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index a0ad3ad93..9495a30ff 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -66,10 +66,15 @@ describe Admin::ProceduresController, type: :controller do it { expect(subject).to have_http_status(:success) } end + context 'when procedure have at least a file' do + let!(:dossier) { create(:dossier, :with_user, procedure: procedure) } + it { expect(subject.status).to eq(403) } + end + context "when procedure doesn't exist" do let(:procedure_id) { bad_procedure_id } - it { expect(subject).to redirect_to admin_procedures_path } + it { expect(subject).to have_http_status(404) } end end end diff --git a/spec/controllers/admin/types_de_champ_controller_spec.rb b/spec/controllers/admin/types_de_champ_controller_spec.rb index 8ff562e91..e35a46ced 100644 --- a/spec/controllers/admin/types_de_champ_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_controller_spec.rb @@ -2,12 +2,36 @@ require 'spec_helper' describe Admin::TypesDeChampController, type: :controller do let(:admin) { create(:administrateur) } + let(:procedure) { create(:procedure, administrateur: admin) } + before do sign_in admin end + describe 'GET #show' do + let(:procedure) { create(:procedure, administrateur: admin) } + let(:procedure_id) { procedure.id } + + subject { get :show, procedure_id: procedure_id } + + context 'when procedure is not found' do + let(:procedure_id) { 9_999_999 } + it { expect(subject.status).to eq(404) } + end + + context 'when procedure have at least a file' do + let!(:dossier) { create(:dossier, :with_user, procedure: procedure) } + it { expect(subject.status).to eq(403) } + end + + context 'when procedure does not belong to admin' do + let(:admin_2) { create(:administrateur) } + let(:procedure) { create(:procedure, administrateur: admin_2) } + it { expect(subject.status).to eq(404) } + end + end + describe '#update' do - let(:procedure) { create(:procedure) } let(:libelle) { 'mon libelle' } let(:type_champ) { 'text' } let(:description) { 'titi' } @@ -47,7 +71,7 @@ describe Admin::TypesDeChampController, type: :controller do end context 'when type_de_champ already exist' do - let(:procedure) { create(:procedure, :with_type_de_champ) } + let(:procedure) { create(:procedure, :with_type_de_champ, administrateur: admin) } let(:type_de_champ) { procedure.types_de_champ.first } let(:types_de_champ_id) { type_de_champ.id } let(:libelle) { 'toto' } @@ -77,13 +101,13 @@ describe Admin::TypesDeChampController, type: :controller do before do delete :destroy, procedure_id: procedure.id, id: type_de_champ_id, format: :js end + context 'when type de champs does not exist' do let(:type_de_champ_id) { 99999999 } - let(:procedure) { create(:procedure) } it { expect(subject.status).to eq(404) } end context 'when types_de_champ exists' do - let(:procedure) { create(:procedure, :with_type_de_champ) } + let(:procedure) { create(:procedure, :with_type_de_champ, administrateur: admin) } let(:type_de_champ_id) { procedure.types_de_champ.first.id } it { expect(subject.status).to eq(200) } it 'destroy type de champ' do @@ -92,7 +116,6 @@ describe Admin::TypesDeChampController, type: :controller do end end context 'when procedure and type de champs are not linked' do - let(:procedure) { create(:procedure) } let(:type_de_champ) { create(:type_de_champ) } let(:type_de_champ_id) { type_de_champ.id } it { expect(subject.status).to eq(404) } @@ -101,28 +124,25 @@ describe Admin::TypesDeChampController, type: :controller do describe 'POST #move_up' do subject { post :move_up, procedure_id: procedure.id, index: index, format: :js } + context 'when procedure have no type de champ' do let(:index) { 0 } - let(:procedure) { create(:procedure) } it { expect(subject.status).to eq(400) } end context 'when procedure have only one type de champ' do let(:index) { 1 } - let(:procedure) { create(:procedure) } let!(:type_de_champ) { create(:type_de_champ, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when procedure have tow type de champs' do context 'when index == 0' do let(:index) { 0 } - let(:procedure) { create(:procedure) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure) } let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure) } it { expect(subject.status).to eq(400) } end context 'when index > 0' do let(:index) { 1 } - let(:procedure) { create(:procedure) } let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } @@ -141,9 +161,10 @@ describe Admin::TypesDeChampController, type: :controller do describe 'POST #move_down' do let(:request) { post :move_down, procedure_id: procedure.id, index: index, format: :js } - subject { request } let(:index) { 0 } - let(:procedure) { create(:procedure) } + + subject { request } + context 'when procedure have no type de champ' do it { expect(subject.status).to eq(400) } end diff --git a/spec/features/admin/add_type_de_champ_spec.rb b/spec/features/admin/add_type_de_champ_spec.rb index 52011a3b7..2540a2fcf 100644 --- a/spec/features/admin/add_type_de_champ_spec.rb +++ b/spec/features/admin/add_type_de_champ_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' feature 'add a new type de champs', js: true do let(:administrateur) { create(:administrateur) } - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, administrateur: administrateur) } before do login_as administrateur, scope: :administrateur diff --git a/spec/features/admin/move_down_type_de_champ_spec.rb b/spec/features/admin/move_down_type_de_champ_spec.rb index 5f8b31fed..84f291caf 100644 --- a/spec/features/admin/move_down_type_de_champ_spec.rb +++ b/spec/features/admin/move_down_type_de_champ_spec.rb @@ -7,7 +7,7 @@ feature 'move down button type de champs', js: true do login_as administrateur, scope: :administrateur end - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, administrateur: administrateur) } let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } diff --git a/spec/features/admin/move_up_type_de_champ_spec.rb b/spec/features/admin/move_up_type_de_champ_spec.rb index 3718e4d6e..4f0679509 100644 --- a/spec/features/admin/move_up_type_de_champ_spec.rb +++ b/spec/features/admin/move_up_type_de_champ_spec.rb @@ -7,7 +7,7 @@ feature 'move up button type de champs', js: true do login_as administrateur, scope: :administrateur end - let(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure, administrateur: administrateur) } let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } From c20f9a87e9ace5a3958388ef2b273a4c08553225 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 21 Dec 2015 14:40:28 +0100 Subject: [PATCH 10/11] Front : Procedure can not be edited when at least one file with state other what draft is created by user --- app/controllers/admin_controller.rb | 2 +- app/models/procedure.rb | 4 + .../pieces_justificatives/show.html.haml | 12 +- app/views/admin/procedures/show.html.haml | 143 ++++++++++-------- .../pieces_justificatives_controller_spec.rb | 2 +- .../admin/procedures_controller_spec.rb | 2 +- .../admin/types_de_champ_controller_spec.rb | 2 +- spec/features/admin/procedure_locked_spec.rb | 58 +++++++ spec/models/procedure_spec.rb | 30 +++- 9 files changed, 179 insertions(+), 76 deletions(-) create mode 100644 spec/features/admin/procedure_locked_spec.rb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 69a5ec030..cddb113ea 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -10,7 +10,7 @@ class AdminController < ApplicationController @procedure = current_administrateur.procedures.find(id) - unless @procedure.dossiers.count == 0 + if @procedure.locked? render json: {message: 'Procedure locked'}, status: 403 end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index c9b824433..e56894024 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -27,4 +27,8 @@ class Procedure < ActiveRecord::Base types_de_champ_tmp[index_of_first_element + 1].update_attributes(order_place: index_of_first_element) true end + + def locked? + dossiers.where.not(state: :draft).count > 0 + end end diff --git a/app/views/admin/pieces_justificatives/show.html.haml b/app/views/admin/pieces_justificatives/show.html.haml index 1fd542442..079c6289d 100644 --- a/app/views/admin/pieces_justificatives/show.html.haml +++ b/app/views/admin/pieces_justificatives/show.html.haml @@ -3,10 +3,14 @@ %br %ul.nav.nav-tabs - %li= link_to('Informations', admin_procedure_path(@procedure)) - %li= link_to('Description', edit_admin_procedure_path(@procedure)) - %li= link_to('Champs', admin_procedure_types_de_champ_path(@procedure)) - %li.active= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) + %li + = link_to('Informations', admin_procedure_path(@procedure)) + %li + = link_to('Description', edit_admin_procedure_path(@procedure)) + %li + = link_to('Champs', admin_procedure_types_de_champ_path(@procedure)) + %li.active + = link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) #piece_justificative_form = render 'form' \ No newline at end of file diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index ca57f6258..f633f2392 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -1,78 +1,89 @@ -%h2.text-info - =@procedure.libelle -%br +#procedure_show + %h2.text-info + =@procedure.libelle + %br -%ul.nav.nav-tabs - %li.active - = link_to('Informations', admin_procedure_path(@procedure)) - %li - = link_to('Description', edit_admin_procedure_path(@procedure)) - %li - = link_to('Champs', admin_procedure_types_de_champ_path(@procedure)) - %li - = link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) - %li{style:'float:right'} - = form_tag admin_procedure_archive_path(procedure_id: @procedure.id, archive: !@procedure.archived?), method: :put do - %button#archive.btn.btn-nav.text-info{type: :button} - %i.fa.fa-eraser - - if @procedure.archived - = 'Réactiver' - - else - = 'Archiver' - #confirm - %button#valid.btn.btn-nav.text-success{type: :submit} - %i.fa.fa-check - Valider - %button#cancel.btn.btn-nav.text-danger{type: :button} - %i.fa.fa-remove - Annuler + %ul.nav.nav-tabs + %li.active + = link_to('Informations', admin_procedure_path(@procedure)) + + %li{ class: ('disabled' if @procedure.locked?) } + = link_to_unless(@procedure.locked?, 'Description', edit_admin_procedure_path(@procedure)) do + = link_to('Description', '#') + + %li{ class: ('disabled' if @procedure.locked?) } + = link_to_unless(@procedure.locked?, 'Champs', admin_procedure_types_de_champ_path(@procedure)) do + = link_to('Champs', '#') + + %li{ class: ('disabled' if @procedure.locked?) } + = link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do + = link_to('Pièces justificatives', '#') -%br -%div + %li{style:'float:right'} + = form_tag admin_procedure_archive_path(procedure_id: @procedure.id, archive: !@procedure.archived?), method: :put do + %button#archive.btn.btn-nav.text-info{type: :button} + %i.fa.fa-eraser + - if @procedure.archived + = 'Réactiver' + - else + = 'Archiver' + #confirm + %button#valid.btn.btn-nav.text-success{type: :submit} + %i.fa.fa-check + Valider + %button#cancel.btn.btn-nav.text-danger{type: :button} + %i.fa.fa-remove + Annuler - %h3 Lien procédure - %div{style:'margin-left:3%'} - = @procedure.lien + - if @procedure.locked? + #procedure_locked.center + %h5 + .label.label-info La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier -%br -%h3 Dossiers + %div + %h3 Lien procédure + %div{style:'margin-left:3%'} + = @procedure.lien -.row - .col-md-6.col-lg-6{style:'margin-left:3%'} - %h4 Total - %div - = @facade.dossiers_total + %br + %h3 Dossiers - %h4.text-danger Attente Accompagnateur - %div - = @facade.dossiers_waiting_gestionnaire_total + .row + .col-md-6.col-lg-6{style:'margin-left:3%'} + %h4 Total + %div + = @facade.dossiers_total - %h4.text-info Attente Utilisateur - %div - = @facade.dossiers_waiting_user_total + %h4.text-danger Attente Accompagnateur + %div + = @facade.dossiers_waiting_gestionnaire_total - %h4.text-success Terminé - %div - = @facade.dossiers_termine_total + %h4.text-info Attente Utilisateur + %div + = @facade.dossiers_waiting_user_total - %h4 Archivé + %h4.text-success Terminé + %div + = @facade.dossiers_termine_total - - unless @facade.dossiers_archived_total == 0 - %ul - - @facade.dossiers_archived_by_state_total.each do |dossier| - %li - = dossier.state_fr - \: - = dossier.total - - else - %p - 0 + %h4 Archivé - .col-md-5.col-lg-5 - %h4 Non archivés - = javascript_include_tag "https://code.highcharts.com/highcharts.js", "chartkick" - - if @facade.dossiers_for_pie_highchart.blank? - Aucune statistique pour le moment - -else - =pie_chart @facade.dossiers_for_pie_highchart \ No newline at end of file + - unless @facade.dossiers_archived_total == 0 + %ul + - @facade.dossiers_archived_by_state_total.each do |dossier| + %li + = dossier.state_fr + \: + = dossier.total + - else + %p + 0 + + .col-md-5.col-lg-5 + %h4 Non archivés + = javascript_include_tag "https://code.highcharts.com/highcharts.js", "chartkick" + - if @facade.dossiers_for_pie_highchart.blank? + Aucune statistique pour le moment + -else + =pie_chart @facade.dossiers_for_pie_highchart \ No newline at end of file diff --git a/spec/controllers/admin/pieces_justificatives_controller_spec.rb b/spec/controllers/admin/pieces_justificatives_controller_spec.rb index 382d4208c..d90860116 100644 --- a/spec/controllers/admin/pieces_justificatives_controller_spec.rb +++ b/spec/controllers/admin/pieces_justificatives_controller_spec.rb @@ -18,7 +18,7 @@ describe Admin::PiecesJustificativesController, type: :controller do end context 'when procedure have at least a file' do - let!(:dossier) { create(:dossier, :with_user, procedure: procedure) } + let!(:dossier) { create(:dossier, :with_user, procedure: procedure, state: :initiated) } it { expect(subject.status).to eq(403) } end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 9495a30ff..534f17b78 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -67,7 +67,7 @@ describe Admin::ProceduresController, type: :controller do end context 'when procedure have at least a file' do - let!(:dossier) { create(:dossier, :with_user, procedure: procedure) } + let!(:dossier) { create(:dossier, :with_user, procedure: procedure, state: :initiated) } it { expect(subject.status).to eq(403) } end diff --git a/spec/controllers/admin/types_de_champ_controller_spec.rb b/spec/controllers/admin/types_de_champ_controller_spec.rb index e35a46ced..9d660884c 100644 --- a/spec/controllers/admin/types_de_champ_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_controller_spec.rb @@ -20,7 +20,7 @@ describe Admin::TypesDeChampController, type: :controller do end context 'when procedure have at least a file' do - let!(:dossier) { create(:dossier, :with_user, procedure: procedure) } + let!(:dossier) { create(:dossier, :with_user, procedure: procedure, state: :initiated) } it { expect(subject.status).to eq(403) } end diff --git a/spec/features/admin/procedure_locked_spec.rb b/spec/features/admin/procedure_locked_spec.rb new file mode 100644 index 000000000..7f1e7de93 --- /dev/null +++ b/spec/features/admin/procedure_locked_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +feature 'procedure locked' do + + let(:administrateur) { create(:administrateur) } + let(:procedure) { create(:procedure, administrateur: administrateur) } + + before do + login_as administrateur, scope: :administrateur + visit admin_procedure_path(procedure) + end + + context 'when procedure have no file' do + scenario 'info label is not present' do + expect(page).not_to have_content('La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier') + end + end + context 'when procedure have at least a file' do + before do + create(:dossier, :with_user, procedure: procedure, state: :initiated) + visit admin_procedure_path(procedure) + end + + scenario 'info label is present' do + expect(page).to have_content('La procédure ne peut plus être modifiée car un usagé a déjà déposé un dossier') + end + + context 'when user click on Description tab' do + before do + page.click_on 'Description' + end + + scenario 'page doest not change' do + expect(page).to have_css('#procedure_show') + end + end + + context 'when user click on Champs tab' do + before do + page.click_on 'Champs' + end + + scenario 'page doest not change' do + expect(page).to have_css('#procedure_show') + end + end + + context 'when user click on Pieces Justificatiives tab' do + before do + page.click_on 'Pièces justificatives' + end + + scenario 'page doest not change' do + expect(page).to have_css('#procedure_show') + end + end + end +end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 506f3de36..c91f37524 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -51,7 +51,7 @@ describe Procedure do describe '#switch_types_de_champ' do let(:procedure) { create(:procedure) } let(:index) { 0 } - subject { procedure.switch_types_de_champ index} + subject { procedure.switch_types_de_champ index } context 'when procedure have no types_de_champ' do it { expect(subject).to eq(false) } @@ -74,5 +74,31 @@ describe Procedure do it { expect(subject).to eq(false) } end end - end + end + + describe 'locked?' do + let(:procedure) { create(:procedure) } + + subject { procedure.locked? } + + context 'when procedure does not have dossier' do + it { is_expected.to be_falsey } + end + + context 'when procedure have dossier with state draft' do + before do + create(:dossier, :with_user, procedure: procedure, state: :draft) + end + + it { is_expected.to be_falsey } + end + + context 'when procedure have dossier with state initiated' do + before do + create(:dossier, :with_user, procedure: procedure, state: :initiated) + end + + it { is_expected.to be_truthy } + end + end end From 12943241f46df1ed39016ee46fd09b94b7f8c6c3 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 21 Dec 2015 15:24:02 +0100 Subject: [PATCH 11/11] Change identifier and secret name for FranceConnect::Entreprise connection --- app/models/france_connect_entreprise_client.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/france_connect_entreprise_client.rb b/app/models/france_connect_entreprise_client.rb index 5d8f218a2..e2b1d7252 100644 --- a/app/models/france_connect_entreprise_client.rb +++ b/app/models/france_connect_entreprise_client.rb @@ -2,8 +2,8 @@ class FranceConnectEntrepriseClient < OpenIDConnect::Client def initialize params={} super( - identifier: FRANCE_CONNECT.identifier, - secret: FRANCE_CONNECT.secret, + identifier: FRANCE_CONNECT.entreprise_identifier, + secret: FRANCE_CONNECT.entreprise_secret, redirect_uri: FRANCE_CONNECT.entreprise_redirect_uri,