Skip to content

Commit 206be22

Browse files
committed
Initial attempt at toggling features on/off in spaces. #1205
1 parent b962c9b commit 206be22

9 files changed

Lines changed: 52 additions & 3 deletions

File tree

app/controllers/spaces_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def set_space
7676
end
7777

7878
def space_params
79-
permitted = [:title, :description, :theme, :image, :image_url, { administrator_ids: [] }]
79+
permitted = [:title, :description, :theme, :image, :image_url, { administrator_ids: [] }, { enabled_features: [] }]
8080
permitted += [:host] if current_user.is_admin?
8181
params.require(:space).permit(*permitted)
8282
end

app/helpers/spaces_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ module SpacesHelper
33
def spaces_info
44
I18n.t('info.spaces.description')
55
end
6+
7+
def space_feature_options
8+
Space::FEATURES.map { |f| [t("features.#{f}.short"), f] }
9+
end
610
end

app/models/default_space.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ def default?
6060
def administrators
6161
User.with_role('admin')
6262
end
63+
64+
def feature_enabled?(feature)
65+
TeSS::Config.feature[feature]
66+
end
6367
end

app/models/space.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Space < ApplicationRecord
2+
FEATURES = %w[events materials elearning_materials learning_paths workflows collections trainers content_providers nodes].freeze
3+
24
include PublicActivity::Common
35
include LogParameterChanges
46

@@ -15,6 +17,7 @@ class Space < ApplicationRecord
1517
has_many :administrators, through: :administrator_roles, source: :user, class_name: 'User'
1618

1719
validates :theme, inclusion: { in: TeSS::Config.themes.keys, allow_blank: true }
20+
validate :disabled_features_valid?
1821

1922
has_image(placeholder: TeSS::Config.placeholder['content_provider'])
2023

@@ -45,4 +48,31 @@ def default?
4548
def users_with_role(role)
4649
space_role_users.joins(:space_roles).where(space_roles: { key: role })
4750
end
51+
52+
def feature_enabled?(feature)
53+
if FEATURES.include?(feature)
54+
!disabled_features.include?(feature)
55+
else
56+
TeSS::Config.feature[feature]
57+
end
58+
end
59+
60+
def enabled_features= features
61+
self.disabled_features = (FEATURES - features)
62+
end
63+
64+
def enabled_features
65+
(FEATURES - disabled_features)
66+
end
67+
68+
private
69+
70+
def disabled_features_valid?
71+
disabled_features.each do |feature|
72+
next if feature.blank?
73+
unless FEATURES.include?(feature)
74+
errors.add(:disabled_features, :inclusion)
75+
end
76+
end
77+
end
4878
end

app/views/layouts/_header.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{ feature: 'nodes', link: nodes_path },
5555
{ feature: 'spaces', link: spaces_path }
5656
].select do |t|
57-
t[:feature] == 'about' || TeSS::Config.feature[t[:feature]]
57+
t[:feature] == 'about' || Space.current_space.feature_enabled?(t[:feature])
5858
end.sort_by do |t|
5959
TeSS::Config.site['tab_order'].index(t[:feature]) || 99
6060
end

app/views/spaces/_form.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
id_field: :id,
2020
existing_items_method: :administrators %>
2121

22+
<div>
23+
<%= f.input :enabled_features, label: t('features.enabled'), collection: space_feature_options, as: :check_boxes %>
24+
</div>
25+
2226
<div class="form-group">
2327
<%= f.submit(class: 'btn btn-primary') %>
2428
<%= link_to t('.cancel', default: t("helpers.links.cancel")),

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
en:
22
features:
3+
enabled: Features enabled
34
about:
45
short: About
56
long: About
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddDisabledFeaturesToSpaces < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :spaces, :disabled_features, :string, array: true, default: []
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_12_01_143501) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_12_22_142740) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -511,6 +511,7 @@
511511
t.datetime "created_at", null: false
512512
t.datetime "updated_at", null: false
513513
t.text "image_url"
514+
t.string "disabled_features", default: [], array: true
514515
t.index ["host"], name: "index_spaces_on_host", unique: true
515516
t.index ["user_id"], name: "index_spaces_on_user_id"
516517
end

0 commit comments

Comments
 (0)