Merge pull request #515 from sgmap/new_routes_hierarchy
New routes hierarchy
This commit is contained in:
commit
ff5cfafd6d
14 changed files with 247 additions and 25 deletions
13
app/controllers/new_gestionnaire/dossiers_controller.rb
Normal file
13
app/controllers/new_gestionnaire/dossiers_controller.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module NewGestionnaire
|
||||
class DossiersController < ProceduresController
|
||||
def attestation
|
||||
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
Dossier.find(params[:dossier_id])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
module NewGestionnaire
|
||||
class GestionnaireController < ApplicationController
|
||||
before_action :authenticate_gestionnaire!
|
||||
end
|
||||
end
|
18
app/controllers/new_gestionnaire/procedures_controller.rb
Normal file
18
app/controllers/new_gestionnaire/procedures_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module NewGestionnaire
|
||||
class ProceduresController < GestionnaireController
|
||||
before_action :ensure_ownership!
|
||||
|
||||
private
|
||||
|
||||
def procedure
|
||||
Procedure.find(params[:procedure_id])
|
||||
end
|
||||
|
||||
def ensure_ownership!
|
||||
if !procedure.gestionnaires.include?(current_gestionnaire)
|
||||
flash[:alert] = "Vous n'avez pas accès à cette procédure"
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
22
app/controllers/new_user/dossiers_controller.rb
Normal file
22
app/controllers/new_user/dossiers_controller.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
module NewUser
|
||||
class DossiersController < UserController
|
||||
before_action :ensure_ownership!
|
||||
|
||||
def attestation
|
||||
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
Dossier.find(params[:dossier_id])
|
||||
end
|
||||
|
||||
def ensure_ownership!
|
||||
if dossier.user != current_user
|
||||
flash[:alert] = "Vous n'avez pas accès à ce dossier"
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
5
app/controllers/new_user/user_controller.rb
Normal file
5
app/controllers/new_user/user_controller.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module NewUser
|
||||
class UserController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
end
|
||||
end
|
|
@ -7,10 +7,6 @@ class Users::RecapitulatifController < UsersController
|
|||
create_dossier_facade
|
||||
end
|
||||
|
||||
def attestation
|
||||
send_data(current_user_dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
||||
end
|
||||
|
||||
def initiate
|
||||
create_dossier_facade
|
||||
|
||||
|
|
|
@ -11,4 +11,7 @@
|
|||
= image_tag('pdf.svg', width: '20px')
|
||||
%p.title= dossier.attestation.title
|
||||
%p.delivery Délivrée le #{l(dossier.attestation.created_at, format: '%d %B %Y')}
|
||||
%a.btn.btn-primary{ href: users_dossier_recapitulatif_attestation_path(dossier), target: '_blank' } Télécharger
|
||||
- if user_signed_in?
|
||||
= link_to 'Télécharger', dossier_attestation_path(dossier), target: '_blank', class: 'btn btn-primary'
|
||||
- else
|
||||
= link_to 'Télécharger', procedure_dossier_attestation_path(dossier.procedure, dossier), target: '_blank', class: 'btn btn-primary'
|
||||
|
|
|
@ -82,8 +82,6 @@ Rails.application.routes.draw do
|
|||
get '/recapitulatif' => 'recapitulatif#show'
|
||||
post '/recapitulatif/initiate' => 'recapitulatif#initiate'
|
||||
|
||||
get '/recapitulatif/attestation' => 'recapitulatif#attestation'
|
||||
|
||||
post '/commentaire' => 'commentaires#create'
|
||||
resources :commentaires, only: [:index]
|
||||
|
||||
|
@ -229,5 +227,19 @@ Rails.application.routes.draw do
|
|||
|
||||
get "patron" => "root#patron"
|
||||
|
||||
scope module: 'new_user' do
|
||||
resources :dossiers, only: [] do
|
||||
get 'attestation'
|
||||
end
|
||||
end
|
||||
|
||||
scope module: 'new_gestionnaire' do
|
||||
resources :procedures, only: [] do
|
||||
resources :dossiers, only: [] do
|
||||
get 'attestation'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
apipie
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewGestionnaire::DossiersController, type: :controller do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
before { sign_in(gestionnaire) }
|
||||
|
||||
describe 'attestation' do
|
||||
context 'when a dossier has an attestation' do
|
||||
let(:fake_pdf) { double(read: 'pdf content') }
|
||||
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
||||
let!(:dossier) { create(:dossier, attestation: Attestation.new, procedure: procedure) }
|
||||
|
||||
it 'returns the attestation pdf' do
|
||||
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
||||
|
||||
expect(controller).to receive(:send_data)
|
||||
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
||||
controller.render nothing: true
|
||||
end
|
||||
|
||||
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewGestionnaire::GestionnaireController, type: :controller do
|
||||
describe 'before actions: authenticate_gestionnaire!' do
|
||||
it 'is present' do
|
||||
before_actions = NewGestionnaire::GestionnaireController
|
||||
._process_action_callbacks
|
||||
.find_all{|process_action_callbacks| process_action_callbacks.kind == :before}
|
||||
.map(&:filter)
|
||||
|
||||
expect(before_actions).to include(:authenticate_gestionnaire!)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewGestionnaire::ProceduresController, type: :controller do
|
||||
describe 'before_action: ensure_ownership!' do
|
||||
it 'is present' do
|
||||
before_actions = NewGestionnaire::ProceduresController
|
||||
._process_action_callbacks
|
||||
.find_all{|process_action_callbacks| process_action_callbacks.kind == :before}
|
||||
.map(&:filter)
|
||||
|
||||
expect(before_actions).to include(:ensure_ownership!)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ensure_ownership!' do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
|
||||
before do
|
||||
@controller.params[:procedure_id] = asked_procedure.id
|
||||
expect(@controller).to receive(:current_gestionnaire).and_return(gestionnaire)
|
||||
allow(@controller).to receive(:redirect_to)
|
||||
|
||||
@controller.send(:ensure_ownership!)
|
||||
end
|
||||
|
||||
context 'when a gestionnaire asks for its procedure' do
|
||||
let(:asked_procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
||||
|
||||
it 'does not redirects nor flash' do
|
||||
expect(@controller).not_to have_received(:redirect_to)
|
||||
expect(flash.alert).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a gestionnaire asks for another procedure' do
|
||||
let(:asked_procedure) { create(:procedure) }
|
||||
|
||||
it 'redirects and flash' do
|
||||
expect(@controller).to have_received(:redirect_to).with(root_path)
|
||||
expect(flash.alert).to eq("Vous n'avez pas accès à cette procédure")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
67
spec/controllers/new_user/dossiers_controller_spec.rb
Normal file
67
spec/controllers/new_user/dossiers_controller_spec.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewUser::DossiersController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
describe 'before_action: ensure_ownership!' do
|
||||
it 'is present' do
|
||||
before_actions = NewUser::DossiersController
|
||||
._process_action_callbacks
|
||||
.find_all{|process_action_callbacks| process_action_callbacks.kind == :before}
|
||||
.map(&:filter)
|
||||
|
||||
expect(before_actions).to include(:ensure_ownership!)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ensure_ownership!' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
@controller.params[:dossier_id] = asked_dossier.id
|
||||
expect(@controller).to receive(:current_user).and_return(user)
|
||||
allow(@controller).to receive(:redirect_to)
|
||||
|
||||
@controller.send(:ensure_ownership!)
|
||||
end
|
||||
|
||||
context 'when a user asks for its dossier' do
|
||||
let(:asked_dossier) { create(:dossier, user: user) }
|
||||
|
||||
it 'does not redirects nor flash' do
|
||||
expect(@controller).not_to have_received(:redirect_to)
|
||||
expect(flash.alert).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a user asks for another dossier' do
|
||||
let(:asked_dossier) { create(:dossier) }
|
||||
|
||||
it 'redirects and flash' do
|
||||
expect(@controller).to have_received(:redirect_to).with(root_path)
|
||||
expect(flash.alert).to eq("Vous n'avez pas accès à ce dossier")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'attestation' do
|
||||
before { sign_in(user) }
|
||||
|
||||
context 'when a dossier has an attestation' do
|
||||
let(:fake_pdf) { double(read: 'pdf content') }
|
||||
let!(:dossier) { create(:dossier, attestation: Attestation.new, user: user) }
|
||||
|
||||
it 'returns the attestation pdf' do
|
||||
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
||||
|
||||
expect(controller).to receive(:send_data)
|
||||
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
||||
controller.render nothing: true
|
||||
end
|
||||
|
||||
get :attestation, params: { dossier_id: dossier.id }
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
spec/controllers/new_user/user_controller_spec.rb
Normal file
14
spec/controllers/new_user/user_controller_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewUser::UserController, type: :controller do
|
||||
describe 'before actions: authenticate_gestionnaire!' do
|
||||
it 'is present' do
|
||||
before_actions = NewUser::UserController
|
||||
._process_action_callbacks
|
||||
.find_all{|process_action_callbacks| process_action_callbacks.kind == :before}
|
||||
.map(&:filter)
|
||||
|
||||
expect(before_actions).to include(:authenticate_user!)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -51,22 +51,4 @@ describe Users::RecapitulatifController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Get #attestation' do
|
||||
context 'when a dossier has an attestation' do
|
||||
let(:fake_pdf) { double(read: 'pdf content') }
|
||||
let!(:dossier) { create(:dossier, attestation: Attestation.new) }
|
||||
|
||||
it 'returns the attestation pdf' do
|
||||
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
||||
|
||||
expect(controller).to receive(:send_data)
|
||||
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
||||
controller.render nothing: true
|
||||
end
|
||||
|
||||
get :attestation, params: { dossier_id: dossier.id }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue