[IMP]mail: secu
bzr revid: chm@openerp.com-20121012124003-zs8uj68gr1upgc57
This commit is contained in:
parent
4a77345f63
commit
adc318837a
|
@ -232,12 +232,12 @@ class mail_message(osv.Model):
|
|||
# expandable for not show message
|
||||
for msg in tree:
|
||||
# get all childs
|
||||
not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',msg.id],['id','not in',message_loaded_ids]], None, limit=1000)
|
||||
not_loaded_ids = self.search(cr, uid, [['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 in self.browse(cr, SUPERUSER_ID, not_loaded_ids, context=context):
|
||||
for not_loaded in self.browse(cr, uid, not_loaded_ids, context=context):
|
||||
if not_loaded not in tree:
|
||||
nb+=1
|
||||
if id_min==None or id_min>not_loaded.id:
|
||||
|
@ -270,7 +270,7 @@ class mail_message(osv.Model):
|
|||
message_loaded_ids.append( msg.id )
|
||||
|
||||
# expandable for limit max
|
||||
ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded_ids]], context=context, limit=1)
|
||||
ids = self.search(cr, uid, domain+[['id','not in',message_loaded_ids]], context=context, limit=1)
|
||||
if len(ids) > 0:
|
||||
result.append(
|
||||
{
|
||||
|
@ -309,33 +309,47 @@ class mail_message(osv.Model):
|
|||
context = context or {}
|
||||
|
||||
tree = []
|
||||
result = []
|
||||
message_ids = []
|
||||
record = None
|
||||
|
||||
# select ids
|
||||
if ids and ids!=[None]:
|
||||
for msg in self.browse(cr, uid, ids, context=context):
|
||||
result.append(self._message_dict_get(cr, uid, msg, context=context))
|
||||
return result
|
||||
message_ids.append(msg.id)
|
||||
|
||||
# key: ID, value: record
|
||||
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 not in tree and msg.id not in message_loaded_ids :
|
||||
record = self._message_dict_get(cr, uid, msg, context=context)
|
||||
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
|
||||
# key: ID, value: tree
|
||||
if not ids:
|
||||
ids = self.search(cr, uid, domain, context=context, limit=limit)
|
||||
for msg in self.browse(cr, uid, ids, context=context):
|
||||
# if not in tree and not in message_loded list
|
||||
if msg not in tree and msg.id not in message_loaded_ids :
|
||||
message_ids.append(msg.id)
|
||||
tree.append(msg)
|
||||
# if not in record and not in message_loded list
|
||||
if msg.id not in message_loaded_ids :
|
||||
record = self._message_dict_get(cr, uid, msg, context=context)
|
||||
result.append(record)
|
||||
|
||||
try:
|
||||
parent = msg.parent_id
|
||||
except orm.except_orm, inst:
|
||||
print inst
|
||||
parent = False
|
||||
|
||||
while parent and parent.id != parent_id:
|
||||
parent_id = msg.parent_id.id
|
||||
if msg.parent_id.id not in tree:
|
||||
tree.append(parent)
|
||||
# if not in tree and not in message_loded list
|
||||
if parent.id not in message_loaded_ids :
|
||||
message_ids.append(parent.id)
|
||||
|
||||
try:
|
||||
parent = msg.parent_id
|
||||
except orm.except_orm, inst:
|
||||
print inst
|
||||
parent = False
|
||||
|
||||
result = []
|
||||
for msg in self.browse(cr, uid, message_ids, context=context):
|
||||
record = self._message_dict_get(cr, uid, msg, context=context)
|
||||
result.append( record )
|
||||
|
||||
result = sorted(result, key=lambda k: k['id'])
|
||||
|
||||
|
@ -371,7 +385,8 @@ class mail_message(osv.Model):
|
|||
- Otherwise: raise
|
||||
- create: if
|
||||
- I am in the document message_follower_ids OR
|
||||
- I can write on the related document if res_model, res_id
|
||||
- I can write on the related document if res_model, res_id OR
|
||||
- I write a mail to another user (no res_model)
|
||||
- Otherwise: raise
|
||||
- write: if
|
||||
- I can write on the related document if res_model, res_id
|
||||
|
@ -412,7 +427,7 @@ class mail_message(osv.Model):
|
|||
else:
|
||||
author_ids = []
|
||||
|
||||
# Create: Check message_follower_ids
|
||||
# Create: Check message_follower_ids and author_ids
|
||||
if operation == 'create':
|
||||
doc_follower_ids = []
|
||||
for model, mids in model_record_ids.items():
|
||||
|
@ -428,6 +443,12 @@ class mail_message(osv.Model):
|
|||
else:
|
||||
doc_follower_ids = []
|
||||
|
||||
# Create/write: Check author_ids
|
||||
if operation == 'create' or operation == 'write':
|
||||
author_ids = author_ids+[mid for mid, message in message_values.iteritems()
|
||||
if message.get('author_id') and message.get('author_id') == partner_id and not message.get('res_model')]
|
||||
|
||||
|
||||
# Calculate remaining ids, and related model/res_ids
|
||||
model_record_ids = {}
|
||||
other_ids = set(ids).difference(set(notified_ids), set(author_ids), set(doc_follower_ids))
|
||||
|
@ -511,6 +532,8 @@ class mail_message(osv.Model):
|
|||
Call mail_notification.notify to manage the email sending
|
||||
"""
|
||||
message = self.browse(cr, uid, newid, context=context)
|
||||
|
||||
print message.partner_ids
|
||||
if not message:
|
||||
self._notify_followers(cr, uid, newid, message, context=context)
|
||||
|
||||
|
|
|
@ -221,8 +221,8 @@ class mail_thread(osv.AbstractModel):
|
|||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
""" Override to subscribe the current user. """
|
||||
thread_id = super(mail_thread, self).create(cr, uid, vals, context=context)
|
||||
self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context)
|
||||
thread_id = super(mail_thread, self).create(cr, SUPERUSER_ID, vals, context=context)
|
||||
self.message_subscribe_users(cr, SUPERUSER_ID, [thread_id], [uid], context=context)
|
||||
return thread_id
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
@ -682,9 +682,10 @@ class mail_thread(osv.AbstractModel):
|
|||
# if the parent is private, the message must be private
|
||||
if parent_id:
|
||||
msg = messages.browse(cr, uid, parent_id, context=context)
|
||||
if msg.is_private:
|
||||
values["is_private"] = msg.is_private
|
||||
values["is_private"] = msg.is_private or False
|
||||
values["partner_ids"] = [(4, partner.id) for partner in msg.partner_ids]
|
||||
|
||||
print values
|
||||
# Avoid warnings about non-existing fields
|
||||
for x in ('from', 'to', 'cc'):
|
||||
values.pop(x, None)
|
||||
|
|
|
@ -27,6 +27,7 @@ openerp.mail = function(session) {
|
|||
if( key!='default_template_id' &&
|
||||
key!='default_use_template' &&
|
||||
key!='default_is_private' &&
|
||||
key!='default_partner_ids' &&
|
||||
key!='default_model' &&
|
||||
key!='default_res_id' &&
|
||||
key!='default_subtype' &&
|
||||
|
@ -331,6 +332,11 @@ openerp.mail = function(session) {
|
|||
for(var i in this.attachment_ids){
|
||||
attachments.push(this.attachment_ids[i].id);
|
||||
}
|
||||
var partner_ids=[];
|
||||
for(var i in this.partner_ids){
|
||||
partner_ids.push(this.partner_ids[i][0]);
|
||||
}
|
||||
|
||||
var action = {
|
||||
type: 'ir.actions.act_window',
|
||||
res_model: 'mail.compose.message',
|
||||
|
@ -346,14 +352,15 @@ openerp.mail = function(session) {
|
|||
'default_is_private': true,
|
||||
'default_parent_id': this.id,
|
||||
'default_body': mail.ChatterUtils.get_text2html(this.$('textarea').val() || ''),
|
||||
'default_attachment_ids': attachments
|
||||
'default_attachment_ids': attachments,
|
||||
'default_partner_ids': partner_ids
|
||||
},
|
||||
};
|
||||
this.do_action(action);
|
||||
},
|
||||
|
||||
on_cancel: function(){
|
||||
event.stopPropagation();
|
||||
on_cancel: function(event){
|
||||
if(event) event.stopPropagation();
|
||||
this.$('textarea').val("");
|
||||
this.$('input[data-id]').remove();
|
||||
//this.attachment_ids=[];
|
||||
|
@ -365,6 +372,7 @@ openerp.mail = function(session) {
|
|||
|
||||
/*post a message and fetch the message*/
|
||||
on_message_post: function (body) {
|
||||
var self = this;
|
||||
|
||||
if (! body) {
|
||||
var comment_node = this.$('textarea');
|
||||
|
@ -390,9 +398,11 @@ openerp.mail = function(session) {
|
|||
false,
|
||||
this.context.default_parent_id,
|
||||
attachments]
|
||||
).then(this.parent_thread.proxy('switch_new_message'));
|
||||
this.attachment_ids=[];
|
||||
this.on_cancel();
|
||||
).then(function(records){
|
||||
self.parent_thread.switch_new_message(records);
|
||||
self.attachment_ids=[];
|
||||
self.on_cancel();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
@ -451,8 +461,12 @@ openerp.mail = function(session) {
|
|||
*/
|
||||
on_expandable: function (event) {
|
||||
if(event)event.stopPropagation();
|
||||
var self = this;
|
||||
this.parent_thread.message_fetch(false, this.domain, this.context);
|
||||
this.destroy();
|
||||
this.$el.fadeOut(300, function(){
|
||||
self.destroy();
|
||||
});
|
||||
this.$('*').unbind();
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
@ -841,7 +855,7 @@ openerp.mail = function(session) {
|
|||
|
||||
this.messages = [];
|
||||
|
||||
this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model);
|
||||
this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model || 'mail.thread');
|
||||
this.ds_message = new session.web.DataSetSearch(this, 'mail.message');
|
||||
},
|
||||
|
||||
|
@ -1002,7 +1016,7 @@ openerp.mail = function(session) {
|
|||
* @param {Array} replace_domain: added to this.domain
|
||||
* @param {Object} replace_context: added to this.context
|
||||
*/
|
||||
message_fetch: function (initial_mode, replace_domain, replace_context, ids) {
|
||||
message_fetch: function (initial_mode, replace_domain, replace_context, ids, callback) {
|
||||
var self = this;
|
||||
|
||||
// initial mode: try to use message_data or message_ids
|
||||
|
@ -1015,7 +1029,7 @@ openerp.mail = function(session) {
|
|||
fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() );
|
||||
|
||||
return this.ds_message.call('message_read', [ids, fetch_domain, fetch_context, 0, this.context.default_parent_id || undefined]
|
||||
).then(this.proxy('switch_new_message'));
|
||||
).then(function (records) { self.switch_new_message(records); });
|
||||
},
|
||||
|
||||
/* create record object and linked him
|
||||
|
@ -1072,13 +1086,15 @@ openerp.mail = function(session) {
|
|||
// check older and newer message for insert
|
||||
var parent_newer = false;
|
||||
var parent_older = false;
|
||||
for(var i in thread_messages){
|
||||
if(thread_messages[i].id > message.id){
|
||||
if(!parent_newer || parent_newer.id>=thread_messages[i].id)
|
||||
parent_newer = thread_messages[i];
|
||||
} else if(thread_messages[i].id>0 && thread_messages[i].id < message.id) {
|
||||
if(!parent_older || parent_older.id<thread_messages[i].id)
|
||||
parent_older = thread_messages[i];
|
||||
if ( message.id > 0 ){
|
||||
for(var i in thread_messages){
|
||||
if(thread_messages[i].id > message.id){
|
||||
if(!parent_newer || parent_newer.id>=thread_messages[i].id)
|
||||
parent_newer = thread_messages[i];
|
||||
} else if(thread_messages[i].id>0 && thread_messages[i].id < message.id) {
|
||||
if(!parent_older || parent_older.id<thread_messages[i].id)
|
||||
parent_older = thread_messages[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1099,12 +1115,13 @@ openerp.mail = function(session) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if(sort){
|
||||
if(sort && message.id > 0){
|
||||
message.prependTo(thread.list_ul);
|
||||
} else {
|
||||
message.appendTo(thread.list_ul);
|
||||
}
|
||||
}
|
||||
|
||||
return message
|
||||
},
|
||||
|
||||
|
@ -1115,9 +1132,6 @@ 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({
|
||||
|
|
|
@ -158,6 +158,9 @@ openerp_mail_followers = function(session, mail) {
|
|||
|
||||
set_subtypes:function(data){
|
||||
var self = this;
|
||||
if (!data[this.view.dataset.ids[0]]) {
|
||||
return false;
|
||||
}
|
||||
var records = data[this.view.dataset.ids[0]].message_subtype_data;
|
||||
|
||||
_(records).each(function (record, record_name) {
|
||||
|
|
Loading…
Reference in New Issue