From d9f5603f0545b95600cea285aa15c3b11d2774f7 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 1 Mar 2017 09:51:55 +0100 Subject: [PATCH 01/10] Add state dates to dossier --- app/models/dossier.rb | 14 ++++ ...70228144909_add_state_dates_to_dossiers.rb | 7 ++ db/schema.rb | 5 +- spec/models/dossier_spec.rb | 65 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170228144909_add_state_dates_to_dossiers.rb diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 88acb1cee..3a366d8e6 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -38,6 +38,8 @@ class Dossier < ActiveRecord::Base delegate :types_de_champ, to: :procedure delegate :france_connect_information, to: :user + before_validation :update_state_dates, if: -> { state_changed? } + after_save :build_default_champs, if: Proc.new { procedure_id_changed? } after_save :build_default_individual, if: Proc.new { procedure.for_individual? } @@ -302,4 +304,16 @@ class Dossier < ActiveRecord::Base def invite_by_user? email (invites_user.pluck :email).include? email end + + private + + def update_state_dates + if initiated? && !self.initiated_at + self.initiated_at = DateTime.now + elsif received? && !self.received_at + self.received_at = DateTime.now + elsif TERMINE.include?(state) + self.processed_at = DateTime.now + end + end end diff --git a/db/migrate/20170228144909_add_state_dates_to_dossiers.rb b/db/migrate/20170228144909_add_state_dates_to_dossiers.rb new file mode 100644 index 000000000..b07f022ea --- /dev/null +++ b/db/migrate/20170228144909_add_state_dates_to_dossiers.rb @@ -0,0 +1,7 @@ +class AddStateDatesToDossiers < ActiveRecord::Migration[5.0] + def change + add_column :dossiers, :initiated_at, :datetime + add_column :dossiers, :received_at, :datetime + add_column :dossiers, :processed_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 7c4a70927..d1426d252 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170223170808) do +ActiveRecord::Schema.define(version: 20170228144909) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -127,6 +127,9 @@ ActiveRecord::Schema.define(version: 20170223170808) do t.boolean "archived", default: false t.boolean "mandataire_social", default: false t.datetime "deposit_datetime" + t.datetime "initiated_at" + t.datetime "received_at" + t.datetime "processed_at" t.index ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree t.index ["user_id"], name: "index_dossiers_on_user_id", using: :btree end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index ad9b4c19e..80656c2ff 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -881,6 +881,71 @@ describe Dossier do it { is_expected.to eq "#{gestionnaire.email} #{gestionnaire2.email}" } end + end + + describe '#update_state_dates' do + let(:state) { 'draft' } + let(:dossier) { create(:dossier, state: state) } + let(:now) { Time.now.beginning_of_day } + + before do + Timecop.freeze(now) + end + + context 'when dossier is initiated' do + before do + dossier.initiated! + dossier.reload + end + + it { expect(dossier.state).to eq('initiated') } + it { expect(dossier.initiated_at).to eq(now) } + + # it 'should not change initiated_at if it is already set' do + # dossier.initiated_at = 1.day.ago + # expect(dossier.initiated_at).to eq(1.day.ago) + # end + end + + context 'when dossier is received' do + let(:state) { 'initiated' } + + before do + dossier.received! + dossier.reload + end + + it { expect(dossier.state).to eq('received') } + it { expect(dossier.received_at).to eq(now) } + end + + shared_examples 'dossier is processed' do |new_state| + before do + dossier.update(state: new_state) + dossier.reload + end + + it { expect(dossier.state).to eq(new_state) } + it { expect(dossier.processed_at).to eq(now) } + end + + context 'when dossier is closed' do + let(:state) { 'received' } + + it_behaves_like 'dossier is processed', 'closed' + end + + context 'when dossier is refused' do + let(:state) { 'received' } + + it_behaves_like 'dossier is processed', 'refused' + end + + context 'when dossier is without_continuation' do + let(:state) { 'received' } + + it_behaves_like 'dossier is processed', 'without_continuation' + end end end From 210e0294e16b4e7726e4bc077c15df5c04e190a5 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 1 Mar 2017 11:13:48 +0100 Subject: [PATCH 02/10] Rewrite tests and logic --- spec/models/dossier_spec.rb | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 80656c2ff..d211e1542 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -886,10 +886,10 @@ describe Dossier do describe '#update_state_dates' do let(:state) { 'draft' } let(:dossier) { create(:dossier, state: state) } - let(:now) { Time.now.beginning_of_day } + let(:beginning_of_day) { Time.now.beginning_of_day } before do - Timecop.freeze(now) + Timecop.freeze(beginning_of_day) end context 'when dossier is initiated' do @@ -899,12 +899,15 @@ describe Dossier do end it { expect(dossier.state).to eq('initiated') } - it { expect(dossier.initiated_at).to eq(now) } + it { expect(dossier.initiated_at).to eq(beginning_of_day) } - # it 'should not change initiated_at if it is already set' do - # dossier.initiated_at = 1.day.ago - # expect(dossier.initiated_at).to eq(1.day.ago) - # end + it 'should keep first initiated_at date' do + Timecop.return + dossier.received! + dossier.initiated! + + expect(dossier.initiated_at).to eq(beginning_of_day) + end end context 'when dossier is received' do @@ -916,7 +919,15 @@ describe Dossier do end it { expect(dossier.state).to eq('received') } - it { expect(dossier.received_at).to eq(now) } + it { expect(dossier.received_at).to eq(beginning_of_day) } + + it 'should keep first received_at date if dossier is set to initiated again' do + Timecop.return + dossier.initiated! + dossier.received! + + expect(dossier.received_at).to eq(beginning_of_day) + end end shared_examples 'dossier is processed' do |new_state| @@ -926,7 +937,7 @@ describe Dossier do end it { expect(dossier.state).to eq(new_state) } - it { expect(dossier.processed_at).to eq(now) } + it { expect(dossier.processed_at).to eq(beginning_of_day) } end context 'when dossier is closed' do From 292ab74c450001ddd07b3332dba71dc49791a219 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 2 Mar 2017 12:41:40 +0100 Subject: [PATCH 03/10] Deposit datetime is renamed to initiated_at --- ...0170302112312_remove_deposit_datetime_from_dossiers.rb | 8 ++++++++ db/schema.rb | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb diff --git a/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb b/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb new file mode 100644 index 000000000..600beb4a3 --- /dev/null +++ b/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb @@ -0,0 +1,8 @@ +class RemoveDepositDatetimeFromDossiers < ActiveRecord::Migration[5.0] + def change + Dossier.where.not(deposit_datetime: nil).each do |dossier| + dossier.update(initiated_at: dossier.deposit_datetime) + end + remove_column :dossiers, :deposit_datetime, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index c9faf462b..f64bd3888 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170228150522) do +ActiveRecord::Schema.define(version: 20170302112312) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -126,7 +126,6 @@ ActiveRecord::Schema.define(version: 20170228150522) do t.text "json_latlngs" t.boolean "archived", default: false t.boolean "mandataire_social", default: false - t.datetime "deposit_datetime" t.datetime "initiated_at" t.datetime "received_at" t.datetime "processed_at" From 858c9a3bbac7eb81b0ae825228a19a8ddcf5977f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 2 Mar 2017 16:18:14 +0100 Subject: [PATCH 04/10] Export dates and add tests --- app/serializers/dossier_procedure_serializer.rb | 5 ++++- spec/models/dossier_spec.rb | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/serializers/dossier_procedure_serializer.rb b/app/serializers/dossier_procedure_serializer.rb index c0d694d59..02ebc4815 100644 --- a/app/serializers/dossier_procedure_serializer.rb +++ b/app/serializers/dossier_procedure_serializer.rb @@ -4,7 +4,10 @@ class DossierProcedureSerializer < ActiveModel::Serializer :updated_at, :archived, :mandataire_social, - :state + :state, + :initiated_at, + :received_at, + :processed_at attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index d211e1542..182b8c60b 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -597,7 +597,10 @@ describe Dossier do let(:procedure) { create(:procedure, :with_type_de_champ) } let(:gestionnaire) { create(:gestionnaire) } let(:follow) { create(:follow, gestionnaire: gestionnaire) } - let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, follows: [follow]) } + let(:date1) { 1.day.ago } + let(:date2) { 1.hour.ago } + let(:date3) { 1.minute.ago } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, follows: [follow], initiated_at: date1, received_at: date2, processed_at: date3) } describe '#export_headers' do @@ -608,6 +611,7 @@ describe Dossier do end describe '#data_with_champs' do + subject { dossier.data_with_champs } it { expect(subject[0]).to be_a_kind_of(Integer) } @@ -616,14 +620,17 @@ describe Dossier do it { expect(subject[3]).to be_in([true, false]) } it { expect(subject[4]).to be_in([true, false]) } it { expect(subject[5]).to eq("draft") } - it { expect(subject[6]).to eq(dossier.followers_gestionnaires_emails) } + it { expect(subject[6]).to eq(date1) } + it { expect(subject[7]).to eq(date2) } + it { expect(subject[8]).to eq(date3) } + it { expect(subject[9]).to eq(dossier.followers_gestionnaires_emails) } it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) } end end describe '#Dossier.to_csv' do let!(:procedure) { create(:procedure) } - let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, ) } subject do dossier_hash = {} From a24980145c7345631a5ad7338314b04fc07db627 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 6 Mar 2017 14:29:01 +0100 Subject: [PATCH 05/10] Block dossier initiation if procedure is archived --- .../users/description_controller.rb | 15 +++---- app/views/users/description/_show.html.haml | 21 +++++----- config/locales/fr.yml | 1 + config/routes.rb | 5 +-- .../description_controller_shared_example.rb | 40 ++++++++++++++----- .../users/description_controller_spec.rb | 22 +++++++++- 6 files changed, 72 insertions(+), 32 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 4dcd7f287..fb4bedda7 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -17,20 +17,21 @@ class Users::DescriptionController < UsersController acc end + if @procedure.archived? + flash[:alert] = t('errors.messages.procedure_archived') + end + rescue ActiveRecord::RecordNotFound flash.alert = t('errors.messages.dossier_not_found') redirect_to url_for(root_path) end - # def error - # show - # flash.now.alert = 'Un ou plusieurs attributs obligatoires sont manquants ou incorrects.' - # render 'show' - # end - - def create + def update @dossier = current_user_dossier @procedure = @dossier.procedure + + return head :forbidden if @procedure.archived? + @champs = @dossier.ordered_champs mandatory = true diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml index f216b3d7a..13bb982e9 100644 --- a/app/views/users/description/_show.html.haml +++ b/app/views/users/description/_show.html.haml @@ -15,7 +15,7 @@ = @dossier.procedure.libelle -#TODO use form_for - = form_tag(url_for({controller: 'users/description', action: :create, dossier_id: @dossier.id}), class: 'form', method: 'POST', multipart: true) do + = form_tag(url_for({controller: 'users/description', action: :update, dossier_id: @dossier.id}), class: 'form', method: 'POST', multipart: true) do -unless @champs.nil? #liste_champs =render partial: 'users/description/champs', locals:{private: false} @@ -41,16 +41,17 @@ Vous pourrez dans tous les cas les compléter plus tard si vous ne les possédez pas de suite. - -route = Rails.application.routes.recognize_path(request.referrer) + -route = Rails.application.routes.recognize_path(request.referrer) # WTF ? - unless route[:controller].match('admin') %div{style: 'text-align:right'} %h6 Tous les champs portant un * sont obligatoires. - -if !@dossier.draft? - =render partial: '/layouts/modifications_terminees' - -else - = submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true} - = submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: %w(btn btn-xs btn-default), style: 'float:right; margin-right: 10px; margin-top: 6px', data: {disable_with: 'Enregistrer un brouillon', submit: true} - - %br - %br + - if @procedure.archived? + .alert.alert-danger + = t('errors.messages.procedure_archived') + - else + - if !@dossier.draft? + = render partial: '/layouts/modifications_terminees' + - else + = submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float:right', disabled: @procedure.archived?, data: { disable_with: 'Soumettre votre dossier', submit: true} + = submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float:right; margin-right: 10px; margin-top: 6px', disabled: @procedure.archived?, data: {disable_with: 'Enregistrer un brouillon', submit: true} diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 795c51d50..5f8a4ad9e 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -147,6 +147,7 @@ fr: france_connect: connexion: "Erreur lors de la connexion à France Connect." extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide." + procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier." datetime: distance_in_words: diff --git a/config/routes.rb b/config/routes.rb index 9735cadae..2f96e0031 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -63,9 +63,8 @@ Rails.application.routes.draw do resources :dossiers do get '/add_siret' => 'dossiers/add_siret#show' - get '/description' => 'description#show' - # get '/description/error' => 'description#error' - post 'description' => 'description#create' + get 'description' => 'description#show' + post 'description' => 'description#update' patch 'pieces_justificatives' => 'description#pieces_justificatives' diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index fa90d0824..89ebfa094 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -17,12 +17,20 @@ shared_examples 'description_controller_spec' do context 'when all is ok' do before do dossier.entreprise = create :entreprise + get :show, params: {dossier_id: dossier_id} end it 'returns http success' do - get :show, params: {dossier_id: dossier_id} expect(response).to have_http_status(:success) end + + context 'but procedure is archived' do + let(:archived) { true } + render_views + + it { expect(response).to have_http_status(:success) } + it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) } + end end it 'redirection vers start si mauvais dossier ID' do @@ -90,7 +98,7 @@ shared_examples 'description_controller_spec' do end end - describe 'POST #create' do + describe 'POST #update' do let(:timestamp) { Time.now } let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' } @@ -98,7 +106,7 @@ shared_examples 'description_controller_spec' do describe 'Premier enregistrement des données' do let(:submit) { {nouveaux: 'nouveaux'} } - subject { post :create, params: {dossier_id: dossier_id, submit: submit} } + subject { post :update, params: {dossier_id: dossier_id, submit: submit} } before do dossier.draft! @@ -130,7 +138,7 @@ shared_examples 'description_controller_spec' do context 'En train de manipuler un dossier non brouillon' do before do dossier.initiated! - post :create, params: {dossier_id: dossier_id} + post :update, params: {dossier_id: dossier_id} dossier.reload end @@ -145,7 +153,7 @@ shared_examples 'description_controller_spec' do end context 'Quand la procédure accepte les CERFA' do - subject { post :create, params: {dossier_id: dossier_id, + subject { post :update, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf} } it 'Notification interne is create' do @@ -154,7 +162,7 @@ shared_examples 'description_controller_spec' do context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do before do - post :create, params: {dossier_id: dossier_id, + post :update, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf} dossier.reload end @@ -181,7 +189,7 @@ shared_examples 'description_controller_spec' do let(:cerfas) { Cerfa.where(dossier_id: dossier_id) } before do - post :create, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf} + post :update, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf} end it "il y a deux CERFA PDF pour ce dossier" do @@ -195,7 +203,7 @@ shared_examples 'description_controller_spec' do context 'Sauvegarde du CERFA PDF' do let!(:procedure) { create(:procedure) } before do - post :create, params: {dossier_id: dossier_id, + post :update, params: {dossier_id: dossier_id, cerfa_pdf: cerfa_pdf} dossier.reload end @@ -214,7 +222,7 @@ shared_examples 'description_controller_spec' do let(:dossier_minute_value) { '00' } before do - post :create, params: {dossier_id: dossier_id, + post :update, params: {dossier_id: dossier_id, champs: { "'#{dossier.champs.first.id}'" => dossier_champs_first, "'#{dossier.champs.second.id}'" => dossier_date_value @@ -254,7 +262,7 @@ shared_examples 'description_controller_spec' do context 'Sauvegarde des pièces justificatives', vcr: {cassette_name: 'controllers_users_description_controller_sauvegarde_pj'} do let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } before do - post :create, params: {dossier_id: dossier_id, + post :update, params: {dossier_id: dossier_id, 'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0, 'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1} dossier.reload @@ -264,7 +272,7 @@ shared_examples 'description_controller_spec' do it 'ClamavService safe_file? is call' do expect(ClamavService).to receive(:safe_file?).twice - post :create, params: {dossier_id: dossier_id, + post :update, params: {dossier_id: dossier_id, 'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0, 'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1} end @@ -281,6 +289,16 @@ shared_examples 'description_controller_spec' do it { expect(subject.user).to eq user } end end + + context 'La procédure est archivée' do + let(:archived) { true } + + before do + post :update, params: { dossier_id: dossier.id } + end + + it { expect(response.status).to eq(403) } + end end describe 'POST #pieces_justificatives', vcr: {cassette_name: 'controllers_users_description_controller_pieces_justificatives'} do diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb index ace2b9f1b..fe5965eaf 100644 --- a/spec/controllers/users/description_controller_spec.rb +++ b/spec/controllers/users/description_controller_spec.rb @@ -5,8 +5,9 @@ require 'controllers/users/description_controller_shared_example' describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do let(:owner_user) { create(:user) } let(:invite_by_user) { create :user, email: 'invite@plop.com' } + let(:archived) { false } - let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true) } + let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, archived: archived) } let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') } let(:dossier_id) { dossier.id } @@ -42,4 +43,23 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: ' it_should_behave_like "description_controller_spec" end + # + # context 'POST #update' do + # let(:user) { owner_user } + # + # subject { post :update, params: { dossier_id: dossier.id } } + # + # before do + # subject + # end + # + # it { expect(response.status).to eq(302) } + # + # context 'when procedure is archived' do + # let(:archived) { true } + # + # it { expect(response.status).to eq(403) } + # end + # + # end end From 88654535ea99d7cd8a4815a33771274867dda3c9 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 6 Mar 2017 14:35:45 +0100 Subject: [PATCH 06/10] Remove comment --- .../users/description_controller_spec.rb | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb index fe5965eaf..9511f3d4a 100644 --- a/spec/controllers/users/description_controller_spec.rb +++ b/spec/controllers/users/description_controller_spec.rb @@ -43,23 +43,4 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: ' it_should_behave_like "description_controller_spec" end - # - # context 'POST #update' do - # let(:user) { owner_user } - # - # subject { post :update, params: { dossier_id: dossier.id } } - # - # before do - # subject - # end - # - # it { expect(response.status).to eq(302) } - # - # context 'when procedure is archived' do - # let(:archived) { true } - # - # it { expect(response.status).to eq(403) } - # end - # - # end end From 7e4f473027c47718afb86fe729803cea0bc5f36f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 6 Mar 2017 15:03:51 +0100 Subject: [PATCH 07/10] When procedure is archived user can update dossier if not in brouillon --- .../users/description_controller.rb | 4 ++-- app/models/dossier.rb | 4 ++++ app/views/users/description/_show.html.haml | 11 +++++----- .../description_controller_shared_example.rb | 21 +++++++++++++++---- .../users/description_controller_spec.rb | 3 ++- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index fb4bedda7..fa2d26f8d 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -17,7 +17,7 @@ class Users::DescriptionController < UsersController acc end - if @procedure.archived? + unless @dossier.can_be_initiated? flash[:alert] = t('errors.messages.procedure_archived') end @@ -30,7 +30,7 @@ class Users::DescriptionController < UsersController @dossier = current_user_dossier @procedure = @dossier.procedure - return head :forbidden if @procedure.archived? + return head :forbidden unless @dossier.can_be_initiated? @champs = @dossier.ordered_champs diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5877e87fd..8031da67b 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -304,4 +304,8 @@ class Dossier < ActiveRecord::Base def invite_by_user? email (invites_user.pluck :email).include? email end + + def can_be_initiated? + !(procedure.archived && draft?) + end end diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml index 13bb982e9..14b17b160 100644 --- a/app/views/users/description/_show.html.haml +++ b/app/views/users/description/_show.html.haml @@ -46,12 +46,11 @@ %div{style: 'text-align:right'} %h6 Tous les champs portant un * sont obligatoires. - - if @procedure.archived? + - if !@dossier.can_be_initiated? .alert.alert-danger = t('errors.messages.procedure_archived') + - elsif !@dossier.draft? + = render partial: '/layouts/modifications_terminees' - else - - if !@dossier.draft? - = render partial: '/layouts/modifications_terminees' - - else - = submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float:right', disabled: @procedure.archived?, data: { disable_with: 'Soumettre votre dossier', submit: true} - = submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float:right; margin-right: 10px; margin-top: 6px', disabled: @procedure.archived?, data: {disable_with: 'Enregistrer un brouillon', submit: true} + = submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: 'btn btn btn-success', style: 'float:right', disabled: @procedure.archived?, data: { disable_with: 'Soumettre votre dossier', submit: true} + = submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: 'btn btn-xs btn-default', style: 'float:right; margin-right: 10px; margin-top: 6px', disabled: @procedure.archived?, data: {disable_with: 'Enregistrer un brouillon', submit: true} diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index 89ebfa094..f74eb29b1 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -24,12 +24,19 @@ shared_examples 'description_controller_spec' do expect(response).to have_http_status(:success) end - context 'but procedure is archived' do - let(:archived) { true } + context 'procedure is archived' do render_views + let(:archived) { true } it { expect(response).to have_http_status(:success) } - it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) } + it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) } + + context 'dossier is a draft' do + let(:state) { 'draft' } + + it { expect(response).to have_http_status(:success) } + it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) } + end end end @@ -297,7 +304,13 @@ shared_examples 'description_controller_spec' do post :update, params: { dossier_id: dossier.id } end - it { expect(response.status).to eq(403) } + it { expect(response.status).to eq(302) } + + context 'Le dossier est en brouillon' do + let(:state) { 'draft' } + + it { expect(response.status).to eq(403) } + end end end diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb index 9511f3d4a..0cd1c0414 100644 --- a/spec/controllers/users/description_controller_spec.rb +++ b/spec/controllers/users/description_controller_spec.rb @@ -6,9 +6,10 @@ describe Users::DescriptionController, type: :controller, vcr: {cassette_name: ' let(:owner_user) { create(:user) } let(:invite_by_user) { create :user, email: 'invite@plop.com' } let(:archived) { false } + let(:state) { 'initiated' } let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, archived: archived) } - let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') } + let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) } let(:dossier_id) { dossier.id } let(:bad_dossier_id) { Dossier.count + 10000 } From 376c50db8fb5fa35109a82d4e082a12659f959dc Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 6 Mar 2017 16:18:22 +0100 Subject: [PATCH 08/10] Long procedure title should be cut if too long --- app/assets/stylesheets/navbar.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/navbar.scss b/app/assets/stylesheets/navbar.scss index bad10bfdb..bf35549e1 100644 --- a/app/assets/stylesheets/navbar.scss +++ b/app/assets/stylesheets/navbar.scss @@ -46,6 +46,7 @@ min-height: 58px; color: #000000; overflow: hidden; + white-space: nowrap; text-overflow: ellipsis; } .options { From a5bb6ea0d727bff5f6af7d17a6fab43553957825 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 6 Mar 2017 18:17:28 +0100 Subject: [PATCH 09/10] Dossier: fix merge --- app/models/dossier.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 46562be71..00afd691e 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -307,6 +307,9 @@ class Dossier < ActiveRecord::Base (invites_user.pluck :email).include? email end + def can_be_initiated? + !(procedure.archived && draft?) + end private @@ -320,7 +323,4 @@ class Dossier < ActiveRecord::Base end end - def can_be_initiated? - !(procedure.archived && draft?) - end end From a3348883634f05adf21a41eba8438ae075bd6711 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 6 Mar 2017 18:14:54 +0100 Subject: [PATCH 10/10] Wording --- app/facades/admin_procedures_show_facades.rb | 7 +++++-- app/views/backoffice/dossiers/index.html.haml | 12 +++++------- ...anel_backoffice_dossierscontroller_show.html.haml | 2 +- ...ft_panel_users_dossierscontroller_index.html.haml | 4 ++-- config/locales/models/dossier/fr.yml | 2 +- spec/decorators/dossier_decorator_spec.rb | 2 +- spec/facades/admin_procedures_show_facades_spec.rb | 2 +- spec/features/users/onglets_link_spec.rb | 4 ++-- ..._panel_backoffice_dossierscontroller_show_spec.rb | 12 ++++++------ ..._panel_users_recapitulatifcontroller_show_spec.rb | 2 +- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/app/facades/admin_procedures_show_facades.rb b/app/facades/admin_procedures_show_facades.rb index ae09fa37a..6b9c7f07a 100644 --- a/app/facades/admin_procedures_show_facades.rb +++ b/app/facades/admin_procedures_show_facades.rb @@ -13,8 +13,11 @@ class AdminProceduresShowFacades def dossiers_for_pie_highchart dossiers.where.not(state: :draft, archived: true).group(:state).count - .map{|key, value| { (DossierDecorator.case_state_fr key) => value } } - .reduce({}, :merge) + .reduce({}) do |acc, (key, val)| + translated_key = DossierDecorator.case_state_fr(key) + acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val + acc + end end def dossiers_archived_by_state_total diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index 8e80fbe6d..561c8df4b 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -15,15 +15,13 @@ = smart_listing_render :new_dossiers .row.center - .col-xs-2.col-xs-offset-1 + .col-xs-3 =link_to 'Tous les états', '?liste=all_state', class: 'text-info', style:"text-decoration: #{@facade_data_view.liste == 'all_state'? 'underline' : ''}" - .col-xs-2 + .col-xs-3 =link_to 'En construction', '?liste=a_traiter', class: 'text-danger', style:"text-decoration: #{@facade_data_view.liste == 'a_traiter'? 'underline' : ''}" - .col-xs-2 - =link_to 'À receptionner', '?liste=deposes', class: 'text-purple', style:"text-decoration: #{@facade_data_view.liste == 'deposes'? 'underline' : ''}" - .col-xs-2 - =link_to 'À instruire', '?liste=a_instruire', class: 'text-warning', style:"text-decoration: #{@facade_data_view.liste == 'a_instruire'? 'underline' : ''}" - .col-xs-2 + .col-xs-3 + =link_to 'En instruction', '?liste=a_instruire', class: 'text-warning', style:"text-decoration: #{@facade_data_view.liste == 'a_instruire'? 'underline' : ''}" + .col-xs-3 =link_to 'Terminés', '?liste=termine', class: 'text-success', style:"text-decoration: #{@facade_data_view.liste == 'termine'? 'underline' : ''}" .default_data_block.default_visible diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml index b7a0b9804..5868e5ae8 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml @@ -5,7 +5,7 @@ #action-block - if gestionnaire_signed_in? - if !@facade.dossier.read_only? || @facade.dossier.initiated? - = link_to 'Accuser réception', backoffice_dossier_receive_path(@facade.dossier), method: :post, class: 'btn btn-danger btn-block' + = link_to 'Passer en instruction', backoffice_dossier_receive_path(@facade.dossier), method: :post, class: 'btn btn-danger btn-block' - elsif @facade.dossier.received? = form_tag(url_for({controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id}), class: 'form-inline action_button', method: 'POST', style: 'display:inline', 'data-toggle' => :tooltip, title: 'Accepter') do diff --git a/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml index 643af12dc..a6f39fe6d 100644 --- a/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml @@ -25,13 +25,13 @@ %a{:href => "#{url_for users_dossiers_path(liste: 'en_instruction')}", 'data-toggle' => :tooltip, title: 'Les dossiers en cours d\'examen par l\'administration compétante.'} %div.procedure_list_element{ class: @dossiers_list_facade.en_instruction_class, id: 'en_instruction' } - ="En examen" + ="En instruction" .badge.progress-bar-default = @dossiers_list_facade.en_instruction_total %a{:href => "#{url_for users_dossiers_path(liste: 'termine')}", 'data-toggle' => :tooltip, title: 'Les dossiers cloturés qui peuvent être "Accepté", "Refusé" ou "Sans suite".'} %div.procedure_list_element{ class: @dossiers_list_facade.termine_class, id: 'termine' } - = "Cloturé" + = "Terminé" .badge.progress-bar-success = @dossiers_list_facade.termine_total diff --git a/config/locales/models/dossier/fr.yml b/config/locales/models/dossier/fr.yml index f7a8eb123..9b4b80766 100644 --- a/config/locales/models/dossier/fr.yml +++ b/config/locales/models/dossier/fr.yml @@ -9,7 +9,7 @@ fr: date_previsionnelle: "La date de début prévisionnelle" state: draft: "Brouillon" - initiated: "Nouveau" + initiated: "En construction" replied: "En construction" updated: "En construction" received: "En instruction" diff --git a/spec/decorators/dossier_decorator_spec.rb b/spec/decorators/dossier_decorator_spec.rb index 7746c397a..31a32b161 100644 --- a/spec/decorators/dossier_decorator_spec.rb +++ b/spec/decorators/dossier_decorator_spec.rb @@ -24,7 +24,7 @@ describe DossierDecorator do it 'initiated is initiate' do dossier.initiated! - expect(subject).to eq('Nouveau') + expect(subject).to eq('En construction') end it 'replied is repondu' do diff --git a/spec/facades/admin_procedures_show_facades_spec.rb b/spec/facades/admin_procedures_show_facades_spec.rb index 8988d3474..9352eecd6 100644 --- a/spec/facades/admin_procedures_show_facades_spec.rb +++ b/spec/facades/admin_procedures_show_facades_spec.rb @@ -26,7 +26,7 @@ describe AdminProceduresShowFacades do describe '.dossiers_for_pie_highchart' do subject { super().dossiers_for_pie_highchart } - it { expect(subject).to eq({'Nouveau' => 1, "En construction"=>1}) } + it { expect(subject).to eq({ 'En construction' => 3 }) } end describe '.dossiers_archived_by_state_total' do diff --git a/spec/features/users/onglets_link_spec.rb b/spec/features/users/onglets_link_spec.rb index 14a9d8fd3..7454df1e4 100644 --- a/spec/features/users/onglets_link_spec.rb +++ b/spec/features/users/onglets_link_spec.rb @@ -34,7 +34,7 @@ feature 'on click on tabs button' do context 'when he click on tabs en examen' do before do visit users_dossiers_url(liste: :en_instruction) - page.click_on 'En examen 1' + page.click_on 'En instruction 1' end scenario 'it redirect to users dossier termine' do @@ -45,7 +45,7 @@ feature 'on click on tabs button' do context 'when he click on tabs termine' do before do visit users_dossiers_url(liste: :termine) - page.click_on 'Cloturé 3' + page.click_on 'Terminé 3' end scenario 'it redirect to users dossier termine' do diff --git a/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb b/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb index 7871cfe42..fc7322a97 100644 --- a/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb +++ b/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb @@ -25,8 +25,8 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm context 'button dossier state changements' do - shared_examples 'button Accuser réception is present' do - it { expect(rendered).to have_link('Accuser réception') } + shared_examples 'button Passer en instruction is present' do + it { expect(rendered).to have_link('Passer en instruction') } end context 'when dossier have state initiated' do @@ -36,9 +36,9 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm render end - it { expect(rendered).to have_content('Nouveau') } + it { expect(rendered).to have_content('En construction') } - include_examples 'button Accuser réception is present' + include_examples 'button Passer en instruction is present' end context 'when dossier have state replied' do @@ -50,7 +50,7 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm it { expect(rendered).to have_content('En construction') } - include_examples 'button Accuser réception is present' + include_examples 'button Passer en instruction is present' end context 'when dossier have state update' do @@ -62,7 +62,7 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm it { expect(rendered).to have_content('En construction') } - include_examples 'button Accuser réception is present' + include_examples 'button Passer en instruction is present' end context 'when dossier have state received' do diff --git a/spec/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show_spec.rb b/spec/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show_spec.rb index 5f6dcb87b..d696534d3 100644 --- a/spec/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show_spec.rb +++ b/spec/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show_spec.rb @@ -17,7 +17,7 @@ describe 'layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.htm render end - it { expect(rendered).to have_content('Nouveau') } + it { expect(rendered).to have_content('En construction') } end context 'when dossier state is replied' do