Skip to content

Commit 42e2013

Browse files
committed
Add a short helper method for checking features enabled
1 parent fa0df60 commit 42e2013

36 files changed

+98
-96
lines changed

app/controllers/application_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ def job_status
9696

9797
private
9898

99-
def feature_enabled?(feature = controller_name)
99+
def feature_enabled?(feature)
100+
Space.current_space.feature_enabled?(feature)
101+
end
102+
103+
helper_method :feature_enabled?
104+
105+
def ensure_feature_enabled(feature = controller_name)
100106
if TeSS::Config.feature.key?(feature) && !TeSS::Config.feature[feature]
101107
raise ActionController::RoutingError.new('Feature not enabled')
102108
end

app/controllers/bioschemas_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class BioschemasController < ApplicationController
2-
before_action -> { feature_enabled?('bioschemas_testing') }
2+
before_action -> { ensure_feature_enabled('bioschemas_testing') }
33

44
def test
55

app/controllers/collections_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The controller for actions related to the Collection model
22
class CollectionsController < ApplicationController
3-
before_action :feature_enabled?
3+
before_action :ensure_feature_enabled
44
before_action :set_collection, only: %i[show edit curate update_curation add_item remove_item update destroy]
55
before_action :set_breadcrumbs
66

app/controllers/communities_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def show
88
@resources = []
99
if TeSS::Config.solr_enabled
1010
enabled = []
11-
enabled.append(Event) if Space.current_space.feature_enabled?('events')
12-
enabled.append(Material) if Space.current_space.feature_enabled?('materials')
13-
enabled.append(Collection) if Space.current_space.feature_enabled?('collections')
11+
enabled.append(Event) if feature_enabled?('events')
12+
enabled.append(Material) if feature_enabled?('materials')
13+
enabled.append(Collection) if feature_enabled?('collections')
1414
enabled.each do |resource|
1515
@resources += resource.search_and_filter(nil, '', { 'max_age' => '1 month' },
1616
sort_by: 'new', per_page: 5).results

app/controllers/content_providers_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The controller for actions related to the Content Providers model
22
class ContentProvidersController < ApplicationController
3-
before_action -> { feature_enabled?('content_providers') }
3+
before_action :ensure_feature_enabled
44
before_action :set_content_provider, only: %i[show edit update destroy]
55
before_action :set_breadcrumbs
66

app/controllers/events_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# The controller for actions related to the Events model
44
class EventsController < ApplicationController
5-
before_action :feature_enabled?
5+
before_action :ensure_feature_enabled
66
before_action :set_event, only: %i[show edit clone update destroy update_collections add_term reject_term
77
redirect report update_report add_data reject_data]
88
before_action :set_breadcrumbs

app/controllers/learning_path_topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class LearningPathTopicsController < ApplicationController
2-
before_action -> { feature_enabled?('learning_paths') }
2+
before_action -> { ensure_feature_enabled('learning_paths') }
33
before_action :set_topic, only: %i[show edit update destroy]
44
before_action :set_breadcrumbs
55

app/controllers/learning_paths_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class LearningPathsController < ApplicationController
2-
before_action :feature_enabled?
2+
before_action :ensure_feature_enabled
33
before_action :set_learning_path, only: [:show, :edit, :update, :destroy]
44
before_action :set_breadcrumbs
55

app/controllers/materials_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The controller for actions related to the Materials model
22
class MaterialsController < ApplicationController
3-
before_action :feature_enabled?
3+
before_action :ensure_feature_enabled
44
before_action :set_material, only: %i[show edit update destroy update_collections clone
55
add_term reject_term add_data reject_data]
66
before_action :set_breadcrumbs
@@ -17,7 +17,7 @@ class MaterialsController < ApplicationController
1717
# GET /materials.json?q=queryparam
1818

1919
def index
20-
elearning = @facet_params[:resource_type] == 'e-learning' && Space.current_space.feature_enabled?('elearning_materials')
20+
elearning = @facet_params[:resource_type] == 'e-learning' && feature_enabled?('elearning_materials')
2121
@bioschemas = @materials.flat_map(&:to_bioschemas)
2222
respond_to do |format|
2323
format.html { render elearning ? 'elearning_materials/index' : 'index' }

app/controllers/nodes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The controller for actions related to the Nodes model
22
class NodesController < ApplicationController
3-
before_action :feature_enabled?
3+
before_action :ensure_feature_enabled
44
before_action :set_node, only: [:show, :edit, :update, :destroy]
55
before_action :set_breadcrumbs
66

0 commit comments

Comments
 (0)