[#1677] Simplify code
This commit is contained in:
parent
c413dfa127
commit
cab670b1ad
1 changed files with 8 additions and 11 deletions
|
@ -1,16 +1,15 @@
|
||||||
class InvitesController < ApplicationController
|
class InvitesController < ApplicationController
|
||||||
before_action :gestionnaire_or_user?
|
before_action :ensure_user_signed_in
|
||||||
|
|
||||||
def create
|
def create
|
||||||
email_sender = @current_devise_profil.email
|
|
||||||
|
|
||||||
class_var = @current_devise_profil.class == User ? InviteUser : InviteGestionnaire
|
|
||||||
dossier = @current_devise_profil.dossiers.find(params[:dossier_id])
|
|
||||||
|
|
||||||
email = params[:email].downcase
|
email = params[:email].downcase
|
||||||
|
|
||||||
user = User.find_by(email: email)
|
invite = InviteUser.create(
|
||||||
invite = class_var.create(dossier: dossier, user: user, email: email, email_sender: email_sender)
|
dossier: current_user.dossiers.find(params[:dossier_id]),
|
||||||
|
user: User.find_by(email: email),
|
||||||
|
email: email,
|
||||||
|
email_sender: current_user.email
|
||||||
|
)
|
||||||
|
|
||||||
if invite.valid?
|
if invite.valid?
|
||||||
if invite.user.present?
|
if invite.user.present?
|
||||||
|
@ -29,11 +28,9 @@ class InvitesController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def gestionnaire_or_user?
|
def ensure_user_signed_in
|
||||||
if !user_signed_in?
|
if !user_signed_in?
|
||||||
return redirect_to root_path
|
return redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
@current_devise_profil = current_user if user_signed_in?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue