[Fix #2260] Add a search field in the usager UI
This commit is contained in:
parent
cd22a9742e
commit
ed436bfe77
4 changed files with 61 additions and 1 deletions
|
@ -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 n’avez 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -249,6 +249,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
collection do
|
||||
post 'recherche'
|
||||
# FIXME: to remove when show is implemeted
|
||||
# needed to fix refresh after dossier draft save
|
||||
get ':id', to: redirect('/dossiers/%{id}/modifier')
|
||||
|
|
|
@ -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 n’avez 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 n’avez 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
|
||||
|
|
Loading…
Reference in a new issue