mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
FIX: Correct mention autocomplete in new topics in unsecured categories
When autocompleting mentions in secure categories, we immediately populate the list with users which have permission to view the category. This logic is applied to unsecured categories as well, but the server returns an empty list of users. This commit teaches the autocomplete to understand empty lists of users without terminating the autocomplete dropdown.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import userSearch from "discourse/lib/user-search";
|
||||
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
|
||||
|
||||
QUnit.module("lib:user-search", {
|
||||
beforeEach() {
|
||||
@ -12,6 +13,9 @@ QUnit.module("lib:user-search", {
|
||||
// special responder for per category search
|
||||
const categoryMatch = request.url.match(/category_id=([0-9]+)/);
|
||||
if (categoryMatch) {
|
||||
if(categoryMatch[1] === "3"){
|
||||
return response({});
|
||||
}
|
||||
return response({
|
||||
users: [
|
||||
{
|
||||
@ -92,6 +96,32 @@ QUnit.test("it flushes cache when switching categories", async assert => {
|
||||
assert.equal(results.length, 1);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"it returns cancel when eager completing with no results",
|
||||
async assert => {
|
||||
// Do everything twice, to check the cache works correctly
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
// No topic or category, will always cancel
|
||||
let result = await userSearch({ term: "" });
|
||||
assert.equal(result, CANCELLED_STATUS);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
// Unsecured category, so has no recommendations
|
||||
let result = await userSearch({ term: "", categoryId: 3 });
|
||||
assert.equal(result, CANCELLED_STATUS);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 2; i++) {
|
||||
// Secured category, will have 1 recommendation
|
||||
let results = await userSearch({ term: "", categoryId: 1 });
|
||||
assert.equal(results[0].username, "category_1");
|
||||
assert.equal(results.length, 1);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("it places groups unconditionally for exact match", async assert => {
|
||||
let results = await userSearch({ term: "Team" });
|
||||
assert.equal(results[results.length - 1]["name"], "team");
|
||||
|
Reference in New Issue
Block a user