Skip to content

Commit

Permalink
Merge pull request #1071 from DaanVanVugt/bugfix/material_disable
Browse files Browse the repository at this point in the history
do not show disabled materials on material index and provider show
  • Loading branch information
fbacall authored Dec 20, 2024
2 parents ad42e4a + f6ccfb0 commit 5bb5b1f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
8 changes: 8 additions & 0 deletions app/models/material.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_providers/_content_provider.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<% if content_provider.materials.length > 0 %>
<div><strong><%= pluralize(content_provider.materials.length, 'training material') %></strong></div>
<div><strong><%= pluralize(content_provider.materials.not_disabled.length, 'training material') %></strong></div>
<% end %>

<% if content_provider.events.length > 0 %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/content_providers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<div class="my-3">
<% 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) %>
Expand Down
2 changes: 1 addition & 1 deletion lib/facets.rb
Original file line number Diff line number Diff line change
@@ -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) },
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/content_providers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5bb5b1f

Please sign in to comment.