FEATURE: compose a new pre-filled private message to a group via URL

This commit is contained in:
Arpit Jalan 2016-03-02 23:48:17 +05:30
parent 94f5aa6015
commit bfaa4cdb37
4 changed files with 41 additions and 13 deletions

View file

@ -1,9 +1,13 @@
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) {
if (transition.queryParams.username) {
// send a message to user
Discourse.User.findByUsername(transition.queryParams.username).then((user) => { Discourse.User.findByUsername(transition.queryParams.username).then((user) => {
if (user.can_send_private_message_to_user) { if (user.can_send_private_message_to_user) {
Ember.run.next(function() { Ember.run.next(function() {
@ -15,6 +19,20 @@ export default Discourse.Route.extend({
}).catch(() => { }).catch(() => {
bootbox.alert(I18n.t("generic_error")); 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

View file

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

View file

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

View file

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