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) ||
|
2019-08-06 11:02:54 +02:00
|
|
|
find_current_instructeur&.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
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
def find_current_instructeur
|
|
|
|
instructeur_id = Current.instructeur&.id
|
|
|
|
if instructeur_id
|
|
|
|
Instructeur.find_by(id: instructeur_id)
|
2019-03-06 15:21:10 +01:00
|
|
|
end
|
|
|
|
end
|
2018-04-18 12:16:25 +02:00
|
|
|
end
|
|
|
|
end
|