FEATURE: warn if attempting to mention a group with too many members
This commit is contained in:
parent
081959227d
commit
62a27f9d57
|
@ -363,7 +363,7 @@ export default Ember.Component.extend({
|
|||
const $e = $(e);
|
||||
var name = $e.data('name');
|
||||
if (found.indexOf(name) === -1){
|
||||
this.sendAction('groupsMentioned', [{name: name, user_count: $e.data('mentionable-user-count')}]);
|
||||
this.sendAction('groupsMentioned', [{name: name, user_count: $e.data('mentionable-user-count'), max_mentions: $e.data('max-mentions')}]);
|
||||
found.push(name);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -378,11 +378,21 @@ export default Ember.Controller.extend({
|
|||
groupsMentioned(groups) {
|
||||
if (!this.get('model.creatingPrivateMessage') && !this.get('model.topic.isPrivateMessage')) {
|
||||
groups.forEach(group => {
|
||||
const body = I18n.t('composer.group_mentioned', {
|
||||
group: "@" + group.name,
|
||||
count: group.user_count,
|
||||
group_link: Discourse.getURL(`/groups/${group.name}/members`)
|
||||
});
|
||||
let body;
|
||||
|
||||
if (group.max_mentions < group.user_count) {
|
||||
body = I18n.t('composer.group_mentioned_limit', {
|
||||
group: "@" + group.name,
|
||||
max: group.max_mentions,
|
||||
group_link: Discourse.getURL(`/groups/${group.name}/members`)
|
||||
});
|
||||
} else {
|
||||
body = I18n.t('composer.group_mentioned', {
|
||||
group: "@" + group.name,
|
||||
count: group.user_count,
|
||||
group_link: Discourse.getURL(`/groups/${group.name}/members`)
|
||||
});
|
||||
}
|
||||
|
||||
this.appEvents.trigger('composer-messages:create', {
|
||||
extraClass: 'custom-body',
|
||||
|
|
|
@ -2,13 +2,15 @@ import { ajax } from 'discourse/lib/ajax';
|
|||
import { userPath } from 'discourse/lib/url';
|
||||
import { formatUsername } from 'discourse/lib/utilities';
|
||||
|
||||
let maxGroupMention;
|
||||
|
||||
function replaceSpan($e, username, opts) {
|
||||
let extra = "";
|
||||
let extraClass = "";
|
||||
|
||||
if (opts && opts.group) {
|
||||
if (opts.mentionable) {
|
||||
extra = `data-name='${username}' data-mentionable-user-count='${opts.mentionable.user_count}'`;
|
||||
extra = `data-name='${username}' data-mentionable-user-count='${opts.mentionable.user_count}' data-max-mentions='${maxGroupMention}'`;
|
||||
extraClass = "notify";
|
||||
}
|
||||
$e.replaceWith(`<a href='${Discourse.getURL("/groups/") + username}' class='mention-group ${extraClass}' ${extra}>@${username}</a>`);
|
||||
|
@ -61,6 +63,7 @@ export function fetchUnseenMentions(usernames, topic_id) {
|
|||
r.valid_groups.forEach(vg => foundGroups[vg] = true);
|
||||
r.mentionable_groups.forEach(mg => mentionableGroups[mg.name] = mg);
|
||||
r.cannot_see.forEach(cs => cannotSee[cs] = true);
|
||||
maxGroupMention = r.max_users_notified_per_group_mention;
|
||||
usernames.forEach(u => checked[u] = true);
|
||||
return r;
|
||||
});
|
||||
|
|
|
@ -248,7 +248,12 @@ class UsersController < ApplicationController
|
|||
Group.mentionable(current_user)
|
||||
.where(name: usernames)
|
||||
.pluck(:name, :user_count)
|
||||
.map { |name, user_count| { name: name, user_count: user_count } }
|
||||
.map do |name, user_count|
|
||||
{
|
||||
name: name,
|
||||
user_count: user_count
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
usernames -= groups
|
||||
|
@ -267,7 +272,13 @@ class UsersController < ApplicationController
|
|||
.where(username_lower: usernames)
|
||||
.pluck(:username_lower)
|
||||
|
||||
render json: { valid: result, valid_groups: groups, mentionable_groups: mentionable_groups, cannot_see: cannot_see }
|
||||
render json: {
|
||||
valid: result,
|
||||
valid_groups: groups,
|
||||
mentionable_groups: mentionable_groups,
|
||||
cannot_see: cannot_see,
|
||||
max_users_notified_per_group_mention: SiteSetting.max_users_notified_per_group_mention
|
||||
}
|
||||
end
|
||||
|
||||
def render_available_true
|
||||
|
|
|
@ -1211,6 +1211,7 @@ en:
|
|||
similar_topics: "Your topic is similar to..."
|
||||
drafts_offline: "drafts offline"
|
||||
|
||||
group_mentioned_limit: "<b>Warning!</b> you mentioned <a href='{{group_link}}'>{{group}}</a>, however it has more members than the administrator configured limit of {{max}} users. Nobody will be notified. "
|
||||
group_mentioned:
|
||||
one: "By mentioning {{group}}, you are about to notify <a href='{{group_link}}'>1 person</a> – are you sure?"
|
||||
other: "By mentioning {{group}}, you are about to notify <a href='{{group_link}}'>{{count}} people</a> – are you sure?"
|
||||
|
|
Loading…
Reference in New Issue