Skip to content
8 changes: 7 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ def job_status

private

def feature_enabled?(feature = controller_name)
def feature_enabled?(feature)
Space.current_space.feature_enabled?(feature)
end

helper_method :feature_enabled?

def ensure_feature_enabled(feature = controller_name)
if TeSS::Config.feature.key?(feature) && !TeSS::Config.feature[feature]
raise ActionController::RoutingError.new('Feature not enabled')
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bioschemas_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class BioschemasController < ApplicationController
before_action -> { feature_enabled?('bioschemas_testing') }
before_action -> { ensure_feature_enabled('bioschemas_testing') }

def test

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Collection model
class CollectionsController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_collection, only: %i[show edit curate update_curation add_item remove_item update destroy]
before_action :set_breadcrumbs

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def show
@resources = []
if TeSS::Config.solr_enabled
enabled = []
enabled.append(Event) if TeSS::Config.feature['events']
enabled.append(Material) if TeSS::Config.feature['materials']
enabled.append(Collection) if TeSS::Config.feature['collections']
enabled.append(Event) if feature_enabled?('events')
enabled.append(Material) if feature_enabled?('materials')
enabled.append(Collection) if feature_enabled?('collections')
enabled.each do |resource|
@resources += resource.search_and_filter(nil, '', { 'max_age' => '1 month' },
sort_by: 'new', per_page: 5).results
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/content_providers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Content Providers model
class ContentProvidersController < ApplicationController
before_action -> { feature_enabled?('content_providers') }
before_action :ensure_feature_enabled
before_action :set_content_provider, only: %i[show edit update destroy]
before_action :set_breadcrumbs

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# The controller for actions related to the Events model
class EventsController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_event, only: %i[show edit clone update destroy update_collections add_term reject_term
redirect report update_report add_data reject_data]
before_action :set_breadcrumbs
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/learning_path_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LearningPathTopicsController < ApplicationController
before_action -> { feature_enabled?('learning_paths') }
before_action -> { ensure_feature_enabled('learning_paths') }
before_action :set_topic, only: %i[show edit update destroy]
before_action :set_breadcrumbs

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/learning_paths_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LearningPathsController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_learning_path, only: [:show, :edit, :update, :destroy]
before_action :set_breadcrumbs

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/materials_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Materials model
class MaterialsController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_material, only: %i[show edit update destroy update_collections clone
add_term reject_term add_data reject_data]
before_action :set_breadcrumbs
Expand All @@ -17,7 +17,7 @@ class MaterialsController < ApplicationController
# GET /materials.json?q=queryparam

def index
elearning = @facet_params[:resource_type] == 'e-learning' && TeSS::Config.feature['elearning_materials']
elearning = @facet_params[:resource_type] == 'e-learning' && feature_enabled?('elearning_materials')
@bioschemas = @materials.flat_map(&:to_bioschemas)
respond_to do |format|
format.html { render elearning ? 'elearning_materials/index' : 'index' }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Nodes model
class NodesController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_node, only: [:show, :edit, :update, :destroy]
before_action :set_breadcrumbs

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def search_params
def search_models
return @_models if @_models
@_models = ['User']
@_models << 'Event' if TeSS::Config.feature['events']
@_models << 'Material' if TeSS::Config.feature['materials']
@_models << 'Collection' if TeSS::Config.feature['collections']
@_models << 'ContentProvider' if TeSS::Config.feature['content_providers']
@_models << 'Trainer' if TeSS::Config.feature['trainers']
@_models << 'Event' if feature_enabled?('events')
@_models << 'Material' if feature_enabled?('materials')
@_models << 'Collection' if feature_enabled?('collections')
@_models << 'ContentProvider' if feature_enabled?('content_providers')
@_models << 'Trainer' if feature_enabled?('trainers')
@_models
end
end
4 changes: 2 additions & 2 deletions app/controllers/spaces_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Spaces model
class SpacesController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_space, only: [:show, :edit, :update, :destroy]
before_action :set_breadcrumbs

Expand Down Expand Up @@ -76,7 +76,7 @@ def set_space
end

