Migrate commencer to new_user
This commit is contained in:
parent
66fb0c70f6
commit
cfd1950e17
8 changed files with 166 additions and 209 deletions
25
app/controllers/new_user/commencer_controller.rb
Normal file
25
app/controllers/new_user/commencer_controller.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module NewUser
|
||||
class CommencerController < ApplicationController
|
||||
def commencer_test
|
||||
procedure = Procedure.brouillons.find_by(path: params[:path])
|
||||
|
||||
if procedure.present?
|
||||
redirect_to new_dossier_path(procedure_id: procedure.id, brouillon: true)
|
||||
else
|
||||
flash.alert = "La démarche est inconnue."
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
def commencer
|
||||
procedure = Procedure.publiees.find_by(path: params[:path])
|
||||
|
||||
if procedure.present?
|
||||
redirect_to new_dossier_path(procedure_id: procedure.id)
|
||||
else
|
||||
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,8 @@ module NewUser
|
|||
class DossiersController < UserController
|
||||
include DossierHelper
|
||||
|
||||
ACTIONS_ALLOWED_TO_ANY_USER = [:index, :recherche]
|
||||
SESSION_USER_RETURN_LOCATION = 'user_return_to'
|
||||
ACTIONS_ALLOWED_TO_ANY_USER = [:index, :recherche, :new]
|
||||
ACTIONS_ALLOWED_TO_OWNER_OR_INVITE = [:show, :demande, :messagerie, :brouillon, :update_brouillon, :modifier, :update, :create_commentaire]
|
||||
|
||||
before_action :ensure_ownership!, except: ACTIONS_ALLOWED_TO_ANY_USER + ACTIONS_ALLOWED_TO_OWNER_OR_INVITE
|
||||
|
@ -11,6 +12,7 @@ module NewUser
|
|||
before_action :forbid_invite_submission!, only: [:update_brouillon]
|
||||
before_action :forbid_closed_submission!, only: [:update_brouillon]
|
||||
before_action :show_demarche_en_test_banner
|
||||
before_action :store_user_location!, only: :new
|
||||
|
||||
def index
|
||||
@user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page)
|
||||
|
@ -194,7 +196,7 @@ module NewUser
|
|||
redirect_to dossiers_path
|
||||
else
|
||||
flash.notice = "L'instruction de votre dossier a commencé, il n'est plus possible de supprimer votre dossier. Si vous souhaitez annuler l'instruction contactez votre administration par la messagerie de votre dossier."
|
||||
redirect_to users_dossier_path(dossier)
|
||||
redirect_to dossier_path(dossier)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -210,8 +212,38 @@ module NewUser
|
|||
end
|
||||
end
|
||||
|
||||
def new
|
||||
erase_user_location!
|
||||
|
||||
if params[:brouillon]
|
||||
procedure = Procedure.brouillon.find(params[:procedure_id])
|
||||
else
|
||||
procedure = Procedure.publiees.find(params[:procedure_id])
|
||||
end
|
||||
|
||||
dossier = Dossier.create!(procedure: procedure, user: current_user, state: Dossier.states.fetch(:brouillon))
|
||||
|
||||
if dossier.procedure.for_individual
|
||||
redirect_to identite_dossier_path(dossier)
|
||||
else
|
||||
redirect_to siret_dossier_path(id: dossier.id)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = t('errors.messages.procedure_not_found')
|
||||
|
||||
redirect_to url_for dossiers_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def store_user_location!
|
||||
store_location_for(:user, request.fullpath)
|
||||
end
|
||||
|
||||
def erase_user_location!
|
||||
session.delete(SESSION_USER_RETURN_LOCATION)
|
||||
end
|
||||
|
||||
def show_demarche_en_test_banner
|
||||
if @dossier.present? && @dossier.procedure.brouillon?
|
||||
flash.now.notice = "Ce dossier est déposé sur une démarche en test. Il sera supprimé lors de la publication de la démarche."
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
class Users::DossiersController < UsersController
|
||||
include SmartListing::Helper::ControllerExtensions
|
||||
helper SmartListing::Helper
|
||||
|
||||
SESSION_USER_RETURN_LOCATION = 'user_return_to'
|
||||
|
||||
before_action :store_user_location!, only: :new
|
||||
before_action :authenticate_user!, except: [:commencer, :commencer_test]
|
||||
|
||||
before_action only: [:show] do
|
||||
authorized_routes? self.class
|
||||
end
|
||||
|
||||
def commencer_test
|
||||
procedure = Procedure.brouillons.find_by(path: params[:path])
|
||||
|
||||
if procedure.present?
|
||||
redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true)
|
||||
else
|
||||
flash.alert = "La démarche est inconnue."
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
def commencer
|
||||
procedure = Procedure.publiees.find_by(path: params[:path])
|
||||
|
||||
if procedure.present?
|
||||
redirect_to new_users_dossier_path(procedure_id: procedure.id)
|
||||
else
|
||||
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
erase_user_location!
|
||||
|
||||
if params[:brouillon]
|
||||
procedure = Procedure.brouillon.find(params[:procedure_id])
|
||||
else
|
||||
procedure = Procedure.publiees.find(params[:procedure_id])
|
||||
end
|
||||
|
||||
dossier = Dossier.create!(procedure: procedure, user: current_user, state: Dossier.states.fetch(:brouillon))
|
||||
|
||||
if dossier.procedure.for_individual
|
||||
redirect_to identite_dossier_path(dossier)
|
||||
else
|
||||
redirect_to siret_dossier_path(id: dossier.id)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
error_procedure
|
||||
end
|
||||
|
||||
def self.route_authorization
|
||||
{
|
||||
states: [Dossier.states.fetch(:brouillon)]
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def error_procedure
|
||||
flash.alert = t('errors.messages.procedure_not_found')
|
||||
|
||||
redirect_to url_for dossiers_path
|
||||
end
|
||||
|
||||
def facade(id = params[:id])
|
||||
DossierFacades.new id, current_user.email
|
||||
end
|
||||
|
||||
def store_user_location!
|
||||
store_location_for(:user, request.fullpath)
|
||||
end
|
||||
|
||||
def erase_user_location!
|
||||
session.delete(SESSION_USER_RETURN_LOCATION)
|
||||
end
|
||||
end
|
|
@ -127,11 +127,6 @@ Rails.application.routes.draw do
|
|||
post ':position/carte', to: 'carte#show', as: :carte
|
||||
end
|
||||
|
||||
namespace :commencer do
|
||||
get '/test/:path' => '/users/dossiers#commencer_test', as: :test
|
||||
get '/:path' => '/users/dossiers#commencer'
|
||||
end
|
||||
|
||||
get "patron" => "root#patron"
|
||||
|
||||
get "contact", to: "support#index"
|
||||
|
@ -149,7 +144,7 @@ Rails.application.routes.draw do
|
|||
resources :invites, only: [:index, :show]
|
||||
end
|
||||
|
||||
resources :dossiers do
|
||||
resources :dossiers, only: [] do
|
||||
post '/carte/zones' => 'carte#zones'
|
||||
get '/carte' => 'carte#show'
|
||||
post '/carte' => 'carte#save'
|
||||
|
@ -267,7 +262,12 @@ Rails.application.routes.draw do
|
|||
#
|
||||
|
||||
scope module: 'new_user' do
|
||||
resources :dossiers, only: [:index, :show] do
|
||||
namespace :commencer do
|
||||
get '/test/:path', action: 'commencer_test', as: :test
|
||||
get '/:path', action: 'commencer'
|
||||
end
|
||||
|
||||
resources :dossiers, only: [:index, :show, :new] do
|
||||
member do
|
||||
get 'identite'
|
||||
patch 'update_identite'
|
||||
|
|
40
spec/controllers/new_user/commencer_controller_spec.rb
Normal file
40
spec/controllers/new_user/commencer_controller_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewUser::CommencerController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
describe 'GET #commencer' do
|
||||
subject { get :commencer, params: { path: path } }
|
||||
let(:path) { procedure.path }
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { expect(subject).to redirect_to new_dossier_path(procedure_id: procedure.id) }
|
||||
|
||||
context 'when procedure path does not exist' do
|
||||
let(:path) { 'hello' }
|
||||
|
||||
it { expect(subject).to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #commencer_test' do
|
||||
before do
|
||||
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
|
||||
end
|
||||
|
||||
subject { get :commencer_test, params: { path: path } }
|
||||
let(:procedure) { create(:procedure, :with_path) }
|
||||
let(:path) { procedure.path }
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { expect(subject).to redirect_to new_dossier_path(procedure_id: procedure.id, brouillon: true) }
|
||||
|
||||
context 'when procedure path does not exist' do
|
||||
let(:path) { 'hello' }
|
||||
|
||||
it { expect(subject).to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -843,7 +843,7 @@ describe NewUser::DossiersController, type: :controller do
|
|||
let(:dossier) { create(:dossier, :en_instruction, user: user, autorisation_donnees: true) }
|
||||
|
||||
it_behaves_like "the dossier can not be deleted"
|
||||
it { is_expected.to redirect_to(users_dossier_path(dossier)) }
|
||||
it { is_expected.to redirect_to(dossier_path(dossier)) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -855,4 +855,63 @@ describe NewUser::DossiersController, type: :controller do
|
|||
it { is_expected.to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#new' do
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
subject { get :new, params: { procedure_id: procedure_id } }
|
||||
|
||||
context 'when params procedure_id is present' do
|
||||
context 'when procedure_id is valid' do
|
||||
context 'when user is logged in' do
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
|
||||
|
||||
it { expect { subject }.to change(Dossier, :count).by 1 }
|
||||
|
||||
context 'when procedure is archived' do
|
||||
let(:procedure) { create(:procedure, :archived) }
|
||||
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
end
|
||||
end
|
||||
context 'when user is not logged' do
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure_id is not valid' do
|
||||
let(:procedure_id) { 0 }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
end
|
||||
|
||||
context 'when procedure is not published' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
|
||||
context 'and brouillon param is passed' do
|
||||
subject { get :new, params: { procedure_id: procedure_id, brouillon: true } }
|
||||
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Users::DossiersController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
describe 'GET #new' do
|
||||
subject { get :new, params: { procedure_id: procedure_id } }
|
||||
|
||||
context 'when params procedure_id is present' do
|
||||
context 'when procedure_id is valid' do
|
||||
context 'when user is logged in' do
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
|
||||
|
||||
it { expect { subject }.to change(Dossier, :count).by 1 }
|
||||
|
||||
context 'when procedure is archived' do
|
||||
let(:procedure) { create(:procedure, :archived) }
|
||||
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
end
|
||||
end
|
||||
context 'when user is not logged' do
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure_id is not valid' do
|
||||
let(:procedure_id) { 0 }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
end
|
||||
|
||||
context 'when procedure is not published' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
|
||||
context 'and brouillon param is passed' do
|
||||
subject { get :new, params: { procedure_id: procedure_id, brouillon: true } }
|
||||
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to siret_dossier_path(id: Dossier.last) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #commencer' do
|
||||
subject { get :commencer, params: { path: path } }
|
||||
let(:path) { procedure.path }
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
|
||||
|
||||
context 'when procedure path does not exist' do
|
||||
let(:path) { 'hello' }
|
||||
|
||||
it { expect(subject).to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #commencer_test' do
|
||||
before do
|
||||
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
|
||||
end
|
||||
|
||||
subject { get :commencer_test, params: { path: path } }
|
||||
let(:procedure) { create(:procedure, :with_path) }
|
||||
let(:path) { procedure.path }
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true) }
|
||||
|
||||
context 'when procedure path does not exist' do
|
||||
let(:path) { 'hello' }
|
||||
|
||||
it { expect(subject).to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,25 +10,6 @@ describe UserRoutesAuthorizationService do
|
|||
|
||||
subject { described_class.authorized_route? controller, dossier }
|
||||
|
||||
describe 'Users::DossiersController' do
|
||||
let(:controller) { Users::DossiersController }
|
||||
|
||||
describe 'brouillon' do
|
||||
let(:state) { Dossier.states.fetch(:brouillon) }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
describe 'en_construction' do
|
||||
let(:state) { Dossier.states.fetch(:en_construction) }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
describe 'accepte' do
|
||||
let(:state) { Dossier.states.fetch(:accepte) }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'carte' do
|
||||
let(:controller) { Users::CarteController }
|
||||
|
||||
|
|
Loading…
Reference in a new issue