diff --git a/Gemfile.lock b/Gemfile.lock index 891384ef7..daaa6dcb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,25 +22,25 @@ GEM specs: aasm (5.0.1) concurrent-ruby (~> 1.0) - actioncable (5.2.1.1) - actionpack (= 5.2.1.1) + actioncable (5.2.2) + actionpack (= 5.2.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.1.1) - actionpack (= 5.2.1.1) - actionview (= 5.2.1.1) - activejob (= 5.2.1.1) + actionmailer (5.2.2) + actionpack (= 5.2.2) + actionview (= 5.2.2) + activejob (= 5.2.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.1.1) - actionview (= 5.2.1.1) - activesupport (= 5.2.1.1) + actionpack (5.2.2) + actionview (= 5.2.2) + activesupport (= 5.2.2) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.1.1) - activesupport (= 5.2.1.1) + actionview (5.2.2) + activesupport (= 5.2.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -53,24 +53,24 @@ GEM activemodel (>= 4.1, < 6) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (5.2.1.1) - activesupport (= 5.2.1.1) + activejob (5.2.2) + activesupport (= 5.2.2) globalid (>= 0.3.6) - activemodel (5.2.1.1) - activesupport (= 5.2.1.1) + activemodel (5.2.2) + activesupport (= 5.2.2) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (5.2.1.1) - activemodel (= 5.2.1.1) - activesupport (= 5.2.1.1) + activerecord (5.2.2) + activemodel (= 5.2.2) + activesupport (= 5.2.2) arel (>= 9.0) - activestorage (5.2.1.1) - actionpack (= 5.2.1.1) - activerecord (= 5.2.1.1) + activestorage (5.2.2) + actionpack (= 5.2.2) + activerecord (= 5.2.2) marcel (~> 0.3.1) - activesupport (5.2.1.1) + activesupport (5.2.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -436,18 +436,18 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.1.1) - actioncable (= 5.2.1.1) - actionmailer (= 5.2.1.1) - actionpack (= 5.2.1.1) - actionview (= 5.2.1.1) - activejob (= 5.2.1.1) - activemodel (= 5.2.1.1) - activerecord (= 5.2.1.1) - activestorage (= 5.2.1.1) - activesupport (= 5.2.1.1) + rails (5.2.2) + actioncable (= 5.2.2) + actionmailer (= 5.2.2) + actionpack (= 5.2.2) + actionview (= 5.2.2) + activejob (= 5.2.2) + activemodel (= 5.2.2) + activerecord (= 5.2.2) + activestorage (= 5.2.2) + activesupport (= 5.2.2) bundler (>= 1.3.0) - railties (= 5.2.1.1) + railties (= 5.2.2) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.3) actionpack (>= 5.0.1.x) @@ -461,9 +461,9 @@ GEM rails-i18n (5.1.2) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.2.1.1) - actionpack (= 5.2.1.1) - activesupport (= 5.2.1.1) + railties (5.2.2) + actionpack (= 5.2.2) + activesupport (= 5.2.2) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 9faa079a4..b9f1d3fdd 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -4,11 +4,11 @@ module NewUser SESSION_USER_RETURN_LOCATION = 'user_return_to' ACTIONS_ALLOWED_TO_ANY_USER = [:index, :recherche, :new] - ACTIONS_ALLOWED_TO_OWNER_OR_INVITE = [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire] + ACTIONS_ALLOWED_TO_OWNER_OR_INVITE = [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire, :purge_champ_piece_justificative] before_action :ensure_ownership!, except: ACTIONS_ALLOWED_TO_ANY_USER + ACTIONS_ALLOWED_TO_OWNER_OR_INVITE before_action :ensure_ownership_or_invitation!, only: ACTIONS_ALLOWED_TO_OWNER_OR_INVITE - before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier, :update] + before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update_brouillon, :modifier, :update, :purge_champ_piece_justificative] before_action :forbid_invite_submission!, only: [:update_brouillon] before_action :forbid_closed_submission!, only: [:update_brouillon] before_action :show_demarche_en_test_banner @@ -230,6 +230,14 @@ module NewUser redirect_to url_for dossiers_path end + def purge_champ_piece_justificative + @champ = dossier.champs.find(params[:champ_id]) + + @champ.piece_justificative_file.purge + + flash.notice = 'La pièce jointe a bien été supprimée.' + end + private def store_user_location! diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index f8ca9fe9f..87f312d51 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -94,11 +94,9 @@ class Users::SessionsController < Sessions::SessionsController administrateur = Administrateur.find_by(email: gestionnaire.email) [user, gestionnaire, administrateur].compact.each { |resource| sign_in(resource) } - if administrateur.present? - redirect_to admin_procedures_path - else - redirect_to gestionnaire_procedures_path - end + # redirect to procedure'url if stored by store_location_for(:user) in dossiers_controller + # redirect to root_path otherwise + redirect_to after_sign_in_path_for(:user) else flash[:alert] = 'Votre lien est invalide ou expiré, veuillez-vous reconnecter.' redirect_to new_user_session_path diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 4512f22da..7ae51a8e6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -214,6 +214,7 @@ class Procedure < ApplicationRecord procedure.published_at = nil procedure.logo_secure_token = nil procedure.remote_logo_url = self.logo_url + procedure.lien_notice = nil [:notice, :deliberation].each { |attachment| clone_attachment(procedure, attachment) } diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index 46cd62ac2..abdb3dece 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -21,8 +21,7 @@ - if Rails.env.development? = stylesheet_link_tag :xray - - if !current_user - = render partial: "layouts/matomo" + = render partial: "layouts/matomo" :javascript DATA = [{ diff --git a/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb b/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb new file mode 100644 index 000000000..b564293b9 --- /dev/null +++ b/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb @@ -0,0 +1,2 @@ +<%= render_flash(timeout: 5000, sticky: true) %> +<%= remove_element("#piece_justificative_#{@champ.id}") %> diff --git a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml index ce4b05fa3..1785b68d7 100644 --- a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml +++ b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml @@ -10,9 +10,12 @@ id: "champs_#{champ.id}", direct_upload: true - else - = render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true } - %br - Modifier : + %div{ id: "piece_justificative_#{champ.id}" } + = render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true } + %br + = link_to 'supprimer', purge_champ_piece_justificative_dossier_path(champ_id: champ.id), remote: true, method: :delete + %br + Modifier : = form.file_field :piece_justificative_file, id: "champs_#{champ.id}", direct_upload: true diff --git a/config/routes.rb b/config/routes.rb index 48532b4c2..5d8fbbc9b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -284,6 +284,7 @@ Rails.application.routes.draw do post 'commentaire' => 'dossiers#create_commentaire' post 'ask_deletion' get 'attestation' + delete 'purge_champ_piece_justificative' end collection do diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 27726b35f..d404218fc 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -906,4 +906,45 @@ describe NewUser::DossiersController, type: :controller do end end end + + describe '#purge_champ_piece_justificative' do + before { sign_in(user) } + + subject { delete :purge_champ_piece_justificative, params: { id: champ.dossier.id, champ_id: champ.id }, format: :js } + + context 'when dossier is owned by user' do + let(:dossier){ create(:dossier, user: user) } + let(:champ){ create(:champ_piece_justificative, dossier_id: dossier.id) } + + it { is_expected.to have_http_status(200) } + + it do + subject + expect(champ.reload.piece_justificative_file.attached?).to be(false) + end + + context 'but champ is not linked to this dossier' do + let(:champ){ create(:champ_piece_justificative, dossier: create(:dossier)) } + + it { is_expected.to redirect_to(root_path) } + + it do + subject + expect(champ.reload.piece_justificative_file.attached?).to be(true) + end + end + end + + context 'when dossier is not owned by user' do + let(:dossier){ create(:dossier, user: create(:user)) } + let(:champ){ create(:champ_piece_justificative, dossier_id: dossier.id) } + + it { is_expected.to redirect_to(root_path) } + + it do + subject + expect(champ.reload.piece_justificative_file.attached?).to be(true) + end + end + end end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 8d55ac53f..608791878 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -261,7 +261,9 @@ describe Users::SessionsController, type: :controller do context 'when the token is valid' do let(:login_token) { gestionnaire.login_token! } - it { is_expected.to redirect_to gestionnaire_procedures_path } + # TODO when the gestionnaire has no other account, and the token is valid, and the user signing in was not starting a demarche, + # redirect to root_path, then redirect to gestionnaire_procedures_path (see root_controller) + it { is_expected.to redirect_to root_path } it { expect(controller.current_gestionnaire).to eq(gestionnaire) } it { expect(controller).to have_received(:trust_device) } end diff --git a/spec/features/new_gestionnaire/gestionnaire_spec.rb b/spec/features/new_gestionnaire/gestionnaire_spec.rb index e38f6c3f7..220d28d93 100644 --- a/spec/features/new_gestionnaire/gestionnaire_spec.rb +++ b/spec/features/new_gestionnaire/gestionnaire_spec.rb @@ -9,6 +9,19 @@ feature 'The gestionnaire part' do let!(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) } let!(:dossier) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure) } + context 'when the gestionnaire is also a user' do + let!(:user) { create(:user, email: gestionnaire.email, password: password) } + + scenario 'a gestionnaire can fill a dossier' do + visit commencer_path(path: procedure.path) + + expect(page).to have_current_path new_user_session_path + sign_in_with(gestionnaire.email, password, true) + + expect(page).to have_content(procedure.libelle) + end + end + scenario 'A gestionnaire can accept a dossier', :js do log_in(gestionnaire.email, password) diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 196fc010d..21c3dd9d1 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -413,6 +413,12 @@ describe Procedure do expect(subject.assign_to).to eq([]) end + describe 'should not duplicate lien_notice' do + let(:procedure) { create(:procedure, lien_notice: "http://toto.com") } + + it { expect(subject.lien_notice).to be_nil } + end + describe 'procedure status is reset' do let(:procedure) { create(:procedure, :archived, received_mail: received_mail, service: service) }