[#883] move admin part in backoffice
This commit is contained in:
parent
1238fdae23
commit
5ca014587a
17 changed files with 111 additions and 95 deletions
|
@ -1,3 +0,0 @@
|
||||||
class Admin::CommentairesController < CommentairesController
|
|
||||||
before_action :authenticate_user!
|
|
||||||
end
|
|
8
app/controllers/backoffice/commentaires_controller.rb
Normal file
8
app/controllers/backoffice/commentaires_controller.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class Backoffice::CommentairesController < CommentairesController
|
||||||
|
before_action :authenticate_gestionnaire!
|
||||||
|
|
||||||
|
def is_gestionnaire?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,8 +1,8 @@
|
||||||
class Admin::DossierController < ApplicationController
|
class Backoffice::DossiersController < ApplicationController
|
||||||
before_action :authenticate_gestionnaire!
|
before_action :authenticate_gestionnaire!
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
@dossier = Dossier.find(params[:id])
|
||||||
@entreprise = @dossier.entreprise.decorate
|
@entreprise = @dossier.entreprise.decorate
|
||||||
@etablissement = @dossier.etablissement
|
@etablissement = @dossier.etablissement
|
||||||
@pieces_justificatives = @dossier.pieces_justificatives
|
@pieces_justificatives = @dossier.pieces_justificatives
|
||||||
|
@ -17,13 +17,6 @@ class Admin::DossierController < ApplicationController
|
||||||
redirect_start
|
redirect_start
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def redirect_start
|
def redirect_start
|
|
@ -7,10 +7,14 @@ class CommentairesController < ApplicationController
|
||||||
|
|
||||||
@commentaire.save
|
@commentaire.save
|
||||||
|
|
||||||
if request.referer.include? '/recapitulatif'
|
if is_gestionnaire?
|
||||||
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id'])
|
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_gestionnaire?
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#backoffice_dossier_show
|
||||||
%h1#dossier_id.text-info{ :style => 'text-align:right'}
|
%h1#dossier_id.text-info{ :style => 'text-align:right'}
|
||||||
= "Dossier n°#{@dossier.id}"
|
= "Dossier n°#{@dossier.id}"
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
- @dossiers.each do |dossier|
|
- @dossiers.each do |dossier|
|
||||||
%tr
|
%tr
|
||||||
%td= dossier.procedure.libelle
|
%td= dossier.procedure.libelle
|
||||||
%td= dossier.nom_projet
|
%td
|
||||||
|
= link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}")
|
||||||
%td Mise à jour
|
%td Mise à jour
|
||||||
%td= dossier.last_update
|
%td= dossier.last_update
|
|
@ -31,13 +31,13 @@
|
||||||
%a{ href: "mailto:#{@dossier.mail_contact}" }
|
%a{ href: "mailto:#{@dossier.mail_contact}" }
|
||||||
= @dossier.mail_contact
|
= @dossier.mail_contact
|
||||||
|
|
||||||
-if !request.url.include?('admin')
|
/ -if !request.url.include?('admin')
|
||||||
.col-lg-6.col-md-6
|
.col-lg-6.col-md-6
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
%a#modif_carte{href: "/dossiers/#{@dossier.id}/carte?back_url=recapitulatif"} Modifier la localisation
|
%a#modif_carte{href: "/dossiers/#{@dossier.id}/carte?back_url=recapitulatif"} Modifier la localisation
|
||||||
%br
|
%br
|
||||||
%a#modif_description{href: "/dossiers/#{@dossier.id}/description?back_url=recapitulatif"} Modifier la description
|
%a#modif_description{href: "/dossiers/#{@dossier.id}/description?back_url=recapitulatif"} Modifier la description
|
||||||
|
|
||||||
.col-md-6
|
.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})
|
= 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})
|
||||||
|
|
|
@ -29,18 +29,13 @@ Rails.application.routes.draw do
|
||||||
post '/commentaire' => 'commentaires#create'
|
post '/commentaire' => 'commentaires#create'
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :admin do
|
|
||||||
get '/dossiers/:dossier_id' => 'dossier#show'
|
|
||||||
get '/dossiers' => 'dossier#index'
|
|
||||||
post '/commentaire' => 'commentaires#create'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get 'backoffice' => 'backoffice#index'
|
get 'backoffice' => 'backoffice#index'
|
||||||
|
|
||||||
namespace :backoffice do
|
namespace :backoffice do
|
||||||
get 'sign_in' => '/gestionnaires/sessions#new'
|
get 'sign_in' => '/gestionnaires/sessions#new'
|
||||||
|
resources :dossiers, only: [:show]
|
||||||
|
resources :commentaires, only: [:create]
|
||||||
end
|
end
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
|
@ -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
|
|
20
spec/controllers/backoffice/commentaires_controller_spec.rb
Normal file
20
spec/controllers/backoffice/commentaires_controller_spec.rb
Normal file
|
@ -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
|
31
spec/controllers/backoffice/dossiers_controller_spec.rb
Normal file
31
spec/controllers/backoffice/dossiers_controller_spec.rb
Normal file
|
@ -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
|
|
@ -9,16 +9,9 @@ describe CommentairesController, type: :controller do
|
||||||
describe '#POST create' do
|
describe '#POST create' do
|
||||||
context 'création correct d\'un commentaire' do
|
context 'création correct d\'un commentaire' do
|
||||||
it 'depuis la page récapitulatif' 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
|
post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire
|
||||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
|
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :dossier do
|
factory :dossier do
|
||||||
|
nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger"
|
||||||
trait :with_entreprise do
|
trait :with_entreprise do
|
||||||
after(:build) do |dossier, _evaluator|
|
after(:build) do |dossier, _evaluator|
|
||||||
etablissement = create(:etablissement)
|
etablissement = create(:etablissement)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
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) { create(:dossier, :with_entreprise, :with_procedure) }
|
||||||
let(:dossier_id) { dossier.id }
|
let(:dossier_id) { dossier.id }
|
||||||
let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') }
|
let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') }
|
||||||
|
@ -11,7 +11,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as gestionnaire, scope: :gestionnaire
|
login_as gestionnaire, scope: :gestionnaire
|
||||||
visit "/admin/dossiers/#{dossier_id}"
|
visit backoffice_dossier_path(dossier)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Affichage du flux de commentaire' do
|
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
|
context 'Affichage du formulaire de commentaire' do
|
||||||
scenario 'Le formulaire envoie vers /dossiers/:dossier_id/commentaire en #POST' 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
|
end
|
||||||
|
|
||||||
scenario 'Champs de texte' do
|
scenario 'Champs de texte' do
|
|
@ -6,7 +6,7 @@ feature 'Admin/Dossier#Show Page' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_gestionnaire
|
login_gestionnaire
|
||||||
visit "/admin/dossiers/#{dossier_id}"
|
visit "/backoffice/dossiers/#{dossier_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'sur la page admin du dossier' do
|
context 'sur la page admin du dossier' do
|
25
spec/features/backoffice/navigate_to_dossier_spec.rb
Normal file
25
spec/features/backoffice/navigate_to_dossier_spec.rb
Normal file
|
@ -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
|
|
@ -36,7 +36,7 @@ feature 'Recapitulatif#Show Page' do
|
||||||
|
|
||||||
context 'lien description' do
|
context 'lien description' do
|
||||||
scenario 'le lien vers description est présent' 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
|
end
|
||||||
|
|
||||||
scenario 'le lien vers description est correct' do
|
scenario 'le lien vers description est correct' do
|
||||||
|
|
Loading…
Reference in a new issue