autocomplete: fix exception when completing saved search labels.

Fix an exception that was thrown when trying to autocomplete saved
search labels (e.g. `search:all`) as an anonymous user. This was a
pre-existing bug.
This commit is contained in:
evazion
2020-12-13 00:45:22 -06:00
parent d6a5b9e252
commit 119268e118
3 changed files with 12 additions and 1 deletions

View File

@@ -63,6 +63,14 @@ class SavedSearch < ApplicationRecord
.gsub(/[[:space:]]/, "_")
end
def all_labels
select(Arel.sql("distinct unnest(labels) as label")).order(:label)
end
def labels_like(label)
all_labels.select { |ss| ss.label.ilike?(label) }.map(&:label)
end
def search_labels(user_id, params)
labels = labels_for(user_id)