Skip to content

Commit

Permalink
show only available features
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlences committed Dec 4, 2024
1 parent 815bbca commit e4cab68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions app/controllers/admin/feature_flags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e4cab68

Please sign in to comment.