def space_params
permitted = [:title, :description, :theme, :image, :image_url, { administrator_ids: [] }]
permitted = [:title, :description, :theme, :image, :image_url, { administrator_ids: [] }, { enabled_features: [] }]
permitted += [:host] if current_user.is_admin?
params.require(:space).permit(*permitted)
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def home
@resources = []
if TeSS::Config.solr_enabled
enabled = []
enabled.append(Event) if TeSS::Config.feature['events']
enabled.append(Material) if TeSS::Config.feature['materials']
enabled.append(Collection) if TeSS::Config.feature['collections']
enabled.append(Event) if feature_enabled?('events')
enabled.append(Material) if feature_enabled?('materials')
enabled.append(Collection) if feature_enabled?('collections')
enabled.each do |resource|
@resources += resource.search_and_filter(nil, '', { 'max_age' => '1 month' },
sort_by: 'new', per_page: 5).results
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/trainers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Profiles model
class TrainersController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled
before_action :set_trainer, only: [:show]
before_action :set_breadcrumbs

Expand Down
6 changes: 1 addition & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# The controller for actions related to the Users model
class UsersController < ApplicationController
before_action -> { feature_enabled?('invitation') }, only: [:invitees]
before_action -> { ensure_feature_enabled('invitation') }, only: [:invitees]
prepend_before_action :set_user, only: %i[show edit update destroy change_token]
prepend_before_action :init_user, only: [:create]
before_action :set_breadcrumbs
Expand Down Expand Up @@ -139,10 +139,6 @@ def user_params
params.require(:user).permit(allowed_parameters)
end

def invitees_enabled?
feature_enabled?('invitation')
end

# Prevent assigning other profiles
def check_profile_id
profile_id = @user.profile.id
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workflows_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for actions related to the Workflows model
class WorkflowsController < ApplicationController
before_action :feature_enabled?
before_action :ensure_feature_enabled

layout 'application'

Expand Down
8 changes: 8 additions & 0 deletions app/helpers/spaces_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ module SpacesHelper
def spaces_info
I18n.t('info.spaces.description')
end

def space_feature_options
Space::FEATURES.select do |f|
TeSS::Config.feature[f]
end.map do |f|
[t("features.#{f}.short"), f]
end
end
end
4 changes: 4 additions & 0 deletions app/models/default_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ def default?
def administrators
User.with_role('admin')
end

def feature_enabled?(feature)
TeSS::Config.feature[feature]
end
end
4 changes: 2 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def self.facet_fields
field_list.delete('sponsors') if TeSS::Config.feature['disabled'].include? 'sponsors'
field_list.delete('tools') if TeSS::Config.feature['disabled'].include? 'biotools'
field_list.delete('fields') if TeSS::Config.feature['disabled'].include? 'ardc_fields_of_research'
field_list.delete('node') unless TeSS::Config.feature['nodes']
field_list.delete('collections') unless TeSS::Config.feature['collections']
field_list.delete('node') unless Space.current_space.feature_enabled?('nodes')
field_list.delete('collections') unless Space.current_space.feature_enabled?('collections')
field_list.delete('organizer') unless TeSS::Config.feature['organizer']
field_list.delete('contact') unless TeSS::Config.feature['contact']

Expand Down
2 changes: 1 addition & 1 deletion app/models/learning_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def self.facet_fields
difficulty_level licence target_audience authors contributors user node status)

field_list.delete('scientific_topics') if TeSS::Config.feature['disabled'].include? 'topics'
field_list.delete('node') unless TeSS::Config.feature['nodes']
field_list.delete('node') unless Space.current_space.feature_enabled?('nodes')
field_list.delete('status') if TeSS::Config.feature['disabled'].include? 'status'

field_list
Expand Down
4 changes: 2 additions & 2 deletions app/models/material.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def self.facet_fields
field_list.delete('standard_database_or_policy') if TeSS::Config.feature['disabled'].include? 'fairshare'
field_list.delete('tools') if TeSS::Config.feature['disabled'].include? 'biotools'
field_list.delete('fields') if TeSS::Config.feature['disabled'].include? 'ardc_fields_of_research'
field_list.delete('node') unless TeSS::Config.feature['nodes']
field_list.delete('collections') unless TeSS::Config.feature['collections']
field_list.delete('node') unless Space.current_space.feature_enabled?('nodes')
field_list.delete('collections') unless Space.current_space.feature_enabled?('collections')
field_list.delete('status') if TeSS::Config.feature['disabled'].include? 'status'

field_list
Expand Down
2 changes: 1 addition & 1 deletion app/models/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def ingestor_class

def self.facet_fields
field_list = %w( content_provider node method enabled approval_status )
field_list.delete('node') unless TeSS::Config.feature['nodes']
field_list.delete('node') unless Space.current_space.feature_enabled?('nodes')
field_list
end

Expand Down
30 changes: 30 additions & 0 deletions app/models/space.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Space < ApplicationRecord
FEATURES = %w[events materials elearning_materials learning_paths workflows collections trainers content_providers nodes].freeze

