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:
Bianca Nenciu
2017-08-28 17:07:30 +01:00
committed by Sam
parent 4623b46b0b
commit bb3a5910d7
11 changed files with 134 additions and 3 deletions

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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>