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({
beforeModel: function(transition) {
const self = this;
if (Discourse.User.current()) {
// User is logged in
self.replaceWith('discovery.latest').then(function(e) {
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() {
@ -15,6 +19,20 @@ export default Discourse.Route.extend({
}).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

View file

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

View file

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

View file

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