FlipFlop: enable for gestionnaire
This commit is contained in:
parent
457bc13c75
commit
36621bffeb
7 changed files with 51 additions and 4 deletions
|
@ -6,5 +6,19 @@ module Manager
|
|||
flash[:notice] = "Instructeur réinvité."
|
||||
redirect_to manager_gestionnaire_path(gestionnaire)
|
||||
end
|
||||
|
||||
def enable_feature
|
||||
gestionnaire = Gestionnaire.find(params[:id])
|
||||
|
||||
params[:features].each do |key, enable|
|
||||
if enable
|
||||
gestionnaire.enable_feature(key.to_sym)
|
||||
else
|
||||
gestionnaire.disable_feature(key.to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,8 @@ class GestionnaireDashboard < Administrate::BaseDashboard
|
|||
updated_at: Field::DateTime,
|
||||
current_sign_in_at: Field::DateTime,
|
||||
dossiers: Field::HasMany,
|
||||
procedures: Field::HasMany
|
||||
procedures: Field::HasMany,
|
||||
features: FeaturesField
|
||||
}.freeze
|
||||
|
||||
# COLLECTION_ATTRIBUTES
|
||||
|
@ -35,7 +36,8 @@ class GestionnaireDashboard < Administrate::BaseDashboard
|
|||
:id,
|
||||
:email,
|
||||
:current_sign_in_at,
|
||||
:created_at
|
||||
:created_at,
|
||||
:features
|
||||
].freeze
|
||||
|
||||
# FORM_ATTRIBUTES
|
||||
|
|
|
@ -205,6 +205,23 @@ class Gestionnaire < ApplicationRecord
|
|||
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
|
||||
end
|
||||
|
||||
def feature_enabled?(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features[feature.to_s]
|
||||
end
|
||||
|
||||
def disable_feature(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features.delete(feature.to_s)
|
||||
save
|
||||
end
|
||||
|
||||
def enable_feature(feature)
|
||||
Flipflop.feature_set.feature(feature)
|
||||
features[feature.to_s] = true
|
||||
save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def annotations_hash(demande, annotations_privees, avis, messagerie)
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
:ruby
|
||||
url = if field.resource.class.name == 'Gestionnaire'
|
||||
enable_feature_manager_gestionnaire_path(field.resource.id)
|
||||
else
|
||||
enable_feature_manager_administrateur_path(field.resource.id)
|
||||
end
|
||||
|
||||
%table#features
|
||||
- Flipflop.feature_set.features.each do |feature|
|
||||
- if !feature.group || feature.group.key != :production
|
||||
%tr
|
||||
%td= feature.title
|
||||
%td
|
||||
= check_box_tag "enable-feature", "enable", field.data[feature.name], data: { url: enable_feature_manager_administrateur_path(field.resource.id), key: feature.key }
|
||||
= check_box_tag "enable-feature", "enable", field.data[feature.name], data: { url: url, key: feature.key }
|
||||
|
|
|
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :gestionnaires, only: [:index, :show] do
|
||||
post 'reinvite', on: :member
|
||||
put 'enable_feature', on: :member
|
||||
end
|
||||
|
||||
resources :dossiers, only: [:show]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddFeaturesColumnToGestionnaires < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :gestionnaires, :features, :jsonb, null: false, default: {}
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_11_08_091339) do
|
||||
ActiveRecord::Schema.define(version: 2018_11_08_151929) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -367,6 +367,7 @@ ActiveRecord::Schema.define(version: 2018_11_08_091339) do
|
|||
t.datetime "updated_at"
|
||||
t.text "encrypted_login_token"
|
||||
t.datetime "login_token_created_at"
|
||||
t.jsonb "features", default: {}, null: false
|
||||
t.index ["email"], name: "index_gestionnaires_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue