Skip to content

Commit 2e91dc1

Browse files
authored
Merge pull request #1177 from ElixirTeSS/copilot/add-filter-for-broken-links
Replace admin-only broken link filter with user-accessible sidebar toggle
2 parents 09989c7 + 69d742f commit 2e91dc1

5 files changed

Lines changed: 29 additions & 8 deletions

File tree

app/models/concerns/searchable.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ def search_and_filter(user, search_params = '', selected_facets = {}, page: 1, s
105105
facet ff, exclude: active_facets[ff]
106106
end
107107

108-
# Hide records the urls of which are failing
109-
if method_defined?(:link_monitor)
110-
unless user&.is_admin?
111-
without(:failing, true)
112-
end
113-
end
114-
115108
end
116109
end
117110
end

app/views/search/common/_facet_sidebar.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Variable that should be available
6363
count: '-',
6464
enable_text: t('sidebar.filter.values.show_disabled_events'),
6565
disable_text: t('sidebar.filter.values.hide_disabled_events') } %>
66+
<%= render partial: 'search/common/facet_sidebar_boolean_filter',
67+
locals: { facet_field: 'include_broken_links',
68+
count: '-',
69+
enable_text: t('sidebar.filter.values.show_broken_links', resource: resource_type.model_name.human.downcase.pluralize),
70+
disable_text: t('sidebar.filter.values.hide_broken_links', resource: resource_type.model_name.human.downcase.pluralize) } %>
6671
<% elsif resource_type.name == 'Material' || resource_type.name == 'LearningPath' %>
6772
<% resource_name = resource_type.model_name.human.downcase.pluralize %>
6873
<% if resource_type.name == 'Material' %>
@@ -71,6 +76,11 @@ Variable that should be available
7176
count: '-',
7277
enable_text: t('sidebar.filter.values.show_disabled', resource: resource_name),
7378
disable_text: t('sidebar.filter.values.hide_disabled', resource: resource_name) } %>
79+
<%= render partial: 'search/common/facet_sidebar_boolean_filter',
80+
locals: { facet_field: 'include_broken_links',
81+
count: '-',
82+
enable_text: t('sidebar.filter.values.show_broken_links', resource: resource_name),
83+
disable_text: t('sidebar.filter.values.hide_broken_links', resource: resource_name) } %>
7484
<% end %>
7585
<%= render partial: 'search/common/facet_sidebar_boolean_filter',
7686
locals: { facet_field: 'include_archived',

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,8 @@ en:
899899
hide_disabled: 'Hide disabled %{resource}'
900900
show_archived: 'Show archived %{resource}'
901901
hide_archived: 'Hide archived %{resource}'
902+
show_broken_links: 'Show %{resource} with broken links'
903+
hide_broken_links: 'Hide %{resource} with broken links'
902904
show_cross_space: 'Show %{resource} from all spaces'
903905
hide_cross_space: 'Hide %{resource} from all spaces'
904906
hidden:

lib/facets.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Facets
99
start: ->(c) { c.name == 'Event' },
1010
running_during: ->(c) { c.name == 'Event' },
1111
include_hidden: ->(c) { c.method_defined?(:user_requires_approval?) },
12+
include_broken_links: ->(c) { c.method_defined?(:link_monitor) },
1213
across_all_spaces: ->(c) { TeSS::Config.feature['spaces'] && c.reflect_on_association(:space) }
1314
}.with_indifferent_access.freeze
1415

@@ -32,7 +33,8 @@ module Facets
3233
nil
3334
end
3435
},
35-
include_hidden: ->(value) { value == 'true' }
36+
include_hidden: ->(value) { value == 'true' },
37+
include_broken_links: ->(value) { value == 'true' }
3638
}
3739

3840
class << self
@@ -113,6 +115,10 @@ def include_hidden(scope, value, user)
113115
end
114116
end
115117

118+
def include_broken_links(scope, value, _)
119+
sunspot_scoped(scope) { without(:failing, true) } unless value
120+
end
121+
116122
def days_since_scrape(scope, days, _)
117123
sunspot_scoped(scope) { with(:last_scraped).less_than(days.to_i.days.ago) } if days.present?
118124
end

public/api/definitions/tess.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ paths:
190190
description: Include events that are disabled.
191191
schema:
192192
type: boolean
193+
- name: include_broken_links
194+
in: query
195+
description: Include events that have broken links.
196+
schema:
197+
type: boolean
193198
- name: eligibility[]
194199
in: query
195200
description: Filter by who is eligible to attend the event.
@@ -429,6 +434,11 @@ paths:
429434
description: Include materials that are disabled.
430435
schema:
431436
type: boolean
437+
- name: include_broken_links
438+
in: query
439+
description: Include materials that have broken links.
440+
schema:
441+
type: boolean
432442
responses:
433443
200:
434444
description: A collection of materials, and facets available to filter them.

0 commit comments

Comments
 (0)