[Fix #1149] Move avis actions to new gestionnaire controller
This commit is contained in:
parent
aba59239ca
commit
04e9f7be3e
8 changed files with 170 additions and 167 deletions
|
@ -1,7 +1,5 @@
|
|||
class Backoffice::AvisController < ApplicationController
|
||||
before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire]
|
||||
before_action :redirect_if_no_sign_up_needed, only: [:sign_up]
|
||||
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire]
|
||||
before_action :authenticate_gestionnaire!
|
||||
|
||||
def create
|
||||
avis = Avis.new(create_params.merge(claimant: current_gestionnaire, dossier: dossier, confidentiel: true))
|
||||
|
@ -22,30 +20,6 @@ class Backoffice::AvisController < ApplicationController
|
|||
redirect_to backoffice_dossier_path(avis.dossier_id)
|
||||
end
|
||||
|
||||
def sign_up
|
||||
@email = params[:email]
|
||||
@dossier = Avis.includes(:dossier).find(params[:id]).dossier
|
||||
|
||||
render layout: 'new_application'
|
||||
end
|
||||
|
||||
def create_gestionnaire
|
||||
email = params[:email]
|
||||
password = params['gestionnaire']['password']
|
||||
|
||||
gestionnaire = Gestionnaire.new(email: email, password: password)
|
||||
|
||||
if gestionnaire.save
|
||||
sign_in(gestionnaire, scope: :gestionnaire)
|
||||
Avis.link_avis_to_gestionnaire(gestionnaire)
|
||||
avis = Avis.find(params[:id])
|
||||
redirect_to url_for(avis_index_path)
|
||||
else
|
||||
flash[:alert] = gestionnaire.errors.full_messages
|
||||
redirect_to url_for(avis_sign_up_path(params[:id], email))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
|
@ -63,24 +37,4 @@ class Backoffice::AvisController < ApplicationController
|
|||
def update_params
|
||||
params.require(:avis).permit(:answer)
|
||||
end
|
||||
|
||||
def redirect_if_no_sign_up_needed
|
||||
avis = Avis.find(params[:id])
|
||||
|
||||
if current_gestionnaire.present?
|
||||
# a gestionnaire is authenticated ... lets see if it can view the dossier
|
||||
|
||||
redirect_to backoffice_dossier_url(avis.dossier)
|
||||
elsif avis.gestionnaire.present? && avis.gestionnaire.email == params[:email]
|
||||
# the avis gestionnaire has already signed up and it sould sign in
|
||||
|
||||
redirect_to new_gestionnaire_session_url
|
||||
end
|
||||
end
|
||||
|
||||
def check_avis_exists_and_email_belongs_to_avis
|
||||
if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email])
|
||||
redirect_to url_for(root_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
module NewGestionnaire
|
||||
class AvisController < GestionnaireController
|
||||
before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire]
|
||||
before_action :redirect_if_no_sign_up_needed, only: [:sign_up]
|
||||
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire]
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
|
||||
|
||||
A_DONNER_STATUS = 'a-donner'
|
||||
|
@ -56,6 +59,30 @@ module NewGestionnaire
|
|||
redirect_to instruction_avis_path(avis)
|
||||
end
|
||||
|
||||
def sign_up
|
||||
@email = params[:email]
|
||||
@dossier = Avis.includes(:dossier).find(params[:id]).dossier
|
||||
|
||||
render layout: 'new_application'
|
||||
end
|
||||
|
||||
def create_gestionnaire
|
||||
email = params[:email]
|
||||
password = params['gestionnaire']['password']
|
||||
|
||||
gestionnaire = Gestionnaire.new(email: email, password: password)
|
||||
|
||||
if gestionnaire.save
|
||||
sign_in(gestionnaire, scope: :gestionnaire)
|
||||
Avis.link_avis_to_gestionnaire(gestionnaire)
|
||||
avis = Avis.find(params[:id])
|
||||
redirect_to url_for(avis_index_path)
|
||||
else
|
||||
flash[:alert] = gestionnaire.errors.full_messages
|
||||
redirect_to url_for(sign_up_avis_path(params[:id], email))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_avis_and_dossier
|
||||
|
@ -63,6 +90,26 @@ module NewGestionnaire
|
|||
@dossier = avis.dossier
|
||||
end
|
||||
|
||||
def redirect_if_no_sign_up_needed
|
||||
avis = Avis.find(params[:id])
|
||||
|
||||
if current_gestionnaire.present?
|
||||
# a gestionnaire is authenticated ... lets see if it can view the dossier
|
||||
|
||||
redirect_to avis_url(avis)
|
||||
elsif avis.gestionnaire.present? && avis.gestionnaire.email == params[:email]
|
||||
# the avis gestionnaire has already signed up and it sould sign in
|
||||
|
||||
redirect_to new_gestionnaire_session_url
|
||||
end
|
||||
end
|
||||
|
||||
def check_avis_exists_and_email_belongs_to_avis
|
||||
if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email])
|
||||
redirect_to url_for(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
def avis
|
||||
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue