mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +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) {
|
didInsertElement(opts) {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
|
const bool = (n => {
|
||||||
|
const val = this.get(n);
|
||||||
|
return val === true || val === "true";
|
||||||
|
});
|
||||||
|
|
||||||
var self = this,
|
var self = this,
|
||||||
selected = [],
|
selected = [],
|
||||||
groups = [],
|
groups = [],
|
||||||
currentUser = this.currentUser,
|
currentUser = this.currentUser,
|
||||||
includeMentionableGroups = this.get('includeMentionableGroups') === 'true',
|
includeMentionableGroups = bool('includeMentionableGroups'),
|
||||||
includeMessageableGroups = this.get('includeMessageableGroups') === 'true',
|
includeMessageableGroups = bool('includeMessageableGroups'),
|
||||||
includeGroups = this.get('includeGroups') === 'true',
|
includeGroups = bool('includeGroups'),
|
||||||
allowedUsers = this.get('allowedUsers') === 'true';
|
allowedUsers = bool('allowedUsers'),
|
||||||
|
excludeCurrentUser = bool('excludeCurrentUser'),
|
||||||
|
single = bool('single'),
|
||||||
|
allowAny = bool('allowAny'),
|
||||||
|
disabled = bool('disabled');
|
||||||
|
|
||||||
function excludedUsernames() {
|
function excludedUsernames() {
|
||||||
// hack works around some issues with allowAny eventing
|
// 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.concat([currentUser.get('username')]);
|
||||||
}
|
}
|
||||||
return usernames;
|
return usernames;
|
||||||
|
@ -37,9 +47,9 @@ export default TextField.extend({
|
||||||
|
|
||||||
this.$().val(this.get('usernames')).autocomplete({
|
this.$().val(this.get('usernames')).autocomplete({
|
||||||
template: findRawTemplate('user-selector-autocomplete'),
|
template: findRawTemplate('user-selector-autocomplete'),
|
||||||
disabled: this.get('disabled'),
|
disabled: disabled,
|
||||||
single: this.get('single'),
|
single: single,
|
||||||
allowAny: this.get('allowAny'),
|
allowAny: allowAny,
|
||||||
updateData: (opts && opts.updateData) ? opts.updateData : false,
|
updateData: (opts && opts.updateData) ? opts.updateData : false,
|
||||||
|
|
||||||
dataSource(term) {
|
dataSource(term) {
|
||||||
|
|
|
@ -158,6 +158,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||||
return Group.findAll({ term: term, ignore_automatic: true });
|
return Group.findAll({ term: term, ignore_automatic: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed('isPrivateTopic', 'isMessage')
|
||||||
|
includeMentionableGroups(isPrivateTopic, isMessage) {
|
||||||
|
return !isPrivateTopic && !isMessage;
|
||||||
|
},
|
||||||
|
|
||||||
@computed('isMessage', 'emailOrUsername', 'invitingExistingUserToTopic')
|
@computed('isMessage', 'emailOrUsername', 'invitingExistingUserToTopic')
|
||||||
successMessage(isMessage, emailOrUsername, invitingExistingUserToTopic) {
|
successMessage(isMessage, emailOrUsername, invitingExistingUserToTopic) {
|
||||||
if (this.get('hasGroups')) {
|
if (this.get('hasGroups')) {
|
||||||
|
|
|
@ -69,10 +69,11 @@ function organizeResults(r, options) {
|
||||||
|
|
||||||
if (r.groups) {
|
if (r.groups) {
|
||||||
r.groups.every(function(g) {
|
r.groups.every(function(g) {
|
||||||
if (results.length > limit && options.term.toLowerCase() !== g.name.toLowerCase()) return false;
|
if (options.term.toLowerCase() === g.name.toLowerCase() || results.length < limit) {
|
||||||
if (exclude.indexOf(g.name) === -1) {
|
if (exclude.indexOf(g.name) === -1) {
|
||||||
groups.push(g);
|
groups.push(g);
|
||||||
results.push(g);
|
results.push(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,26 +14,16 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<label>{{inviteInstructions}}</label>
|
<label>{{inviteInstructions}}</label>
|
||||||
{{#if allowExistingMembers}}
|
{{#if allowExistingMembers}}
|
||||||
{{#if isPrivateTopic}}
|
{{user-selector
|
||||||
{{user-selector single="true"
|
single=true
|
||||||
allowAny=true
|
allowAny=true
|
||||||
excludeCurrentUser="true"
|
excludeCurrentUser=true
|
||||||
usernames=emailOrUsername
|
includeMentionableGroups=includeMentionableGroups
|
||||||
allowedUsers="true"
|
includeMessageableGroups=isMessage
|
||||||
topicId=topicId
|
hasGroups=hasGroups
|
||||||
placeholderKey=placeholderKey
|
usernames=emailOrUsername
|
||||||
autocomplete="off"}}
|
placeholderKey=placeholderKey
|
||||||
{{else}}
|
autocomplete="off"}}
|
||||||
{{user-selector
|
|
||||||
single="true"
|
|
||||||
allowAny=true
|
|
||||||
excludeCurrentUser="true"
|
|
||||||
includeMentionableGroups="true"
|
|
||||||
hasGroups=hasGroups
|
|
||||||
usernames=emailOrUsername
|
|
||||||
placeholderKey=placeholderKey
|
|
||||||
autocomplete="off"}}
|
|
||||||
{{/if}}
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{text-field value=emailOrUsername placeholderKey="topic.invite_reply.email_placeholder"}}
|
{{text-field value=emailOrUsername placeholderKey="topic.invite_reply.email_placeholder"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -751,6 +751,7 @@ class UsersController < ApplicationController
|
||||||
if include_groups || groups
|
if include_groups || groups
|
||||||
groups = Group.search_groups(term, groups: groups)
|
groups = Group.search_groups(term, groups: groups)
|
||||||
groups = groups.where(visibility_level: Group.visibility_levels[:public]) if include_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|
|
to_render[:groups] = groups.map do |m|
|
||||||
{ name: m.name, full_name: m.full_name }
|
{ name: m.name, full_name: m.full_name }
|
||||||
|
|
|
@ -47,6 +47,10 @@ QUnit.module("lib:user-search", {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
groups: [
|
groups: [
|
||||||
|
{
|
||||||
|
"name": "bob",
|
||||||
|
"usernames": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "team",
|
"name": "team",
|
||||||
"usernames": []
|
"usernames": []
|
||||||
|
@ -61,4 +65,4 @@ QUnit.test("it places groups unconditionally for exact match", assert => {
|
||||||
return userSearch({term: 'Team'}).then((results)=>{
|
return userSearch({term: 'Team'}).then((results)=>{
|
||||||
assert.equal(results[results.length-1]["name"], "team");
|
assert.equal(results[results.length-1]["name"], "team");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user