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)
|
|
|
|
# Can only check features if we have the user's session.
|
|
|
|
if request?
|
2018-04-25 16:41:48 +02:00
|
|
|
find_current_administrateur&.feature_enabled?(feature)
|
2018-04-18 12:16:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_current_administrateur
|
2018-04-25 11:06:40 +02:00
|
|
|
if request.session["warden.user.administrateur.key"]
|
|
|
|
administrateur_id = request.session["warden.user.administrateur.key"][0][0]
|
2018-04-18 12:16:25 +02:00
|
|
|
Administrateur.find_by(id: administrateur_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|