Simplify route_authorization

This commit is contained in:
gregoirenovel 2018-08-28 14:12:48 +02:00
parent bf9f3b40df
commit 47962ef795
4 changed files with 10 additions and 4 deletions

View file

@ -59,7 +59,7 @@ class Users::CarteController < UsersController
def self.route_authorization
{
states: [:brouillon, :en_construction],
states: [Dossier.states.fetch(:brouillon), Dossier.states.fetch(:en_construction)],
api_carto: true
}
end

View file

@ -149,7 +149,7 @@ class Users::DossiersController < UsersController
def self.route_authorization
{
states: [:brouillon]
states: [Dossier.states.fetch(:brouillon)]
}
end

View file

@ -18,7 +18,13 @@ class Users::RecapitulatifController < UsersController
def self.route_authorization
{
states: [:en_construction, :en_instruction, :sans_suite, :accepte, :refuse]
states: [
Dossier.states.fetch(:en_construction),
Dossier.states.fetch(:en_instruction),
Dossier.states.fetch(:sans_suite),
Dossier.states.fetch(:accepte),
Dossier.states.fetch(:refuse)
]
}
end

View file

@ -2,7 +2,7 @@ class UserRoutesAuthorizationService
def self.authorized_route?(controller, dossier)
auth = controller.route_authorization
auth[:states].include?(dossier.state.to_sym) &&
auth[:states].include?(dossier.state) &&
(auth[:api_carto].nil? ? true : auth[:api_carto] == dossier.procedure.use_api_carto)
end
end