demarches-normaliennes/app/controllers/users_controller.rb
2018-01-12 11:32:43 +01:00

32 lines
863 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class UsersController < ApplicationController
before_action :authenticate_user!
def index
redirect_to root_path
end
def current_user_dossier dossier_id=nil
dossier_id ||= params[:dossier_id] || params[:id]
dossier = Dossier.find(dossier_id)
return dossier if dossier.owner?(current_user.email) || dossier.invite_by_user?(current_user.email)
raise ActiveRecord::RecordNotFound
end
def authorized_routes? controller
redirect_to_root_path 'Le statut de votre dossier n\'autorise pas cette URL' if !UserRoutesAuthorizationService.authorized_route?(
controller,
current_user_dossier)
rescue ActiveRecord::RecordNotFound
redirect_to_root_path 'Vous navez pas accès à ce dossier.'
end
private
def redirect_to_root_path message
flash.alert = message
redirect_to url_for root_path
end
end