Merge pull request #1878 from tchak/enable-features-fom-manager

Enable features fom manager
This commit is contained in:
Paul Chavard 2018-04-26 16:35:15 +02:00 committed by GitHub
commit b1fd9b4d52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 28 deletions

View file

@ -19,6 +19,20 @@ module Manager
redirect_to manager_administrateur_path(params[:id])
end
def enable_feature
administrateur = Administrateur.find(params[:id])
params[:features].each do |key, enable|
if enable
administrateur.enable_feature(key.to_sym)
else
administrateur.disable_feature(key.to_sym)
end
end
head :ok
end
private
def create_administrateur_params

View file

@ -11,29 +11,12 @@ module Flipflop::Strategies
def enabled?(feature)
# Can only check features if we have the user's session.
if request?
legacy_enabled?(feature) || find_current_administrateur&.feature_enabled?(feature)
find_current_administrateur&.feature_enabled?(feature)
end
end
private
def legacy_enabled?(feature)
if self.class.legacy_features_map.present?
ids = self.class.legacy_features_map["#{feature}_allowed_for_admin_ids"]
ids.present? && find_current_administrateur&.id&.in?(ids)
end
end
LEGACY_CONFIG_FILE = Rails.root.join("config", "initializers", "features.yml")
def self.legacy_features_map
@@legacy_features_map = begin
if File.exist?(LEGACY_CONFIG_FILE)
YAML.load_file(LEGACY_CONFIG_FILE)
end
end
end
def find_current_administrateur
if request.session["warden.user.administrateur.key"]
administrateur_id = request.session["warden.user.administrateur.key"][0][0]

View file

@ -1,7 +1,26 @@
%table
%table#features
- Flipflop.feature_set.features.each do |feature|
- if !feature.group || feature.group.key != :production
%tr
%td= feature.title
%td
= check_box_tag "Enabled", "enabled", field.data[feature.name], disabled: true
= check_box_tag "enable-feature", "enable", field.data[feature.name], data: { url: enable_feature_manager_administrateur_path(field.resource.id), key: feature.key }
:javascript
window.onload = function() {
$('#features input[type=checkbox]').on('change', function(evt) {
let url = $(evt.target).data('url');
let key = $(evt.target).data('key');
let features = {};
features[key] = $(evt.target).prop('checked');
$.ajax(url, {
method: 'put',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify({
features: features
})
});
});
};

View file

@ -1,8 +0,0 @@
remote_storage: false
weekly_overview: false
champ_pj_allowed_for_admin_ids:
- 0
champ_siret_allowed_for_admin_ids:
- 0
web_hook_allowed_for_admin_ids:
- 0

View file

@ -8,6 +8,7 @@ Rails.application.routes.draw do
resources :administrateurs, only: [:index, :show, :new, :create] do
post 'reinvite', on: :member
put 'enable_feature', on: :member
end
resources :demandes, only: [:index]