autocomplete: fix favgroup:<name> returning favgroups for other users.

* Fix favgroup:<name> autocompletion to only return favgroups for the
  current user.
* Add favgroup autocomplete to the /favorite_groups search form.
This commit is contained in:
evazion
2020-01-22 11:21:16 -06:00
parent edaf6323fd
commit 9d71c77524
2 changed files with 5 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ Autocomplete.initialize_all = function() {
this.initialize_fields($('[data-autocomplete="pool"]'), Autocomplete.pool_source);
this.initialize_fields($('[data-autocomplete="user"]'), Autocomplete.user_source);
this.initialize_fields($('[data-autocomplete="wiki-page"]'), Autocomplete.wiki_source);
this.initialize_fields($('[data-autocomplete="favorite-group"]'), Autocomplete.favorite_group_source);
this.initialize_fields($('[data-autocomplete="saved-search-label"]'), Autocomplete.saved_search_source);
}
}
@@ -139,7 +140,7 @@ Autocomplete.initialize_tag_autocomplete = function() {
results = await Autocomplete.pool_source(term, metatag + ":");
break;
case "favgroup":
results = await Autocomplete.favorite_group_source(term, metatag + ":");
results = await Autocomplete.favorite_group_source(term, metatag + ":", CurrentUser.data("id"));
break;
case "search":
results = await Autocomplete.saved_search_source(term, metatag + ":");
@@ -394,8 +395,9 @@ Autocomplete.pool_source = async function(term, prefix = "") {
});
};
Autocomplete.favorite_group_source = async function(term, prefix = "") {
Autocomplete.favorite_group_source = async function(term, prefix = "", creator_id = null) {
let favgroups = await $.getJSON("/favorite_groups", {
"search[creator_id]": creator_id,
"search[name_matches]": term,
"limit": Autocomplete.MAX_RESULTS
});

View File

@@ -1,7 +1,7 @@
<div id="c-favorite-groups">
<div id="a-index">
<%= search_form_for(favorite_groups_path) do |f| %>
<%= f.input :name_matches, label: "Name", input_html: { value: params.dig(:search, :name_matches) } %>
<%= f.input :name_matches, label: "Name", input_html: { value: params.dig(:search, :name_matches), "data-autocomplete": "favorite-group" } %>
<%= f.input :creator_name, label: "Creator", input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %>
<%= f.input :order, collection: [%w[Created created_at], %w[Updated updated_at], %w[Name name], %w[Post\ count post_count]], include_blank: true, selected: params.dig(:search, :order) %>
<%= f.submit "Search" %>