diff --git a/app/models/material.rb b/app/models/material.rb index c99ea659a..31382f26e 100644 --- a/app/models/material.rb +++ b/app/models/material.rb @@ -142,6 +142,14 @@ def self.facet_fields field_list end + def self.not_disabled + where(visible: true) + end + + def self.disabled + where(visible: false) + end + def self.check_exists(material_params) given_material = material_params.is_a?(Material) ? material_params : new(material_params) material = nil diff --git a/app/views/content_providers/_content_provider.html.erb b/app/views/content_providers/_content_provider.html.erb index a90139c39..78ba2b857 100644 --- a/app/views/content_providers/_content_provider.html.erb +++ b/app/views/content_providers/_content_provider.html.erb @@ -10,7 +10,7 @@ <% if content_provider.materials.length > 0 %> -
<%= pluralize(content_provider.materials.length, 'training material') %>
+
<%= pluralize(content_provider.materials.not_disabled.length, 'training material') %>
<% end %> <% if content_provider.events.length > 0 %> diff --git a/app/views/content_providers/show.html.erb b/app/views/content_providers/show.html.erb index 8d4cd1509..9b8db168d 100644 --- a/app/views/content_providers/show.html.erb +++ b/app/views/content_providers/show.html.erb @@ -21,8 +21,8 @@
<% resource_limit = 30 %> - <% materials = @content_provider.materials.from_verified_users.limit(resource_limit) %> - <% materials_count = @content_provider.materials.from_verified_users.count %> + <% materials = @content_provider.materials.from_verified_users.not_disabled.limit(resource_limit) %> + <% materials_count = @content_provider.materials.from_verified_users.not_disabled.count %> <% upcoming_events = @content_provider.events.from_verified_users.not_finished.not_disabled.order(start: :asc) %> <% past_events = @content_provider.events.from_verified_users.finished.not_disabled %> <% events = upcoming_events.limit(resource_limit) %> diff --git a/lib/facets.rb b/lib/facets.rb index bfc45e3f0..98f11142a 100644 --- a/lib/facets.rb +++ b/lib/facets.rb @@ -1,7 +1,7 @@ module Facets SPECIAL = { include_expired: ->(c) { c.name == 'Event' }, - include_disabled: ->(c) { c.name == 'Event' }, + include_disabled: ->(c) { c.name == 'Event' || c.name == 'Material' }, include_archived: ->(c) { c.name == 'Material' || c.name == 'LearningPath' }, days_since_scrape: ->(c) { c.method_defined?(:last_scraped) }, elixir: ->(c) { %w[Event Material ContentProvider].include?(c.name) }, diff --git a/test/controllers/content_providers_controller_test.rb b/test/controllers/content_providers_controller_test.rb index 1f897abef..c46ff2a19 100644 --- a/test/controllers/content_providers_controller_test.rb +++ b/test/controllers/content_providers_controller_test.rb @@ -582,4 +582,18 @@ class ContentProvidersControllerTest < ActionController::TestCase get :show, params: { id: content_provider } assert_response :forbidden end + + test 'should hide disabled materials on content provider page' do + new_material = Material.create!(title: 'my_material', description: 'visible material', url: 'http://new.url.com', content_provider: @content_provider, user: @content_provider.user) + get :show, params: { id: @content_provider } + assert_response :success + assert_select '.search-results-count.my-3', text: 'Showing 10 materials' + assert_select '.masonry-brick-heading h4', text: 'my_material' + new_material.visible = false + new_material.save! + get :show, params: { id: @content_provider } + assert_response :success + assert_select '.search-results-count.my-3', text: 'Showing 9 materials' + assert_select '.masonry-brick-heading h4', text: 'my_material', count: 0 + end end