include PublicActivity::Common
include LogParameterChanges

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

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

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

Expand Down Expand Up @@ -45,4 +48,31 @@ def default?
def users_with_role(role)
space_role_users.joins(:space_roles).where(space_roles: { key: role })
end

def feature_enabled?(feature)
if FEATURES.include?(feature)
TeSS::Config.feature[feature] && !disabled_features.include?(feature)
else
TeSS::Config.feature[feature]
end
end

def enabled_features= features
self.disabled_features = (FEATURES - features)
end

def enabled_features
(FEATURES - disabled_features)
end

private

def disabled_features_valid?
disabled_features.each do |feature|
next if feature.blank?
unless FEATURES.include?(feature)
errors.add(:disabled_features, :inclusion)
end
end
end
end
2 changes: 1 addition & 1 deletion app/views/about/_about_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ul>

<!-- REGISTERING YOUR LEARNING PATHS -->
<% if TeSS::Config.feature['learning_paths'] %>
<% if feature_enabled?('learning_paths') %>
<ul class="nav nav-stacked <%= show_active(show, 'learning_paths') %>">
<li class="about-page-category">
<%= link_to t('about.sidebar.learning_paths'), registering_learning_paths_path %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/about/_links.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="quick-links">
<%= link_to 'What is ' + TeSS::Config.site['title_short'] + '?', about_path, class: ('selected-tab' if show == 'tess') %>
| <%= link_to 'How to Register', registering_resources_path, class: ('selected-tab' if show == 'registering') %>
<% if TeSS::Config.feature['learning_paths'] %>
<% if feature_enabled?('learning_paths') %>
| <%= link_to 'Learning Paths', registering_learning_paths_path, class: ('selected-tab' if show == 'learning_paths') %>
<% end %>
| <%= link_to 'Developers Guide', developers_path, class: ('selected-tab' if show == 'developer') %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/about/developers.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@

<p>
<!-- Events -->
<% if TeSS::Config.feature['events'] %>
<% if feature_enabled?('events') %>
<code>
<a href="<%= TeSS::Config.base_url %><%== t 'developer.api_example_1' %>">
<%= TeSS::Config.base_url %><%== t 'developer.api_example_1' %></a>
</code><br/>
<% end %>

<!-- Materials -->
<% if TeSS::Config.feature['materials'] %>
<% if feature_enabled?('materials') %>
<code>
<a href="<%= TeSS::Config.base_url %><%== t 'developer.api_example_3' %>">
<%= TeSS::Config.base_url %><%== t 'developer.api_example_3' %> </a>
</code><br/>
<% end %>

<!-- Providers -->
<% if TeSS::Config.feature['content_providers'] %>
<% if feature_enabled?('content_providers') %>
<code>
<a href="<%= TeSS::Config.base_url %><%== t 'developer.api_example_4' %>">
<%= TeSS::Config.base_url %><%== t 'developer.api_example_4' %> </a>
</code><br/>
<% end %>

<!-- Workflows -->
<% if TeSS::Config.feature['workflows'] %>
<% if feature_enabled?('workflows') %>
<code>
<a href="<%= TeSS::Config.base_url %><%== t 'developer.api_example_5' %>">
<%= TeSS::Config.base_url %><%== t 'developer.api_example_5' %> </a>
Expand Down
6 changes: 3 additions & 3 deletions app/views/about/tess.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<% @feature_count = 0 %>

<!-- EVENTS-->
<% if TeSS::Config.feature['events'] == true %>
<% if feature_enabled?('events') %>
<div id="events" class="row <%= next_about_block(@feature_count += 1) %>">
<h3 class="col-lg-12"><%= t('about.headings.events') %></h3>
<div class="col-lg-2 col-lg-push-10 about-resource-icon">
Expand All @@ -59,7 +59,7 @@
<% end %>

<!-- MATERIALS-->
<% if TeSS::Config.feature['materials'] == true %>
<% if feature_enabled?('materials') %>
<div id="materials" class="row <%= next_about_block(@feature_count += 1) %>">
<h3 class="col-lg-12"><%= t('about.headings.materials') %></h3>

Expand All @@ -83,7 +83,7 @@
<% end %>

<!-- WORKFLOWS -->
<% if TeSS::Config.feature['workflows'] == true %>
<% if feature_enabled?('workflows') %>
<div id="workflows" class="row <%= next_about_block(@feature_count += 1) %>">
<h3 class="col-lg-12"><%= t('about.headings.workflows') %></h3>
<div class="col-lg-2 col-lg-push-10 about-resource-icon">
Expand Down
Loading