mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -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({
|
export default Discourse.Route.extend({
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
const self = this;
|
const self = this;
|
||||||
if (Discourse.User.current()) {
|
if (Discourse.User.current()) {
|
||||||
// User is logged in
|
// User is logged in
|
||||||
self.replaceWith('discovery.latest').then(function(e) {
|
self.replaceWith('discovery.latest').then(function(e) {
|
||||||
Discourse.User.findByUsername(transition.queryParams.username).then((user) => {
|
if (transition.queryParams.username) {
|
||||||
if (user.can_send_private_message_to_user) {
|
// send a message to user
|
||||||
Ember.run.next(function() {
|
Discourse.User.findByUsername(transition.queryParams.username).then((user) => {
|
||||||
e.send('createNewMessageViaParams', user.username, transition.queryParams.title, transition.queryParams.body);
|
if (user.can_send_private_message_to_user) {
|
||||||
});
|
Ember.run.next(function() {
|
||||||
} else {
|
e.send('createNewMessageViaParams', user.username, transition.queryParams.title, transition.queryParams.body);
|
||||||
bootbox.alert(I18n.t("composer.cant_send_pm", {username: user.username}));
|
});
|
||||||
}
|
} else {
|
||||||
}).catch(() => {
|
bootbox.alert(I18n.t("composer.cant_send_pm", {username: user.username}));
|
||||||
bootbox.alert(I18n.t("generic_error"));
|
}
|
||||||
});
|
}).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 {
|
} else {
|
||||||
// User is not logged in
|
// User is not logged in
|
||||||
|
|
|
@ -362,6 +362,10 @@ class Group < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mentionable?(user, group_id)
|
||||||
|
Group.mentionable(user).where(id: group_id).exists?
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def name_format_validator
|
def name_format_validator
|
||||||
|
|
|
@ -12,7 +12,8 @@ class BasicGroupSerializer < ApplicationSerializer
|
||||||
:grant_trust_level,
|
:grant_trust_level,
|
||||||
:incoming_email,
|
:incoming_email,
|
||||||
:notification_level,
|
:notification_level,
|
||||||
:has_messages
|
:has_messages,
|
||||||
|
:mentionable
|
||||||
|
|
||||||
def include_incoming_email?
|
def include_incoming_email?
|
||||||
scope.is_staff?
|
scope.is_staff?
|
||||||
|
@ -27,4 +28,8 @@ class BasicGroupSerializer < ApplicationSerializer
|
||||||
scope.authenticated?
|
scope.authenticated?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mentionable
|
||||||
|
object.mentionable?(scope.user, object.id)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,8 @@ describe Admin::GroupsController do
|
||||||
"grant_trust_level"=>nil,
|
"grant_trust_level"=>nil,
|
||||||
"incoming_email"=>nil,
|
"incoming_email"=>nil,
|
||||||
"notification_level"=>2,
|
"notification_level"=>2,
|
||||||
"has_messages"=>false
|
"has_messages"=>false,
|
||||||
|
"mentionable"=>false
|
||||||
}])
|
}])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue