From e4cab6815ac87c11d1dd90a421669ce6626343c3 Mon Sep 17 00:00:00 2001 From: Richard Lences Date: Wed, 4 Dec 2024 21:15:28 +0100 Subject: [PATCH] show only available features --- app/controllers/admin/feature_flags_controller.rb | 12 ++++++++++-- app/models/tenant.rb | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index c52acfaf..3e48de7f 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -3,13 +3,21 @@ class Admin::FeatureFlagsController < ApplicationController def index authorize([:admin, :feature_flag]) - @feature_flags = @tenant.list_features + if params.include?(:labs) + @feature_flags = @tenant.list_all_features + else + @feature_flags = @tenant.list_available_features + end @enabled_features = @tenant.feature_flags end def update authorize([:admin, :feature_flag]) - @tenant.feature_flags = feature_flags_params[:enabled] == "true" ? @tenant.feature_flags.union([params[:id]]) : @tenant.feature_flags - [params[:id]] + if feature_flags_params[:enabled] == "true" + @tenant.feature_flags << params[:id] + else + @tenant.feature_flags.delete(params[:id]) + end @tenant.save! redirect_to admin_tenant_feature_flags_path end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 6f84e588..9ef42ec7 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -45,6 +45,7 @@ class Tenant < ApplicationRecord validates_presence_of :name AVAILABLE_FEATURE_FLAGS = [:audit_log, :archive, :api, :message_draft_import, :fs_api, :fs_sync] + ALL_FEATURE_FLAGS = [:audit_log, :archive, :api, :message_draft_import, :fs_api, :fs_sync] def draft_tag! draft_tag || raise(ActiveRecord::RecordNotFound, "`DraftTag` not found in tenant: #{id}") @@ -88,10 +89,14 @@ def disable_feature(feature) save! end - def list_features + def list_available_features AVAILABLE_FEATURE_FLAGS end + def list_all_features + ALL_FEATURE_FLAGS + end + def make_admins_see_everything! everything_tag.groups << admin_group end