[IMP]mail: add a download_attachment_ids field. the controler can access ton the content of attachemnt with mail security

bzr revid: chm@openerp.com-20121207131118-l88qnfn06aem7ey1
This commit is contained in:
Christophe Matthieu 2012-12-07 14:11:18 +01:00
parent 97505900e6
commit 74d514a213
2 changed files with 16 additions and 5 deletions

View File

@ -118,6 +118,16 @@ class mail_message(osv.Model):
res.append((message.id, self._shorten_name(name.lstrip(' :'))))
return res
def _download_attachment(self, cr, uid, ids, name, arg, context=None):
""" Return the content of linked attachments. """
result = dict.fromkeys(ids, [])
ir_attachment_obj = self.pool.get('ir.attachment')
for message in self.read(cr, uid, ids, ['attachment_ids'], context=context):
if message.get('attachment_ids'):
result[message['id']] = ir_attachment_obj.read(cr, SUPERUSER_ID, list(message.get('attachment_ids')), ['id', 'datas_fname', 'datas', 'type'], context=context)
return result
_columns = {
'type': fields.selection([
('email', 'Email'),
@ -137,6 +147,7 @@ class mail_message(osv.Model):
help='Partners that have a notification pushing this message in their mailboxes'),
'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel',
'message_id', 'attachment_id', 'Attachments'),
'download_attachment_ids':fields.function(_download_attachment, string='Attachments content'),
'parent_id': fields.many2one('mail.message', 'Parent Message', select=True,
ondelete='set null', help="Initial thread message."),
'child_ids': fields.one2many('mail.message', 'parent_id', 'Child Messages'),
@ -250,7 +261,7 @@ class mail_message(osv.Model):
partner_tree = dict((partner[0], partner) for partner in partners)
# 2. Attachments
attachments = ir_attachment_obj.read(cr, uid, list(attachment_ids), ['id', 'datas_fname'], context=context)
attachments = ir_attachment_obj.read(cr, SUPERUSER_ID, list(attachment_ids), ['id', 'datas_fname'], context=context)
attachments_tree = dict((attachment['id'], {'id': attachment['id'], 'filename': attachment['datas_fname']}) for attachment in attachments)
# 3. Update message dictionaries

View File

@ -29,8 +29,8 @@ openerp.mail = function (session) {
},
/* Get the url of an attachment {'id': id} */
get_attachment_url: function (session, attachment) {
return session.url('/web/binary/saveas', {model: 'ir.attachment', field: 'datas', filename_field: 'datas_fname', id: attachment['id']});
get_attachment_url: function (session, id_message, id_attachment) {
return session.url('/web/binary/mail', {'id_message': id_message, 'id_attachment': id_attachment});
},
/**
@ -258,7 +258,7 @@ openerp.mail = function (session) {
for (var l in this.attachment_ids) {
var attach = this.attachment_ids[l];
if (!attach.formating) {
attach.url = mail.ChatterUtils.get_attachment_url(this.session, attach);
attach.url = mail.ChatterUtils.get_attachment_url(this.session, this.id, attach.id);
attach.filetype = mail.ChatterUtils.filetype(attach.filename);
attach.name = mail.ChatterUtils.breakword(attach.name || attach.filename);
attach.formating = true;
@ -431,7 +431,7 @@ openerp.mail = function (session) {
'id': result.id,
'name': result.name,
'filename': result.filename,
'url': mail.ChatterUtils.get_attachment_url(this.session, result)
'url': mail.ChatterUtils.get_attachment_url(this.session, this.id, result.id)
};
}
}