From 1ecfc62bb5fd6adb72f5b427e995efba80a833b8 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 2 Nov 2016 10:18:59 +0100 Subject: [PATCH 1/5] Fix upload cache directory (opensimplif) --- app/uploaders/base_uploader.rb | 15 +++++++++++++++ app/uploaders/cerfa_uploader.rb | 10 +--------- app/uploaders/piece_justificative_uploader.rb | 14 +------------- app/uploaders/procedure_logo_uploader.rb | 10 +--------- 4 files changed, 18 insertions(+), 31 deletions(-) create mode 100644 app/uploaders/base_uploader.rb diff --git a/app/uploaders/base_uploader.rb b/app/uploaders/base_uploader.rb new file mode 100644 index 000000000..b575299d8 --- /dev/null +++ b/app/uploaders/base_uploader.rb @@ -0,0 +1,15 @@ +# encoding: utf-8 + +class BaseUploader < CarrierWave::Uploader::Base + def cache_dir + if Rails.env.production? + if Features.opensimplif? + '/tmp/opensimplif-cache' + else + '/tmp/tps-cache' + end + else + '/tmp/tps-dev-cache' + end + end +end \ No newline at end of file diff --git a/app/uploaders/cerfa_uploader.rb b/app/uploaders/cerfa_uploader.rb index 0b798ec81..c398801b8 100644 --- a/app/uploaders/cerfa_uploader.rb +++ b/app/uploaders/cerfa_uploader.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -class CerfaUploader < CarrierWave::Uploader::Base +class CerfaUploader < BaseUploader before :cache, :set_original_filename # Choose what kind of storage to use for this uploader: @@ -18,14 +18,6 @@ class CerfaUploader < CarrierWave::Uploader::Base end end - def cache_dir - if Rails.env.production? - '/tmp/tps-cache' - else - '/tmp/tps-dev-cache' - end - end - # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list diff --git a/app/uploaders/piece_justificative_uploader.rb b/app/uploaders/piece_justificative_uploader.rb index 868ca5bef..e5c93b34d 100644 --- a/app/uploaders/piece_justificative_uploader.rb +++ b/app/uploaders/piece_justificative_uploader.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -class PieceJustificativeUploader < CarrierWave::Uploader::Base +class PieceJustificativeUploader < BaseUploader before :cache, :set_original_filename # Choose what kind of storage to use for this uploader: @@ -18,18 +18,6 @@ class PieceJustificativeUploader < CarrierWave::Uploader::Base end end - def cache_dir - if Rails.env.production? - if Features.opensimplif? - '/tmp/opensimplif-cache' - else - '/tmp/tps-cache' - end - else - '/tmp/tps-dev-cache' - end - end - # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list diff --git a/app/uploaders/procedure_logo_uploader.rb b/app/uploaders/procedure_logo_uploader.rb index fd1366e0d..e5723f9a0 100644 --- a/app/uploaders/procedure_logo_uploader.rb +++ b/app/uploaders/procedure_logo_uploader.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -class ProcedureLogoUploader < CarrierWave::Uploader::Base +class ProcedureLogoUploader < BaseUploader def root File.join(Rails.root, "public") @@ -21,14 +21,6 @@ class ProcedureLogoUploader < CarrierWave::Uploader::Base end end - def cache_dir - if Rails.env.production? - '/tmp/tps-cache' - else - '/tmp/tps-dev-cache' - end - end - # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list From dd0e746997dddd6efddae6c573305ffaabbde923 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 2 Nov 2016 10:58:28 +0100 Subject: [PATCH 2/5] Add wording for bad token on reset password --- config/locales/fr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 9054844ae..afe725ff8 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -51,6 +51,8 @@ fr: size_too_big: "La taille du fichier joint est trop importante. Elle doit être inférieure à 3Mo." user: attributes: + reset_password_token: + invalid: ": Votre lien de nouveau mot de passe a expiré. Merci d'en demander un nouveau." email: invalid: invalide taken: déjà utilisé From 98fe908dafa64947594d624a30b1657beb988a8d Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 2 Nov 2016 11:07:33 +0100 Subject: [PATCH 3/5] Change status when user upload a new PJ --- app/controllers/users/description_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index cf9c159af..58e58e469 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -83,6 +83,7 @@ class Users::DescriptionController < UsersController flash.alert = errors_upload.html_safe else flash.notice = 'Nouveaux fichiers envoyés' + @dossier.next_step! 'user', 'update' end return redirect_to users_dossiers_invite_path(id: current_user.invites.find_by_dossier_id(@dossier.id).id) if invite From b03dd07d97734e1343414b586b1a471b35661613 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 2 Nov 2016 11:57:07 +0100 Subject: [PATCH 4/5] Add number validation with javascript, for number fields --- app/assets/javascripts/description.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/description.js b/app/assets/javascripts/description.js index d04e75a4b..cb66f0adf 100644 --- a/app/assets/javascripts/description.js +++ b/app/assets/javascripts/description.js @@ -7,6 +7,10 @@ function action_type_de_champs() { toggleErrorClass(this, validateEmail($(this).val())); }); + $("input[type='number']").on('change', function () { + toggleErrorClass(this, validateNumber($(this).val())); + }); + $("input[type='phone']").on('change', function () { val = $(this).val(); val = val.replace(/[ ]/g, ''); @@ -43,6 +47,11 @@ function validateEmail(email) { return validateInput(email, re) } +function validateNumber(number) { + var re = /^[0-9]+$/; + return validateInput(number, re) +} + function validateInput(input, regex) { return regex.test(input); } @@ -63,4 +72,4 @@ function toggle_header_section_composents() { } }); }); -} \ No newline at end of file +} From e596f71b078fb51542797d245e6f3a0a112e54f0 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 2 Nov 2016 16:33:01 +0100 Subject: [PATCH 5/5] Check if starter informations and autorisations_donnees is valid on description dossier page --- .../users/description_controller.rb | 20 ++++++- .../description_controller_shared_example.rb | 57 ++++++++++++++++++- .../upload_piece_justificative_spec.rb | 2 +- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 58e58e469..a8a08fc09 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -3,8 +3,11 @@ class Users::DescriptionController < UsersController authorized_routes? self.class end + before_action :check_autorisation_donnees, only: [:show] + before_action :check_starter_dossier_informations, only: [:show] + def show - @dossier = current_user_dossier.decorate + @dossier ||= current_user_dossier.decorate @procedure = @dossier.procedure @champs = @dossier.ordered_champs @@ -99,6 +102,21 @@ class Users::DescriptionController < UsersController private + def check_autorisation_donnees + @dossier ||= current_user_dossier + + redirect_to url_for(users_dossier_path(@dossier.id)) if @dossier.autorisation_donnees.nil? || !@dossier.autorisation_donnees + end + + def check_starter_dossier_informations + @dossier ||= current_user_dossier + + if (@dossier.procedure.for_individual? && @dossier.individual.nil?) || + (!@dossier.procedure.for_individual? && @dossier.entreprise.nil?) + redirect_to url_for(users_dossier_path(@dossier.id)) + end + end + def create_params params.permit() end diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index b50200332..22f170dbd 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -1,5 +1,8 @@ shared_examples 'description_controller_spec' do describe 'GET #show' do + before do + dossier.update_column :autorisation_donnees, true + end context 'user is not connected' do before do sign_out dossier.user @@ -11,9 +14,15 @@ shared_examples 'description_controller_spec' do end end - it 'returns http success' do - get :show, dossier_id: dossier_id - expect(response).to have_http_status(:success) + context 'when all is ok' do + before do + dossier.entreprise = create :entreprise + end + + it 'returns http success' do + get :show, dossier_id: dossier_id + expect(response).to have_http_status(:success) + end end it 'redirection vers start si mauvais dossier ID' do @@ -35,6 +44,48 @@ shared_examples 'description_controller_spec' do it { is_expected.to redirect_to root_path } end end + + describe 'before action check_autorisation_donnees' do + subject { get :show, dossier_id: dossier_id } + + context 'when dossier does not have a valid autorisations_donness (nil)' do + before do + dossier.update_column :autorisation_donnees, nil + end + + it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } + end + + context 'when dossier does not have a valid autorisations_donness (false)' do + before do + dossier.update_column :autorisation_donnees, false + end + + it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } + end + end + + describe 'before action check_starter_dossier_informations' do + subject { get :show, dossier_id: dossier_id } + + context 'when dossier does not have an enterprise datas' do + before do + + end + + it { expect(dossier.entreprise).to be_nil } + it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } + end + + context 'when dossier does not have an individual datas' do + before do + procedure.update_column :for_individual, true + end + + it { expect(dossier.individual).to be_nil } + it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } + end + end end describe 'POST #create' do diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb index 09f97734d..22bd5e50b 100644 --- a/spec/features/description_page/upload_piece_justificative_spec.rb +++ b/spec/features/description_page/upload_piece_justificative_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' feature 'user is on description page' do let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: true) } - let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) } + let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, autorisation_donnees: true) } before do allow(ClamavService).to receive(:safe_file?).and_return(true)