[IMP] mail, following: access

bzr revid: chm@openerp.com-20121011161614-k72bm2f6gw451u5g
This commit is contained in:
Christophe Matthieu 2012-10-11 18:16:14 +02:00
parent 540248ed9e
commit 4a77345f63
9 changed files with 66 additions and 48 deletions

View File

@ -92,7 +92,7 @@ class mail_notification(osv.Model):
partner_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id
notif_ids = self.search(cr, uid, [('partner_id', '=', partner_id), ('message_id', 'in', msg_ids)], context=context)
return self.write(cr, uid, notif_ids, {'read': read}, context=context)
return self.write(cr, 1, notif_ids, {'read': read}, context=context)
def get_partners_to_notify(self, cr, uid, message, context=None):
""" Return the list of partners to notify, based on their preferences.

View File

@ -163,7 +163,7 @@ class mail_message(osv.Model):
mail.message not always granted. '''
if not user_ids:
user_ids = [uid]
for message in self.read(cr, uid, ids, ['vote_user_ids'], context=context):
for message in self.read(cr, SUPERUSER_ID, ids, ['vote_user_ids'], context=context):
for user_id in user_ids:
has_voted = user_id in message.get('vote_user_ids')
if not has_voted:
@ -189,17 +189,17 @@ class mail_message(osv.Model):
has_voted = True
break
try:
attachment_ids = [{'id': attach[0], 'name': attach[1]} for attach in self.pool.get('ir.attachment').name_get(cr, uid, [x.id for x in msg.attachment_ids], context=context)]
attachment_ids = [{'id': attach[0], 'name': attach[1]} for attach in self.pool.get('ir.attachment').name_get(cr, SUPERUSER_ID, [x.id for x in msg.attachment_ids], context=context)]
except (orm.except_orm, osv.except_osv):
attachment_ids = []
try:
author_id = self.pool.get('res.partner').name_get(cr, uid, [msg.author_id.id], context=context)[0]
author_id = self.pool.get('res.partner').name_get(cr, SUPERUSER_ID, [msg.author_id.id], context=context)[0]
is_author = uid == msg.author_id.user_ids[0].id
except Exception:
author_id = False
is_author = False
try:
partner_ids = self.pool.get('res.partner').name_get(cr, uid, [x.id for x in msg.partner_ids], context=context)
partner_ids = self.pool.get('res.partner').name_get(cr, SUPERUSER_ID, [x.id for x in msg.partner_ids], context=context)
except (orm.except_orm, osv.except_osv):
partner_ids = []
@ -222,7 +222,7 @@ class mail_message(osv.Model):
'unread': msg.unread and msg.unread['unread'] or False
}
def _message_read_expandable(self, cr, uid, tree, result, message_loaded, domain, context, parent_id, limit):
def _message_read_expandable(self, cr, uid, tree, result, message_loaded_ids, domain, context, parent_id, limit):
"""
create the expandable message for all parent message read
this function is used by message_read
@ -230,28 +230,28 @@ class mail_message(osv.Model):
tree_not = []
# expandable for not show message
for id_msg in tree:
for msg in tree:
# get all childs
not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=1000)
not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',msg.id],['id','not in',message_loaded_ids]], None, limit=1000)
# group childs not read
id_min=None
id_max=None
nb=0
for not_loaded_id in not_loaded_ids:
if not_loaded_id not in tree:
for not_loaded in self.browse(cr, SUPERUSER_ID, not_loaded_ids, context=context):
if not_loaded not in tree:
nb+=1
if id_min==None or id_min>not_loaded_id:
id_min=not_loaded_id
if id_max==None or id_max<not_loaded_id:
id_max=not_loaded_id
tree_not.append(not_loaded_id)
if id_min==None or id_min>not_loaded.id:
id_min=not_loaded.id
if id_max==None or id_max<not_loaded.id:
id_max=not_loaded.id
tree_not.append(not_loaded)
else:
if nb>0:
result.append({
'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',id_msg]],
'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',msg.id]],
'nb_messages': nb,
'type': 'expandable',
'parent_id': id_msg,
'parent_id': msg.id,
'id': id_min
})
id_min=None
@ -259,16 +259,18 @@ class mail_message(osv.Model):
nb=0
if nb>0:
result.append({
'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',id_msg]],
'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',msg.id]],
'nb_messages': nb,
'type': 'expandable',
'parent_id': id_msg,
'parent_id': msg.id,
'id': id_min
})
for msg in tree+tree_not:
message_loaded_ids.append( msg.id )
# expandable for limit max
ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded+tree+tree_not]], context=context, limit=1)
ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded_ids]], context=context, limit=1)
if len(ids) > 0:
result.append(
{
@ -297,11 +299,11 @@ class mail_message(osv.Model):
further parents
:return list: list of trees of messages
"""
message_loaded = context and context.get('message_loaded') or [0]
message_loaded_ids = context and context.get('message_loaded') or [0]
# don't read the message display by .js, in context message_loaded list
if context and context.get('message_loaded'):
domain += [ ['id','not in',message_loaded] ];
domain += [ ['id','not in',message_loaded_ids] ];
limit = limit or self._message_read_limit
context = context or {}
@ -317,27 +319,27 @@ class mail_message(osv.Model):
return result
# key: ID, value: record
ids = self.search(cr, SUPERUSER_ID, domain, context=context, limit=limit)
ids = self.search(cr, uid, domain, context=context, limit=limit)
for msg in self.browse(cr, uid, ids, context=context):
# if not in record and not in message_loded list
if msg.id not in tree and msg.id not in message_loaded :
if msg not in tree and msg.id not in message_loaded_ids :
record = self._message_dict_get(cr, uid, msg, context=context)
tree.append(msg.id)
tree.append(msg)
result.append(record)
while msg.parent_id and msg.parent_id.id != parent_id:
parent_id = msg.parent_id.id
if msg.parent_id.id not in tree:
msg = msg.parent_id
tree.append(msg.id)
tree.append(msg)
# if not in record and not in message_loded list
if msg.id not in message_loaded :
if msg.id not in message_loaded_ids :
record = self._message_dict_get(cr, uid, msg, context=context)
result.append(record)
result = sorted(result, key=lambda k: k['id'])
result = self._message_read_expandable(cr, uid, tree, result, message_loaded, domain, context, parent_id, limit)
result = self._message_read_expandable(cr, uid, tree, result, message_loaded_ids, domain, context, parent_id, limit)
return result
@ -465,13 +467,14 @@ class mail_message(osv.Model):
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
""" Override to explicitely call check_access_rule, that is not called
by the ORM. It instead directly fetches ir.rules and apply them. """
res = super(mail_message, self).read(cr, uid, ids, fields=fields, context=context, load=load)
self.check_access_rule(cr, uid, ids, 'read', context=context)
res = super(mail_message, self).read(cr, uid, ids, fields=fields, context=context, load=load)
return res
def unlink(self, cr, uid, ids, context=None):
# cascade-delete attachments that are directly attached to the message (should only happen
# for mail.messages that act as parent for a standalone mail.mail record).
self.check_access_rule(cr, uid, ids, 'unlink', context=context)
attachments_to_delete = []
for message in self.browse(cr, uid, ids, context=context):
for attach in message.attachment_ids:
@ -499,7 +502,6 @@ class mail_message(osv.Model):
fol_objs = fol_obj.browse(cr, uid, fol_ids, context=context)
extra_notified = set(fol.partner_id.id for fol in fol_objs)
missing_notified = extra_notified - partners_to_notify
missing_notified = missing_notified
if missing_notified:
self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(4, p_id) for p_id in missing_notified]}, context=context)
partners_to_notify |= extra_notified

View File

@ -56,6 +56,7 @@
<field name="subject" string="Content" filter_domain="['|', ('subject', 'ilike', self), ('body', 'ilike', self)]" />
<field name="type"/>
<field name="author_id"/>
<field name="partner_ids"/>
<filter string="Unread"
name="unread_message" help="Show unread message"
domain="[('unread', '=', True)]"/>
@ -87,21 +88,28 @@
<record id="action_mail_inbox_feeds" model="ir.actions.client">
<field name="name">Inbox</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('notification_ids.partner_id.user_ids', 'in', [uid]),('unread', '=', True)],
<field name="params" eval="&quot;{'domain': [('notification_ids.partner_id.user_ids', 'in', [uid]),('notification_ids.read', '=', False)],
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
<record id="action_mail_to_me_feeds" model="ir.actions.client">
<field name="name">To: me</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('partner_ids.user_ids', 'in', [uid]),('notification_ids.read', '=', False),('create_uid', '!=', uid)],
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
<record id="action_mail_archives_feeds" model="ir.actions.client">
<field name="name">Archives</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('notification_ids.partner_id.user_ids', 'in', [uid]),('unread', '=', False)],
<field name="params" eval="&quot;{'domain': [('notification_ids.partner_id.user_ids', 'in', [uid]),('notification_ids.read', '=', True)],
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
<record id="action_mail_sent_feeds" model="ir.actions.client">
<field name="name">Sent</field>
<field name="tag">mail.wall</field>
<field name="params" eval="&quot;{'domain': [('author_id.user_ids', 'in', [uid])],
<field name="params" eval="&quot;{'domain': [('create_uid', '=', uid)],
'context': {'default_model': 'res.partner'} }&quot;"/>
</record>
</data>

View File

@ -102,12 +102,12 @@ class mail_thread(osv.AbstractModel):
# find the document followers, update the data
fol_obj = self.pool.get('mail.followers')
fol_ids = fol_obj.search(cr, uid, [
fol_ids = fol_obj.search(cr, SUPERUSER_ID, [
('partner_id', '=', user_pid),
('res_id', 'in', ids),
('res_model', '=', self._name),
], context=context)
for fol in fol_obj.browse(cr, uid, fol_ids, context=context):
for fol in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context):
thread_subtype_dict = res[fol.res_id]['message_subtype_data']
res[fol.res_id]['message_is_follower'] = True
for subtype in fol.subtype_ids:

View File

@ -3,7 +3,7 @@
<data>
<!-- Top menu item -->
<menuitem name="Home"
<menuitem name="Mails"
id="mail_feeds_main"
groups="base.group_user"
sequence="10"/>
@ -18,6 +18,12 @@
<field name="action" ref="action_mail_inbox_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
<record id="mail_tomefeeds" model="ir.ui.menu">
<field name="name">To: me</field>
<field name="sequence" eval="11"/>
<field name="action" ref="action_mail_to_me_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
<record id="mail_archivesfeeds" model="ir.ui.menu">
<field name="name">Archives</field>
<field name="sequence" eval="12"/>

View File

@ -1115,6 +1115,9 @@ openerp.mail = function(session) {
/* Send the records to his parent thread */
switch_new_message: function(records) {
console.log(records);
var self=this;
_(records).each(function(record){
self.browse_thread({

View File

@ -74,7 +74,7 @@ openerp_mail_followers = function(session, mail) {
target: 'new',
context: {
'default_res_model': self.view.dataset.model,
'default_res_id': self.view.datarecord.id
'default_res_id': self.view.dataset.ids[0]
},
}
self.do_action(action, function() { self.read_value(); });
@ -83,7 +83,7 @@ openerp_mail_followers = function(session, mail) {
read_value: function() {
var self = this;
return this.ds_model.read_ids([this.view.datarecord.id], ['message_follower_ids']).pipe(function (results) {
return this.ds_model.read_ids([this.view.dataset.ids[0]], ['message_follower_ids']).pipe(function (results) {
self.set_value(results[0].message_follower_ids);
});
},
@ -158,7 +158,7 @@ openerp_mail_followers = function(session, mail) {
set_subtypes:function(data){
var self = this;
var records = (data[this.view.datarecord.id] || data[null]).message_subtype_data;
var records = data[this.view.dataset.ids[0]].message_subtype_data;
_(records).each(function (record, record_name) {
record.name = record_name;
@ -168,14 +168,14 @@ openerp_mail_followers = function(session, mail) {
},
/** Display subtypes: {'name': default, followed} */
display_subtypes: function (visible) {
display_subtypes: function () {
var self = this;
var recthread_subtypes = self.$('.oe_recthread_subtypes');
subtype_list_ul = self.$('ul.oe_subtypes');
if(subtype_list_ul.is(":empty")) {
var context = new session.web.CompoundContext(this.build_context(), {});
this.ds_model.call('get_message_subtypes',[[self.view.datarecord.id], context]).pipe(this.proxy('set_subtypes'));
this.ds_model.call('get_message_subtypes',[[self.view.dataset.ids[0]], context]).pipe(this.proxy('set_subtypes'));
}
},
@ -191,7 +191,7 @@ openerp_mail_followers = function(session, mail) {
$(record).attr('checked',false);
});
var context = new session.web.CompoundContext(this.build_context(), {});
return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], [this.session.uid], context]).pipe(this.proxy('read_value'));
return this.ds_model.call('message_unsubscribe_users', [[this.view.dataset.ids[0]], [this.session.uid], context]).pipe(this.proxy('read_value'));
},
do_update_subscription: function (event) {
@ -207,9 +207,9 @@ openerp_mail_followers = function(session, mail) {
return this.do_unfollow();
else{
var context = new session.web.CompoundContext(this.build_context(), {});
return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]).pipe(function(value_){
self.read_value(value_);
self.display_subtypes(true);
return this.ds_model.call('message_subscribe_users', [[this.view.dataset.ids[0]], [this.session.uid], undefined, context]).pipe(function(){
self.read_value();
self.display_subtypes();
});
}

View File

@ -111,8 +111,7 @@
wall main template
Template used to display the communication history in the wall.
-->
<div t-name="mail.wall" class="oe_view_manager oe_mail_wall oe_view_manag
er_current">
<div t-name="mail.wall" class="oe_view_manager oe_mail_wall oe_view_manager_current">
<table class="oe_view_manager_header">
<colgroup>
<col width="33%"/>

View File

@ -112,7 +112,7 @@ class procurement_order(osv.osv):
def production_order_create_note(self, cr, uid, ids, context=None):
for procurement in self.browse(cr, uid, ids, context=context):
body = "Manufacturing Order <em>%s</em> created." % ( procurement.production_id.name,)
body = _("Manufacturing Order <em>%s</em> created.") % ( procurement.production_id.name,)
self.message_post(cr, uid, [procurement.id], body=body, context=context)
procurement_order()