mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: pass in excluded usernames to user-selector (#8695)
This commit is contained in:
committed by
GitHub
parent
5a70f50032
commit
5898afaa73
@@ -60,16 +60,18 @@ export default TextField.extend({
|
|||||||
allowAny = bool("allowAny"),
|
allowAny = bool("allowAny"),
|
||||||
disabled = bool("disabled"),
|
disabled = bool("disabled"),
|
||||||
allowEmails = bool("allowEmails"),
|
allowEmails = bool("allowEmails"),
|
||||||
fullWidthWrap = bool("fullWidthWrap");
|
fullWidthWrap = bool("fullWidthWrap"),
|
||||||
|
excludedUsernames = this.excludedUsernames || [];
|
||||||
|
|
||||||
const excludedUsernames = () => {
|
const allExcludedUsernames = () => {
|
||||||
// hack works around some issues with allowAny eventing
|
// hack works around some issues with allowAny eventing
|
||||||
const usernames = single ? [] : selected;
|
let usernames = single ? [] : selected;
|
||||||
|
|
||||||
if (currentUser && excludeCurrentUser) {
|
if (currentUser && excludeCurrentUser) {
|
||||||
return usernames.concat([currentUser.username]);
|
usernames.concat([currentUser.username]);
|
||||||
}
|
}
|
||||||
return usernames;
|
|
||||||
|
return usernames.concat(excludedUsernames);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.element.addEventListener("paste", this._paste);
|
this.element.addEventListener("paste", this._paste);
|
||||||
@@ -90,7 +92,7 @@ export default TextField.extend({
|
|||||||
return userSearch({
|
return userSearch({
|
||||||
term,
|
term,
|
||||||
topicId: userSelectorComponent.topicId,
|
topicId: userSelectorComponent.topicId,
|
||||||
exclude: excludedUsernames(),
|
exclude: allExcludedUsernames(),
|
||||||
includeGroups,
|
includeGroups,
|
||||||
allowedUsers,
|
allowedUsers,
|
||||||
includeMentionableGroups,
|
includeMentionableGroups,
|
||||||
@@ -107,7 +109,7 @@ export default TextField.extend({
|
|||||||
}
|
}
|
||||||
return v.username || v.name;
|
return v.username || v.name;
|
||||||
} else {
|
} else {
|
||||||
const excludes = excludedUsernames();
|
const excludes = allExcludedUsernames();
|
||||||
return v.usernames.filter(item => excludes.indexOf(item) === -1);
|
return v.usernames.filter(item => excludes.indexOf(item) === -1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -158,7 +160,10 @@ export default TextField.extend({
|
|||||||
|
|
||||||
(text || "").split(/[, \n]+/).forEach(val => {
|
(text || "").split(/[, \n]+/).forEach(val => {
|
||||||
val = val.replace(/^@+/, "").trim();
|
val = val.replace(/^@+/, "").trim();
|
||||||
if (val.length > 0) {
|
if (
|
||||||
|
val.length > 0 &&
|
||||||
|
(!this.excludedUsernames || !this.excludedUsernames.includes(val))
|
||||||
|
) {
|
||||||
usernames.push(val);
|
usernames.push(val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ import componentTest from "helpers/component-test";
|
|||||||
|
|
||||||
moduleForComponent("user-selector", { integration: true });
|
moduleForComponent("user-selector", { integration: true });
|
||||||
|
|
||||||
|
function paste(element, text) {
|
||||||
|
let e = new Event("paste");
|
||||||
|
e.clipboardData = { getData: () => text };
|
||||||
|
element.dispatchEvent(e);
|
||||||
|
};
|
||||||
|
|
||||||
componentTest("pasting a list of usernames", {
|
componentTest("pasting a list of usernames", {
|
||||||
template: `{{user-selector usernames=usernames class="test-selector"}}`,
|
template: `{{user-selector usernames=usernames class="test-selector"}}`,
|
||||||
|
|
||||||
@@ -11,28 +17,38 @@ componentTest("pasting a list of usernames", {
|
|||||||
|
|
||||||
test(assert) {
|
test(assert) {
|
||||||
let element = find(".test-selector")[0];
|
let element = find(".test-selector")[0];
|
||||||
let paste = text => {
|
|
||||||
let e = new Event("paste");
|
|
||||||
e.clipboardData = { getData: () => text };
|
|
||||||
element.dispatchEvent(e);
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.equal(this.get("usernames"), "evil,trout");
|
assert.equal(this.get("usernames"), "evil,trout");
|
||||||
paste("zip,zap,zoom");
|
paste(element, "zip,zap,zoom");
|
||||||
assert.equal(this.get("usernames"), "evil,trout,zip,zap,zoom");
|
assert.equal(this.get("usernames"), "evil,trout,zip,zap,zoom");
|
||||||
paste("evil,abc,abc,abc");
|
paste(element, "evil,abc,abc,abc");
|
||||||
assert.equal(this.get("usernames"), "evil,trout,zip,zap,zoom,abc");
|
assert.equal(this.get("usernames"), "evil,trout,zip,zap,zoom,abc");
|
||||||
|
|
||||||
this.set("usernames", "");
|
this.set("usernames", "");
|
||||||
paste("names with spaces");
|
paste(element, "names with spaces");
|
||||||
assert.equal(this.get("usernames"), "names,with,spaces");
|
assert.equal(this.get("usernames"), "names,with,spaces");
|
||||||
|
|
||||||
this.set("usernames", null);
|
this.set("usernames", null);
|
||||||
paste("@eviltrout,@codinghorror sam");
|
paste(element, "@eviltrout,@codinghorror sam");
|
||||||
assert.equal(this.get("usernames"), "eviltrout,codinghorror,sam");
|
assert.equal(this.get("usernames"), "eviltrout,codinghorror,sam");
|
||||||
|
|
||||||
this.set("usernames", null);
|
this.set("usernames", null);
|
||||||
paste("eviltrout\nsam\ncodinghorror");
|
paste(element, "eviltrout\nsam\ncodinghorror");
|
||||||
assert.equal(this.get("usernames"), "eviltrout,sam,codinghorror");
|
assert.equal(this.get("usernames"), "eviltrout,sam,codinghorror");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
componentTest("excluding usernames", {
|
||||||
|
template: `{{user-selector usernames=usernames excludedUsernames=excludedUsernames class="test-selector"}}`,
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
this.set("usernames", "mark");
|
||||||
|
this.set("excludedUsernames", ["jeff", "sam", "robin"]);
|
||||||
|
},
|
||||||
|
|
||||||
|
test(assert) {
|
||||||
|
let element = find(".test-selector")[0];
|
||||||
|
paste(element, "roman,penar,jeff,robin");
|
||||||
|
assert.equal(this.get("usernames"), "mark,roman,penar");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user