Merge pull request #2264 from betagouv/user-search

User search
This commit is contained in:
Pierre de La Morinerie 2018-07-17 17:32:48 +02:00 committed by GitHub
commit 05df46715a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 73 additions and 10 deletions

View file

@ -1,8 +1,10 @@
module NewUser
class DossiersController < UserController
include DossierHelper
helper_method :new_demarche_url
before_action :ensure_ownership!, except: [:index, :modifier, :update]
before_action :ensure_ownership!, except: [:index, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:modifier, :update]
before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update]
before_action :forbid_invite_submission!, only: [:update]
@ -114,6 +116,18 @@ module NewUser
end
end
def recherche
@dossier_id = params[:dossier_id]
dossier = current_user.dossiers.find_by(id: @dossier_id)
if dossier
redirect_to url_for_dossier(dossier)
else
flash.alert = "Vous navez pas de dossier avec le nº #{@dossier_id}."
redirect_to dossiers_path
end
end
def new_demarche_url
"https://doc.demarches-simplifiees.fr/listes-des-demarches"
end

View file

@ -21,7 +21,7 @@ class NewAttestationMailer < ApplicationMailer
Suite à cette opération, l'attestation liée à votre dossier n'a pas é regénérée.
Ce problème est désormais reglé, votre nouvelle attestation est disponible à l'adresse suivante :
#{dossier_attestation_url(dossier)}
#{attestation_dossier_url(dossier)}
Cordialement,

View file

@ -17,7 +17,7 @@ class ResendAttestationMailer < ApplicationMailer
L'attestation de votre dossier  #{dossier.id} (procédure "#{dossier.procedure.libelle}") a été modifiée.
Votre nouvelle attestation est disponible à l'adresse suivante :
#{dossier_attestation_url(dossier)}
#{attestation_dossier_url(dossier)}
Cordialement,

View file

@ -53,7 +53,7 @@ module TagsSubstitutionConcern
{
libelle: 'lien attestation',
description: '',
lambda: -> (d) { external_link(dossier_attestation_url(d)) },
lambda: -> (d) { external_link(attestation_dossier_url(d)) },
available_for_states: ['accepte']
}
]

View file

@ -12,6 +12,6 @@
%p.title= dossier.attestation.title
%p.delivery Délivrée le #{l(dossier.attestation.created_at, format: '%d %B %Y')}
- if user_signed_in? && current_user == dossier.user
= link_to 'Télécharger', dossier_attestation_path(dossier), target: '_blank', class: 'btn btn-primary'
= link_to 'Télécharger', attestation_dossier_path(dossier), target: '_blank', class: 'btn btn-primary'
- else
= link_to 'Télécharger', attestation_gestionnaire_dossier_path(dossier.procedure, dossier), target: '_blank', class: 'btn btn-primary'

View file

@ -47,6 +47,14 @@
%button{ title: "Rechercher" }
= image_tag "icons/search-blue.svg"
- if nav_bar_profile == :user && user_signed_in? && current_user.dossiers.count > 2
%li
.header-search
= form_tag recherche_dossiers_path, method: :post, class: "form" do
= text_field_tag :dossier_id, "", placeholder: "Numéro de dossier"
%button{ title: "Rechercher" }
= image_tag "icons/search-blue.svg"
- if gestionnaire_signed_in? || user_signed_in?
%li
.header-menu-opener

View file

@ -245,12 +245,16 @@ Rails.application.routes.draw do
get 'modifier'
get 'merci'
post 'ask_deletion'
end
get 'attestation'
end
collection do
post 'recherche'
# FIXME: to remove when show is implemeted
# needed to fix refresh after dossier draft save
get 'dossiers/:id', to: redirect('/dossiers/%{id}/modifier')
get ':id', to: redirect('/dossiers/%{id}/modifier')
end
end
end
scope module: 'new_gestionnaire', as: 'gestionnaire' do

View file

@ -111,7 +111,7 @@ describe NewUser::DossiersController, type: :controller do
controller.head :ok
end
get :attestation, params: { dossier_id: dossier.id }
get :attestation, params: { id: dossier.id }
expect(response).to have_http_status(:success)
end
end

View file

@ -65,4 +65,41 @@ describe 'user access to the list of his dossier' do
expect(page).to have_content(CONTACT_EMAIL)
end
end
describe "recherche" do
context "when the dossier does not exist" do
before do
page.find_by_id('dossier_id').set(10000000)
click_button("Rechercher")
end
it "shows an error message on the dossiers page" do
expect(current_path).to eq(dossiers_path)
expect(page).to have_content("Vous navez pas de dossier avec le nº 10000000.")
end
end
context "when the dossier does not belong to the user" do
before do
page.find_by_id('dossier_id').set(dossier2.id)
click_button("Rechercher")
end
it "shows an error message on the dossiers page" do
expect(current_path).to eq(dossiers_path)
expect(page).to have_content("Vous navez pas de dossier avec le nº #{dossier2.id}.")
end
end
context "when the dossier belongs to the user" do
before do
page.find_by_id('dossier_id').set(dossier1.id)
click_button("Rechercher")
end
it "redirects to the dossier page" do
expect(current_path).to eq(users_dossier_recapitulatif_path(dossier1))
end
end
end
end