2018-04-18 12:16:25 +02:00
|
|
|
module Flipflop::Strategies
|
|
|
|
class UserPreferenceStrategy < AbstractStrategy
|
|
|
|
def self.default_description
|
|
|
|
"Allows configuration of features per user."
|
|
|
|
end
|
|
|
|
|
|
|
|
def switchable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def enabled?(feature)
|
2019-03-06 15:21:10 +01:00
|
|
|
find_current_administrateur&.feature_enabled?(feature) ||
|
|
|
|
find_current_gestionnaire&.feature_enabled?(feature)
|
2018-04-18 12:16:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_current_administrateur
|
2019-03-06 15:21:10 +01:00
|
|
|
administrateur_id = Current.administrateur&.id
|
|
|
|
if administrateur_id
|
2018-04-18 12:16:25 +02:00
|
|
|
Administrateur.find_by(id: administrateur_id)
|
|
|
|
end
|
|
|
|
end
|
2019-03-06 15:21:10 +01:00
|
|
|
|
|
|
|
def find_current_gestionnaire
|
|
|
|
gestionnaire_id = Current.gestionnaire&.id
|
|
|
|
if gestionnaire_id
|
|
|
|
Gestionnaire.find_by(id: gestionnaire_id)
|
|
|
|
end
|
|
|
|
end
|
2018-04-18 12:16:25 +02:00
|
|
|
end
|
|
|
|
end
|