From 0995c8e5ad1b05fbed54409702a40ee99d5c25b5 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 20 Sep 2018 12:03:52 +0000 Subject: [PATCH 1/5] dossier: extract the invitation dropdown to a partial --- app/views/invites/_dropdown.html.haml | 10 ++++++++++ app/views/shared/dossiers/_header.html.haml | 11 +---------- 2 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 app/views/invites/_dropdown.html.haml diff --git a/app/views/invites/_dropdown.html.haml b/app/views/invites/_dropdown.html.haml new file mode 100644 index 000000000..19fddeb52 --- /dev/null +++ b/app/views/invites/_dropdown.html.haml @@ -0,0 +1,10 @@ +%span.button.dropdown.invite-user-action + %span.icon.person + - if dossier.invites.count > 0 + Voir les personnes invitées + %span.badge= dossier.invites.count + - else + Inviter une personne à modifier ce dossier + + .dropdown-content.fade-in-down + = render partial: "invites/form", locals: { dossier: dossier } diff --git a/app/views/shared/dossiers/_header.html.haml b/app/views/shared/dossiers/_header.html.haml index edf4c5b92..45e53762b 100644 --- a/app/views/shared/dossiers/_header.html.haml +++ b/app/views/shared/dossiers/_header.html.haml @@ -4,13 +4,4 @@ .dossier-form-actions - if current_user.owns?(dossier) - %span.button.dropdown.invite-user-action - %span.icon.person - - if dossier.invites.count > 0 - Voir les personnes invitées - %span.badge= dossier.invites.count - - else - Inviter une personne à modifier ce dossier - - .dropdown-content.fade-in-down - = render partial: "invites/form", locals: { dossier: dossier } + = render partial: 'invites/dropdown', locals: { dossier: dossier } From 01599ac1e114c7719170d65a18f34b2e3cacd1b3 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 20 Sep 2018 14:05:18 +0200 Subject: [PATCH 2/5] dossier: allow inviting users on the dossier page --- app/assets/stylesheets/new_design/dossier_show.scss | 7 ++++++- app/views/new_user/dossiers/show/_header.html.haml | 4 ++++ spec/views/new_user/dossiers/demande.html.haml_spec.rb | 1 + .../views/new_user/dossiers/show/_header.html.haml_spec.rb | 6 +++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/new_design/dossier_show.scss b/app/assets/stylesheets/new_design/dossier_show.scss index e85c5d10c..971c7cc70 100644 --- a/app/assets/stylesheets/new_design/dossier_show.scss +++ b/app/assets/stylesheets/new_design/dossier_show.scss @@ -11,7 +11,7 @@ } .title-container { - margin-bottom: $default-padding * 2; + margin-bottom: $default-spacer; padding-left: 32px; .icon.folder { @@ -31,6 +31,11 @@ color: $grey; font-weight: bold; } + + .header-actions { + margin-bottom: $default-spacer; + text-align: right; + } } .button.edit-form { diff --git a/app/views/new_user/dossiers/show/_header.html.haml b/app/views/new_user/dossiers/show/_header.html.haml index 6fd9cc867..c3686c8bc 100644 --- a/app/views/new_user/dossiers/show/_header.html.haml +++ b/app/views/new_user/dossiers/show/_header.html.haml @@ -7,6 +7,10 @@ %h1= dossier.procedure.libelle %h2 Dossier nº #{dossier.id} + - if current_user.owns?(dossier) + .header-actions + = render partial: 'invites/dropdown', locals: { dossier: dossier } + %ul.tabs = dynamic_tab_item('Résumé', dossier_path(dossier)) = dynamic_tab_item('Demande', [demande_dossier_path(dossier), modifier_dossier_path(dossier)]) diff --git a/spec/views/new_user/dossiers/demande.html.haml_spec.rb b/spec/views/new_user/dossiers/demande.html.haml_spec.rb index 0dff42b3d..cad147eed 100644 --- a/spec/views/new_user/dossiers/demande.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/demande.html.haml_spec.rb @@ -5,6 +5,7 @@ describe 'new_user/dossiers/demande.html.haml', type: :view do let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) } before do + sign_in dossier.user assign(:dossier, dossier) end diff --git a/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb b/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb index 8c37b55f4..57d0d795c 100644 --- a/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb @@ -1,7 +1,11 @@ describe 'new_user/dossiers/show/header.html.haml', type: :view do let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure)) } - subject! { render 'new_user/dossiers/show/header.html.haml', dossier: dossier } + before do + sign_in dossier.user + end + + subject! { render 'new_user/dossiers/show/header.html.haml', dossier: dossier, is_dossier_owner: true } it 'affiche les informations du dossier' do expect(rendered).to have_text(dossier.procedure.libelle) From a5419b2f08fa2dee3682eac96930578a33977889 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 18 Sep 2018 12:37:50 +0000 Subject: [PATCH 3/5] dossier: fix redirection to dossiers/invite --- app/controllers/new_user/dossiers_controller.rb | 14 +++++++------- .../users/dossiers/invites_controller.rb | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index ce5023b9f..7f8091f5b 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -122,14 +122,14 @@ module NewUser flash.now.alert = errors render :modifier else - if current_user.owns?(dossier) - if Flipflop.new_dossier_details? - redirect_to demande_dossier_path(@dossier) - else - redirect_to users_dossier_recapitulatif_path(@dossier) - end + if Flipflop.new_dossier_details? + redirect_to demande_dossier_path(@dossier) else - redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) + if current_user.owns?(dossier) + redirect_to users_dossier_recapitulatif_path(@dossier) + else + redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user)) + end end end end diff --git a/app/controllers/users/dossiers/invites_controller.rb b/app/controllers/users/dossiers/invites_controller.rb index f4c4d9dc6..078e3d74c 100644 --- a/app/controllers/users/dossiers/invites_controller.rb +++ b/app/controllers/users/dossiers/invites_controller.rb @@ -12,6 +12,10 @@ class Users::Dossiers::InvitesController < UsersController def show @facade = InviteDossierFacades.new params[:id].to_i, current_user.email + if Flipflop.new_dossier_details? + return redirect_to dossier_path(@facade.dossier) + end + if @facade.dossier.brouillon? redirect_to brouillon_dossier_path(@facade.dossier) else From 682e29a21148514b4e9c917ce9783d86bcff1393 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 20 Sep 2018 15:39:15 +0000 Subject: [PATCH 4/5] dossier: refactor the pages permissions Fixes the invites not being able to create a commentaire. --- app/controllers/new_user/dossiers_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 7f8091f5b..0cdb5a55a 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -2,8 +2,11 @@ module NewUser class DossiersController < UserController include DossierHelper - before_action :ensure_ownership!, except: [:index, :show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :recherche] - before_action :ensure_ownership_or_invitation!, only: [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire] + ACTIONS_ALLOWED_TO_ANY_USER = [:index, :recherche] + ACTIONS_ALLOWED_TO_OWNER_OR_INVITE = [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire] + + 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 :forbid_invite_submission!, only: [:update_brouillon] before_action :forbid_closed_submission!, only: [:update_brouillon] From 23820988becd0ab1c611da990bf395fffd9f4fbb Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 24 Sep 2018 17:12:15 +0200 Subject: [PATCH 5/5] fixup! dossier: allow inviting users on the dossier page --- spec/views/new_user/dossiers/show/_header.html.haml_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb b/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb index 57d0d795c..9eaa1d342 100644 --- a/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/show/_header.html.haml_spec.rb @@ -5,7 +5,7 @@ describe 'new_user/dossiers/show/header.html.haml', type: :view do sign_in dossier.user end - subject! { render 'new_user/dossiers/show/header.html.haml', dossier: dossier, is_dossier_owner: true } + subject! { render 'new_user/dossiers/show/header.html.haml', dossier: dossier } it 'affiche les informations du dossier' do expect(rendered).to have_text(dossier.procedure.libelle)