mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Support for sending PMs to email addresses (#4988)
* Added support for sending PMs to email addresses. * Made changes after review. * Added settings validator. * Fixed tests.
This commit is contained in:
@@ -42,8 +42,11 @@ export default TextField.extend({
|
||||
updateData: (opts && opts.updateData) ? opts.updateData : false,
|
||||
|
||||
dataSource: function(term) {
|
||||
const termRegex = Discourse.User.currentProp('can_send_private_email_messages') ?
|
||||
/[^a-zA-Z0-9_\-\.@\+]/ : /[^a-zA-Z0-9_\-\.]/;
|
||||
|
||||
var results = userSearch({
|
||||
term: term.replace(/[^a-zA-Z0-9_\-\.]/, ''),
|
||||
term: term.replace(termRegex, ''),
|
||||
topicId: self.get('topicId'),
|
||||
exclude: excludedUsernames(),
|
||||
includeGroups,
|
||||
|
||||
@@ -46,6 +46,7 @@ function organizeResults(r, options) {
|
||||
var exclude = options.exclude || [],
|
||||
limit = options.limit || 5,
|
||||
users = [],
|
||||
emails = [],
|
||||
groups = [],
|
||||
results = [];
|
||||
|
||||
@@ -59,6 +60,12 @@ function organizeResults(r, options) {
|
||||
});
|
||||
}
|
||||
|
||||
if (options.term.match(/@/)) {
|
||||
let e = { username: options.term };
|
||||
emails = [ e ];
|
||||
results.push(e);
|
||||
}
|
||||
|
||||
if (r.groups) {
|
||||
r.groups.every(function(g) {
|
||||
if (results.length > limit && options.term.toLowerCase() !== g.name.toLowerCase()) return false;
|
||||
@@ -71,6 +78,7 @@ function organizeResults(r, options) {
|
||||
}
|
||||
|
||||
results.users = users;
|
||||
results.emails = emails;
|
||||
results.groups = groups;
|
||||
return results;
|
||||
}
|
||||
@@ -94,7 +102,7 @@ export default function userSearch(options) {
|
||||
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
// TODO site setting for allowed regex in username
|
||||
if (term.match(/[^\w\.\-]/)) {
|
||||
if (term.match(/[^\w_\-\.@\+]/)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,18 @@
|
||||
</a>
|
||||
</li>
|
||||
{{/each}}
|
||||
|
||||
{{#if options.emails}}
|
||||
{{#each options.emails as |email|}}
|
||||
<li>
|
||||
<a href title="{{email.username}}">
|
||||
<i class='fa fa-envelope'></i>
|
||||
<span class='username'>{{email.username}}</span>
|
||||
</a>
|
||||
</li>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
{{#if options.groups}}
|
||||
{{#each options.groups as |group|}}
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user