From 5ca014587aa3ae723cb3c3f17a9c5e87765e8ce5 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Tue, 22 Sep 2015 15:00:59 +0200 Subject: [PATCH] [#883] move admin part in backoffice --- .../admin/commentaires_controller.rb | 3 -- .../backoffice/commentaires_controller.rb | 8 +++ .../dossiers_controller.rb} | 11 +--- app/controllers/commentaires_controller.rb | 10 ++-- .../dossiers}/show.html.haml | 1 + app/views/backoffice/index.html.haml | 3 +- app/views/dossiers/_infos_dossier.html.haml | 14 ++--- config/routes.rb | 9 +--- .../admin/dossier_controller_spec.rb | 53 ------------------- .../commentaires_controller_spec.rb | 20 +++++++ .../backoffice/dossiers_controller_spec.rb | 31 +++++++++++ .../commentaires_controller_spec.rb | 7 --- spec/factories/dossier.rb | 1 + .../add_commentaire_spec.rb} | 6 +-- .../display_dossier_page_spec.rb} | 2 +- .../backoffice/navigate_to_dossier_spec.rb | 25 +++++++++ .../recapitulatif_page/show_page_spec.rb | 2 +- 17 files changed, 111 insertions(+), 95 deletions(-) delete mode 100644 app/controllers/admin/commentaires_controller.rb create mode 100644 app/controllers/backoffice/commentaires_controller.rb rename app/controllers/{admin/dossier_controller.rb => backoffice/dossiers_controller.rb} (67%) rename app/views/{admin/dossier => backoffice/dossiers}/show.html.haml (98%) delete mode 100644 spec/controllers/admin/dossier_controller_spec.rb create mode 100644 spec/controllers/backoffice/commentaires_controller_spec.rb create mode 100644 spec/controllers/backoffice/dossiers_controller_spec.rb rename spec/features/{admin/dossier_page/_commentaires_flux_spec.rb => backoffice/add_commentaire_spec.rb} (87%) rename spec/features/{admin/dossier_page/show_page_spec.rb => backoffice/display_dossier_page_spec.rb} (98%) create mode 100644 spec/features/backoffice/navigate_to_dossier_spec.rb diff --git a/app/controllers/admin/commentaires_controller.rb b/app/controllers/admin/commentaires_controller.rb deleted file mode 100644 index e86f75c65..000000000 --- a/app/controllers/admin/commentaires_controller.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Admin::CommentairesController < CommentairesController - before_action :authenticate_user! -end \ No newline at end of file diff --git a/app/controllers/backoffice/commentaires_controller.rb b/app/controllers/backoffice/commentaires_controller.rb new file mode 100644 index 000000000..744227d0d --- /dev/null +++ b/app/controllers/backoffice/commentaires_controller.rb @@ -0,0 +1,8 @@ +class Backoffice::CommentairesController < CommentairesController + before_action :authenticate_gestionnaire! + + def is_gestionnaire? + true + end + +end \ No newline at end of file diff --git a/app/controllers/admin/dossier_controller.rb b/app/controllers/backoffice/dossiers_controller.rb similarity index 67% rename from app/controllers/admin/dossier_controller.rb rename to app/controllers/backoffice/dossiers_controller.rb index 4068204a2..189cbab65 100644 --- a/app/controllers/admin/dossier_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -1,8 +1,8 @@ -class Admin::DossierController < ApplicationController +class Backoffice::DossiersController < ApplicationController before_action :authenticate_gestionnaire! def show - @dossier = Dossier.find(params[:dossier_id]) + @dossier = Dossier.find(params[:id]) @entreprise = @dossier.entreprise.decorate @etablissement = @dossier.etablissement @pieces_justificatives = @dossier.pieces_justificatives @@ -17,13 +17,6 @@ class Admin::DossierController < ApplicationController redirect_start end - def index - @dossier = Dossier.find(params[:dossier_id]) - redirect_to url_for(controller: 'admin/dossier', action: :show, dossier_id: @dossier.id) - rescue - redirect_start - end - private def redirect_start diff --git a/app/controllers/commentaires_controller.rb b/app/controllers/commentaires_controller.rb index f0d6990c2..cbaf6c678 100644 --- a/app/controllers/commentaires_controller.rb +++ b/app/controllers/commentaires_controller.rb @@ -7,10 +7,14 @@ class CommentairesController < ApplicationController @commentaire.save - if request.referer.include? '/recapitulatif' - redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id']) + if is_gestionnaire? + redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id']) else - redirect_to url_for(controller: 'admin/dossier', action: :show, dossier_id: params['dossier_id']) + redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id']) end end + + def is_gestionnaire? + false + end end diff --git a/app/views/admin/dossier/show.html.haml b/app/views/backoffice/dossiers/show.html.haml similarity index 98% rename from app/views/admin/dossier/show.html.haml rename to app/views/backoffice/dossiers/show.html.haml index 1886e904b..053128c9a 100644 --- a/app/views/admin/dossier/show.html.haml +++ b/app/views/backoffice/dossiers/show.html.haml @@ -1,3 +1,4 @@ +#backoffice_dossier_show %h1#dossier_id.text-info{ :style => 'text-align:right'} = "Dossier n°#{@dossier.id}" diff --git a/app/views/backoffice/index.html.haml b/app/views/backoffice/index.html.haml index d79639e54..2e35e6de4 100644 --- a/app/views/backoffice/index.html.haml +++ b/app/views/backoffice/index.html.haml @@ -10,6 +10,7 @@ - @dossiers.each do |dossier| %tr %td= dossier.procedure.libelle - %td= dossier.nom_projet + %td + = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") %td Mise à jour %td= dossier.last_update \ No newline at end of file diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index c7ca90c76..30468fefc 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -31,13 +31,13 @@ %a{ href: "mailto:#{@dossier.mail_contact}" } = @dossier.mail_contact - -if !request.url.include?('admin') - .col-lg-6.col-md-6 - %br - %br - %a#modif_carte{href: "/dossiers/#{@dossier.id}/carte?back_url=recapitulatif"} Modifier la localisation - %br - %a#modif_description{href: "/dossiers/#{@dossier.id}/description?back_url=recapitulatif"} Modifier la description + / -if !request.url.include?('admin') + .col-lg-6.col-md-6 + %br + %br + %a#modif_carte{href: "/dossiers/#{@dossier.id}/carte?back_url=recapitulatif"} Modifier la localisation + %br + %a#modif_description{href: "/dossiers/#{@dossier.id}/description?back_url=recapitulatif"} Modifier la description .col-md-6 = pie_chart({"Montant à charge #{(100 - @dossier.montant_aide_demande.to_f/@dossier.montant_projet.to_f*100).round(2)}%" => (@dossier.montant_projet.to_f - @dossier.montant_aide_demande.to_f), "Montant souhaité #{(@dossier.montant_aide_demande.to_f/@dossier.montant_projet.to_f*100).round(2)}%" => @dossier.montant_aide_demande}) diff --git a/config/routes.rb b/config/routes.rb index 01a3e70d9..f4fb5ace6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,18 +29,13 @@ Rails.application.routes.draw do post '/commentaire' => 'commentaires#create' end - namespace :admin do - get '/dossiers/:dossier_id' => 'dossier#show' - get '/dossiers' => 'dossier#index' - post '/commentaire' => 'commentaires#create' - end - - get 'backoffice' => 'backoffice#index' namespace :backoffice do get 'sign_in' => '/gestionnaires/sessions#new' + resources :dossiers, only: [:show] + resources :commentaires, only: [:create] end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/spec/controllers/admin/dossier_controller_spec.rb b/spec/controllers/admin/dossier_controller_spec.rb deleted file mode 100644 index e38e7fdbe..000000000 --- a/spec/controllers/admin/dossier_controller_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'rails_helper' - -describe Admin::DossierController, type: :controller do - let(:dossier) { create(:dossier, :with_entreprise) } - let(:dossier_id) { dossier.id } - let(:bad_dossier_id) { Dossier.count + 10 } - let(:gestionnaire) { create(:gestionnaire) } - - describe 'GET #show' do - context "l'utilisateur est connecté" do - before do - sign_in gestionnaire - end - - it 'returns http success' do - get :show, dossier_id: dossier_id - expect(response).to have_http_status(200) - end - - it "le numéro de dossier n'existe pas" do - get :show, dossier_id: bad_dossier_id - expect(response).to redirect_to('/start/error_dossier') - end - end - - context "L'utilisateur n'est pas connecté mais le numéro de dossier est correct" do - subject { get :show, dossier_id: dossier_id } - it { is_expected.to redirect_to('/gestionnaires/sign_in') } - end - end - - describe 'GET #index' do - let(:user) { create(:user) } - before do - sign_in gestionnaire - end - - it 'le numéro de dossier est correct' do - get :index, dossier_id: dossier_id - expect(response).to redirect_to("/admin/dossiers/#{dossier_id}") - end - - it 'il n\' y a pas de numéro de dossier' do - get :index - expect(response).to redirect_to('/start/error_dossier') - end - - it 'le numéro de dossier n\'existe pas' do - get :index, dossier_id: bad_dossier_id - expect(response).to redirect_to('/start/error_dossier') - end - end -end diff --git a/spec/controllers/backoffice/commentaires_controller_spec.rb b/spec/controllers/backoffice/commentaires_controller_spec.rb new file mode 100644 index 000000000..891e48a92 --- /dev/null +++ b/spec/controllers/backoffice/commentaires_controller_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Backoffice::CommentairesController, type: :controller do + let(:dossier) { create(:dossier) } + let(:dossier_id) { dossier.id } + let(:email_commentaire) { 'test@test.com' } + let(:texte_commentaire) { 'Commentaire de test' } + + describe '#POST create' do + before do + sign_in create(:gestionnaire) + end + context "création correct d'un commentaire" do + it 'depuis la page admin' do + post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire + expect(response).to redirect_to("/backoffice/dossiers/#{dossier_id}") + end + end + end +end diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb new file mode 100644 index 000000000..7023432df --- /dev/null +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -0,0 +1,31 @@ +require 'rails_helper' + +describe Backoffice::DossiersController, type: :controller do + let(:dossier) { create(:dossier, :with_entreprise) } + let(:dossier_id) { dossier.id } + let(:bad_dossier_id) { Dossier.count + 10 } + let(:gestionnaire) { create(:gestionnaire) } + + describe 'GET #show' do + context "l'utilisateur est connecté" do + before do + sign_in gestionnaire + end + + it 'returns http success' do + get :show, id: dossier_id + expect(response).to have_http_status(200) + end + + it "le numéro de dossier n'existe pas" do + get :show, id: bad_dossier_id + expect(response).to redirect_to('/start/error_dossier') + end + end + + context "L'utilisateur n'est pas connecté mais le numéro de dossier est correct" do + subject { get :show, id: dossier_id } + it { is_expected.to redirect_to('/gestionnaires/sign_in') } + end + end +end diff --git a/spec/controllers/commentaires_controller_spec.rb b/spec/controllers/commentaires_controller_spec.rb index 7faf5e800..1bf28edec 100644 --- a/spec/controllers/commentaires_controller_spec.rb +++ b/spec/controllers/commentaires_controller_spec.rb @@ -9,16 +9,9 @@ describe CommentairesController, type: :controller do describe '#POST create' do context 'création correct d\'un commentaire' do it 'depuis la page récapitulatif' do - request.env['HTTP_REFERER'] = '/recapitulatif' post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif") end - - it 'depuis la page admin' do - request.env['HTTP_REFERER'] = '/admin/dossiers' - post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire - expect(response).to redirect_to("/admin/dossiers/#{dossier_id}") - end end end end diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 24a9f389b..06fb0057b 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :dossier do + nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger" trait :with_entreprise do after(:build) do |dossier, _evaluator| etablissement = create(:etablissement) diff --git a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb b/spec/features/backoffice/add_commentaire_spec.rb similarity index 87% rename from spec/features/admin/dossier_page/_commentaires_flux_spec.rb rename to spec/features/backoffice/add_commentaire_spec.rb index c7384ffc4..41d9af70e 100644 --- a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb +++ b/spec/features/backoffice/add_commentaire_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature '_Commentaires_Flux Admin/Dossier#Show Page' do +feature 'add commentaire on backoffice' do let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier_id) { dossier.id } let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') } @@ -11,7 +11,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do before do login_as gestionnaire, scope: :gestionnaire - visit "/admin/dossiers/#{dossier_id}" + visit backoffice_dossier_path(dossier) end context 'Affichage du flux de commentaire' do @@ -30,7 +30,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do context 'Affichage du formulaire de commentaire' do scenario 'Le formulaire envoie vers /dossiers/:dossier_id/commentaire en #POST' do - expect(page).to have_selector("form[action='/admin/commentaire?dossier_id=#{dossier_id}'][method=post]") + expect(page).to have_selector("form[action='/backoffice/commentaires?dossier_id=#{dossier_id}'][method=post]") end scenario 'Champs de texte' do diff --git a/spec/features/admin/dossier_page/show_page_spec.rb b/spec/features/backoffice/display_dossier_page_spec.rb similarity index 98% rename from spec/features/admin/dossier_page/show_page_spec.rb rename to spec/features/backoffice/display_dossier_page_spec.rb index 8fe2a3088..059fb17f9 100644 --- a/spec/features/admin/dossier_page/show_page_spec.rb +++ b/spec/features/backoffice/display_dossier_page_spec.rb @@ -6,7 +6,7 @@ feature 'Admin/Dossier#Show Page' do before do login_gestionnaire - visit "/admin/dossiers/#{dossier_id}" + visit "/backoffice/dossiers/#{dossier_id}" end context 'sur la page admin du dossier' do diff --git a/spec/features/backoffice/navigate_to_dossier_spec.rb b/spec/features/backoffice/navigate_to_dossier_spec.rb new file mode 100644 index 000000000..f7d52dfb2 --- /dev/null +++ b/spec/features/backoffice/navigate_to_dossier_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +feature 'on backoffice page' do + let(:procedure) { create(:procedure) } + let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) } + before do + visit backoffice_path + end + context 'when gestionnaire is logged in' do + let(:gestionnaire) { create(:gestionnaire) } + before do + page.find_by_id(:gestionnaire_email).set gestionnaire.email + page.find_by_id(:gestionnaire_password).set gestionnaire.password + page.click_on 'Se connecter' + end + context 'when he click on first dossier' do + before do + page.click_on dossier.nom_projet + end + scenario 'it redirect to dossier page' do + expect(page).to have_css('#backoffice_dossier_show') + end + end + end +end \ No newline at end of file diff --git a/spec/features/recapitulatif_page/show_page_spec.rb b/spec/features/recapitulatif_page/show_page_spec.rb index 2115f290a..5fc2ce2d5 100644 --- a/spec/features/recapitulatif_page/show_page_spec.rb +++ b/spec/features/recapitulatif_page/show_page_spec.rb @@ -36,7 +36,7 @@ feature 'Recapitulatif#Show Page' do context 'lien description' do scenario 'le lien vers description est présent' do - expect(page).to have_selector('a[id=modif_description]') + expect(page).to have_css('#modif_description') end scenario 'le lien vers description est correct' do