[FIX] mail: followers: subtypes: correctly notify channels

Except for messages, activities on a document like internal notes posted
trigger notifications to partners and channels following the corresponding
activity's subtype.

Rev. 69ed801 rightly re-introduces a filter on followers to prevent notifying
more partners than necessary. Unfortunately, this filter doesn't take into
account channels, which are thus automatically removed from followers to
notify, whatever the subtypes they follow, e.g. internal notes on a document
don't appear in channels following the 'Note' subtype of this document.

This commit makes sure that channels always pass through that filter, but warns
users that public channels should probably not following internal subtypes.

Also makes the edit subtypes dialog html valid (li's must be inside, e.g., ul).
This commit is contained in:
Aaron Bohy
2016-01-08 14:32:51 +01:00
parent 329c6e7763
commit 0fbc128033
4 changed files with 26 additions and 10 deletions
+1 -1
View File
@@ -908,7 +908,7 @@ class Message(models.Model):
('res_id', '=', self.res_id)
]).filtered(lambda fol: self.subtype_id in fol.subtype_ids)
if self_sudo.subtype_id.internal:
followers = followers.filtered(lambda fol: fol.partner_id.user_ids and group_user in fol.partner_id.user_ids[0].mapped('groups_id'))
followers = followers.filtered(lambda fol: fol.channel_id or (fol.partner_id.user_ids and group_user in fol.partner_id.user_ids[0].mapped('groups_id')))
channels = self_sudo.channel_ids | followers.mapped('channel_id')
partners = self_sudo.partner_ids | followers.mapped('partner_id')
else:
+14 -7
View File
@@ -114,7 +114,7 @@ var Followers = form_common.AbstractField.extend({
var follower_id = $currentTarget.data('oe-id');
var is_channel = $currentTarget.data('oe-model') === 'mail.channel';
self.dialog = new Dialog(this, {
size: 'small',
size: 'medium',
title: _t('Edit Subscription of ') + $currentTarget.siblings('a').text(),
buttons: [
{
@@ -131,7 +131,7 @@ var Followers = form_common.AbstractField.extend({
},
],
}).open();
return self.fetch_subtypes($currentTarget.data('id'));
return self.fetch_subtypes($currentTarget.data('id'), $currentTarget.data('oe-model'));
},
on_invite_follower: function (channel_only) {
@@ -270,8 +270,10 @@ var Followers = form_common.AbstractField.extend({
/** Fetch subtypes, only if current user is follower or if follower_id is given, i.e. if
* the current user is editing the subtypes of another follower
* @param {int} [follower_id] the id of the follower
* @param {string} [follower_model] 'res.partner' or 'mail.channel'
*/
fetch_subtypes: function (follower_id) {
fetch_subtypes: function (follower_id, follower_model) {
var self = this;
var dialog = false;
@@ -292,7 +294,7 @@ var Followers = form_common.AbstractField.extend({
res_id: this.view.datarecord.id,
follower_id: follower_id,
}).then(function (data) {
self.display_subtypes(data, dialog);
self.display_subtypes(data, dialog, (follower_model === 'mail.channel'));
});
} else {
return $.Deferred().resolve();
@@ -300,11 +302,11 @@ var Followers = form_common.AbstractField.extend({
},
/** Display subtypes: {'name': default, followed} */
display_subtypes:function (data, dialog) {
display_subtypes:function (data, dialog, display_warning) {
var old_parent_model;
var $list;
if (dialog) {
$list = this.dialog.$el;
$list = $('<ul>').appendTo(this.dialog.$el);
} else {
$list = this.$('.o_subtypes_list ul');
}
@@ -324,9 +326,14 @@ var Followers = form_common.AbstractField.extend({
old_parent_model = record.parent_model;
record.followed = record.followed || undefined;
$(qweb.render('mail.Followers.subtype', {'record': record,
'dialog': dialog}))
'dialog': dialog,
'display_warning': display_warning && record.internal}))
.appendTo($list);
});
if (display_warning) {
$(qweb.render('mail.Followers.subtypes.warning')).appendTo(this.dialog.$el);
}
},
do_follow: function () {
+5 -2
View File
@@ -125,8 +125,11 @@
}
// Edit subtypes in dialog
.modal .modal-body > li.o_subtype {
list-style: none;
.modal .modal-body > ul {
padding-left: 0;
> li.o_subtype {
list-style: none;
}
}
@media print {
+6
View File
@@ -154,7 +154,13 @@
<span t-att-for="'input_mail_followers_subtype_'+record.id+(dialog ? '_in_dialog': '')">
<t t-esc="record.name"/>
</span>
<i t-if="display_warning" class="fa fa-warning text-warning"/>
</li>
</t>
<t t-name="mail.Followers.subtypes.warning">
<span class="text-warning">
<i class="fa fa-warning"/> Be careful with channels following internal notifications
</span>
</t>
</templates>