mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: compose a new pre-filled private message to a group via URL
This commit is contained in:
parent
94f5aa6015
commit
bfaa4cdb37
4 changed files with 41 additions and 13 deletions
|
@ -1,20 +1,38 @@
|
|||
import Group from 'discourse/models/group';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
beforeModel: function(transition) {
|
||||
const self = this;
|
||||
if (Discourse.User.current()) {
|
||||
// User is logged in
|
||||
self.replaceWith('discovery.latest').then(function(e) {
|
||||
Discourse.User.findByUsername(transition.queryParams.username).then((user) => {
|
||||
if (user.can_send_private_message_to_user) {
|
||||
Ember.run.next(function() {
|
||||
e.send('createNewMessageViaParams', user.username, transition.queryParams.title, transition.queryParams.body);
|
||||
});
|
||||
} else {
|
||||
bootbox.alert(I18n.t("composer.cant_send_pm", {username: user.username}));
|
||||
}
|
||||
}).catch(() => {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
});
|
||||
if (transition.queryParams.username) {
|
||||
// send a message to user
|
||||
Discourse.User.findByUsername(transition.queryParams.username).then((user) => {
|
||||
if (user.can_send_private_message_to_user) {
|
||||
Ember.run.next(function() {
|
||||
e.send('createNewMessageViaParams', user.username, transition.queryParams.title, transition.queryParams.body);
|
||||
});
|
||||
} else {
|
||||
bootbox.alert(I18n.t("composer.cant_send_pm", {username: user.username}));
|
||||
}
|
||||
}).catch(() => {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
});
|
||||
} else {
|
||||
// send a message to group
|
||||
Group.find(transition.queryParams.groupname).then((group) => {
|
||||
if (!group.automatic && group.mentionable) {
|
||||
Ember.run.next(function() {
|
||||
e.send('createNewMessageViaParams', group.name, transition.queryParams.title, transition.queryParams.body);
|
||||
});
|
||||
} else {
|
||||
bootbox.alert(I18n.t("composer.cant_send_pm", {username: group.name}));
|
||||
}
|
||||
}).catch(() => {
|
||||
bootbox.alert(I18n.t("generic_error"));
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// User is not logged in
|
||||
|
|
|
@ -362,6 +362,10 @@ class Group < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def mentionable?(user, group_id)
|
||||
Group.mentionable(user).where(id: group_id).exists?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def name_format_validator
|
||||
|
|
|
@ -12,7 +12,8 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
:grant_trust_level,
|
||||
:incoming_email,
|
||||
:notification_level,
|
||||
:has_messages
|
||||
:has_messages,
|
||||
:mentionable
|
||||
|
||||
def include_incoming_email?
|
||||
scope.is_staff?
|
||||
|
@ -27,4 +28,8 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
scope.authenticated?
|
||||
end
|
||||
|
||||
def mentionable
|
||||
object.mentionable?(scope.user, object.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -33,7 +33,8 @@ describe Admin::GroupsController do
|
|||
"grant_trust_level"=>nil,
|
||||
"incoming_email"=>nil,
|
||||
"notification_level"=>2,
|
||||
"has_messages"=>false
|
||||
"has_messages"=>false,
|
||||
"mentionable"=>false
|
||||
}])
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue