add expert logic
This commit is contained in:
parent
3cfbe38a8b
commit
d2ab2debb6
15 changed files with 311 additions and 3 deletions
|
@ -20,7 +20,7 @@ class ApplicationController < ActionController::Base
|
|||
before_action :setup_tracking
|
||||
before_action :set_locale
|
||||
|
||||
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur,
|
||||
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur, :current_expert, :expert_signed_in?,
|
||||
:administrateur_signed_in?, :current_administrateur, :current_account
|
||||
|
||||
def staging_authenticate
|
||||
|
@ -32,7 +32,9 @@ class ApplicationController < ActionController::Base
|
|||
def multiple_devise_profile_connect?
|
||||
user_signed_in? && instructeur_signed_in? ||
|
||||
instructeur_signed_in? && administrateur_signed_in? ||
|
||||
user_signed_in? && administrateur_signed_in?
|
||||
instructeur_signed_in? && expert_signed_in? ||
|
||||
user_signed_in? && administrateur_signed_in? ||
|
||||
user_signed_in? && expert_signed_in?
|
||||
end
|
||||
|
||||
def current_instructeur
|
||||
|
@ -51,6 +53,14 @@ class ApplicationController < ActionController::Base
|
|||
current_administrateur.present?
|
||||
end
|
||||
|
||||
def current_expert
|
||||
current_user&.expert
|
||||
end
|
||||
|
||||
def expert_signed_in?
|
||||
current_expert.present?
|
||||
end
|
||||
|
||||
def current_account
|
||||
{
|
||||
administrateur: current_administrateur,
|
||||
|
@ -70,6 +80,8 @@ class ApplicationController < ActionController::Base
|
|||
def authenticate_logged_user!
|
||||
if instructeur_signed_in?
|
||||
authenticate_instructeur!
|
||||
elsif expert_signed_in?
|
||||
authenticate_expert!
|
||||
elsif administrateur_signed_in?
|
||||
authenticate_administrateur!
|
||||
else
|
||||
|
@ -83,6 +95,12 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def authenticate_expert!
|
||||
if !expert_signed_in?
|
||||
redirect_to new_user_session_path
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_administrateur!
|
||||
if !administrateur_signed_in?
|
||||
redirect_to new_user_session_path
|
||||
|
|
59
app/controllers/experts/avis_controller.rb
Normal file
59
app/controllers/experts/avis_controller.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Experts
|
||||
class AvisController < ExpertController
|
||||
include CreateAvisConcern
|
||||
|
||||
before_action :authenticate_expert!, except: [:sign_up, :create_instructeur]
|
||||
before_action :check_if_avis_revoked, only: [:show]
|
||||
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_instructeur]
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire, :update]
|
||||
|
||||
A_DONNER_STATUS = 'a-donner'
|
||||
DONNES_STATUS = 'donnes'
|
||||
|
||||
def index
|
||||
avis = current_expert.avis.includes(dossier: [groupe_instructeur: :procedure])
|
||||
@avis_by_procedure = avis.to_a.group_by(&:procedure)
|
||||
end
|
||||
|
||||
def procedure
|
||||
@procedure = Procedure.find(params[:procedure_id])
|
||||
expert_avis = current_expert.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) })
|
||||
@avis_a_donner = expert_avis.without_answer
|
||||
@avis_donnes = expert_avis.with_answer
|
||||
|
||||
@statut = params[:statut].presence || A_DONNER_STATUS
|
||||
|
||||
@avis = case @statut
|
||||
when A_DONNER_STATUS
|
||||
@avis_a_donner
|
||||
when DONNES_STATUS
|
||||
@avis_donnes
|
||||
end
|
||||
|
||||
@avis = @avis.page([params[:page].to_i, 1].max)
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def instruction
|
||||
@new_avis = Avis.new
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_if_avis_revoked
|
||||
avis = Avis.find(params[:id])
|
||||
if avis.revoked?
|
||||
flash.alert = "Vous n'avez plus accès à ce dossier."
|
||||
redirect_to url_for(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
def set_avis_and_dossier
|
||||
@avis = Avis.find(params[:id])
|
||||
@dossier = @avis.dossier
|
||||
end
|
||||
end
|
||||
end
|
9
app/controllers/experts/expert_controller.rb
Normal file
9
app/controllers/experts/expert_controller.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Experts
|
||||
class ExpertController < ApplicationController
|
||||
before_action :authenticate_expert!
|
||||
|
||||
def nav_bar_profile
|
||||
:expert
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,6 @@
|
|||
module Instructeurs
|
||||
class ProceduresController < InstructeurController
|
||||
before_action :ensure_ownership!, except: [:index]
|
||||
before_action :redirect_to_avis_if_needed, only: [:index]
|
||||
|
||||
ITEMS_PER_PAGE = 25
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue