mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
FIX: invite to message was not allowing groups
Previously we were incorrectly checking mentionable instead of messageable Also fix edge case where multiple groups sharing a name mean that exact match override is not working Also cleans up params sent to user selector
This commit is contained in:
parent
5f8f691e2b
commit
b34b1b6fe3
|
@ -16,20 +16,30 @@ export default TextField.extend({
|
|||
|
||||
didInsertElement(opts) {
|
||||
this._super();
|
||||
|
||||
const bool = (n => {
|
||||
const val = this.get(n);
|
||||
return val === true || val === "true";
|
||||
});
|
||||
|
||||
var self = this,
|
||||
selected = [],
|
||||
groups = [],
|
||||
currentUser = this.currentUser,
|
||||
includeMentionableGroups = this.get('includeMentionableGroups') === 'true',
|
||||
includeMessageableGroups = this.get('includeMessageableGroups') === 'true',
|
||||
includeGroups = this.get('includeGroups') === 'true',
|
||||
allowedUsers = this.get('allowedUsers') === 'true';
|
||||
includeMentionableGroups = bool('includeMentionableGroups'),
|
||||
includeMessageableGroups = bool('includeMessageableGroups'),
|
||||
includeGroups = bool('includeGroups'),
|
||||
allowedUsers = bool('allowedUsers'),
|
||||
excludeCurrentUser = bool('excludeCurrentUser'),
|
||||
single = bool('single'),
|
||||
allowAny = bool('allowAny'),
|
||||
disabled = bool('disabled');
|
||||
|
||||
function excludedUsernames() {
|
||||
// hack works around some issues with allowAny eventing
|
||||
const usernames = self.get('single') ? [] : selected;
|
||||
const usernames = single ? [] : selected;
|
||||
|
||||
if (currentUser && self.get('excludeCurrentUser')) {
|
||||
if (currentUser && excludeCurrentUser) {
|
||||
return usernames.concat([currentUser.get('username')]);
|
||||
}
|
||||
return usernames;
|
||||
|
@ -37,9 +47,9 @@ export default TextField.extend({
|
|||
|
||||
this.$().val(this.get('usernames')).autocomplete({
|
||||
template: findRawTemplate('user-selector-autocomplete'),
|
||||
disabled: this.get('disabled'),
|
||||
single: this.get('single'),
|
||||
allowAny: this.get('allowAny'),
|
||||
disabled: disabled,
|
||||
single: single,
|
||||
allowAny: allowAny,
|
||||
updateData: (opts && opts.updateData) ? opts.updateData : false,
|
||||
|
||||
dataSource(term) {
|
||||
|
|
|
@ -158,6 +158,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
return Group.findAll({ term: term, ignore_automatic: true });
|
||||
},
|
||||
|
||||
@computed('isPrivateTopic', 'isMessage')
|
||||
includeMentionableGroups(isPrivateTopic, isMessage) {
|
||||
return !isPrivateTopic && !isMessage;
|
||||
},
|
||||
|
||||
@computed('isMessage', 'emailOrUsername', 'invitingExistingUserToTopic')
|
||||
successMessage(isMessage, emailOrUsername, invitingExistingUserToTopic) {
|
||||
if (this.get('hasGroups')) {
|
||||
|
|
|
@ -69,10 +69,11 @@ function organizeResults(r, options) {
|
|||
|
||||
if (r.groups) {
|
||||
r.groups.every(function(g) {
|
||||
if (results.length > limit && options.term.toLowerCase() !== g.name.toLowerCase()) return false;
|
||||
if (exclude.indexOf(g.name) === -1) {
|
||||
groups.push(g);
|
||||
results.push(g);
|
||||
if (options.term.toLowerCase() === g.name.toLowerCase() || results.length < limit) {
|
||||
if (exclude.indexOf(g.name) === -1) {
|
||||
groups.push(g);
|
||||
results.push(g);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -14,26 +14,16 @@
|
|||
{{else}}
|
||||
<label>{{inviteInstructions}}</label>
|
||||
{{#if allowExistingMembers}}
|
||||
{{#if isPrivateTopic}}
|
||||
{{user-selector single="true"
|
||||
allowAny=true
|
||||
excludeCurrentUser="true"
|
||||
usernames=emailOrUsername
|
||||
allowedUsers="true"
|
||||
topicId=topicId
|
||||
placeholderKey=placeholderKey
|
||||
autocomplete="off"}}
|
||||
{{else}}
|
||||
{{user-selector
|
||||
single="true"
|
||||
allowAny=true
|
||||
excludeCurrentUser="true"
|
||||
includeMentionableGroups="true"
|
||||
hasGroups=hasGroups
|
||||
usernames=emailOrUsername
|
||||
placeholderKey=placeholderKey
|
||||
autocomplete="off"}}
|
||||
{{/if}}
|
||||
{{user-selector
|
||||
single=true
|
||||
allowAny=true
|
||||
excludeCurrentUser=true
|
||||
includeMentionableGroups=includeMentionableGroups
|
||||
includeMessageableGroups=isMessage
|
||||
hasGroups=hasGroups
|
||||
usernames=emailOrUsername
|
||||
placeholderKey=placeholderKey
|
||||
autocomplete="off"}}
|
||||
{{else}}
|
||||
{{text-field value=emailOrUsername placeholderKey="topic.invite_reply.email_placeholder"}}
|
||||
{{/if}}
|
||||
|
|
|
@ -751,6 +751,7 @@ class UsersController < ApplicationController
|
|||
if include_groups || groups
|
||||
groups = Group.search_groups(term, groups: groups)
|
||||
groups = groups.where(visibility_level: Group.visibility_levels[:public]) if include_groups
|
||||
groups = groups.order('groups.name asc')
|
||||
|
||||
to_render[:groups] = groups.map do |m|
|
||||
{ name: m.name, full_name: m.full_name }
|
||||
|
|
|
@ -47,6 +47,10 @@ QUnit.module("lib:user-search", {
|
|||
}
|
||||
],
|
||||
groups: [
|
||||
{
|
||||
"name": "bob",
|
||||
"usernames": []
|
||||
},
|
||||
{
|
||||
"name": "team",
|
||||
"usernames": []
|
||||
|
@ -61,4 +65,4 @@ QUnit.test("it places groups unconditionally for exact match", assert => {
|
|||
return userSearch({term: 'Team'}).then((results)=>{
|
||||
assert.equal(results[results.length-1]["name"], "team");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user