From 48c6ea72ff94a156995aeb08089dab9bfec4e11c Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 30 Nov 2012 10:06:55 +0100 Subject: [PATCH 01/17] [FIX] web form : catch and display error when there are an error in an attachment upload bzr revid: chm@openerp.com-20121130090655-gmymwe1z1ofl7wn9 --- addons/mail/static/src/js/mail.js | 56 ++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index a5beaac229f..e08f828d272 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -422,15 +422,25 @@ openerp.mail = function (session) { /* when the file is uploaded */ on_attachment_loaded: function (event, result) { - for (var i in this.attachment_ids) { - if (this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { - this.attachment_ids[i]={ - 'id': result.id, - 'name': result.name, - 'filename': result.filename, - 'url': mail.ChatterUtils.get_attachment_url(this.session, result) - }; + + if (result.erorr || !result.id ) { + + this.do_warn(result.title, result.erorr); + this.attachment_ids = _.filter(this.attachment_ids, function (val) { return !val.upload; }); + + } else { + + for (var i in this.attachment_ids) { + if (this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { + this.attachment_ids[i]={ + 'id': result.id, + 'name': result.name, + 'filename': result.filename, + 'url': mail.ChatterUtils.get_attachment_url(this.session, result) + }; + } } + } this.display_attachments(); @@ -486,6 +496,11 @@ openerp.mail = function (session) { }, on_compose_fullmail: function (default_composition_mode) { + + if(!this.do_check_attachment_upload()) { + return false; + } + if (default_composition_mode == 'reply') { var context = { 'default_composition_mode': default_composition_mode, @@ -536,31 +551,32 @@ openerp.mail = function (session) { this.reinit(); }, + /* return true if all file are complete else return false and make an alert */ + do_check_attachment_upload: function () { + if (_.find(this.attachment_ids, function (file) {return file.upload;})) { + this.do_warn(session.web._t('Attachment error :'), session.web._t('Please, wait while the file is uploading.')); + return false; + } else { + return true; + } + }, + /*post a message and fetch the message*/ on_message_post: function (event) { var self = this; var comment_node = this.$('textarea'); var body = comment_node.val(); - comment_node.val(''); - var attachments=[]; - for (var i in this.attachment_ids) { - if (this.attachment_ids[i].upload) { - session.web.dialog($('
' + session.web.qweb.render('CrashManager.warning', {message: 'Please, wait while the file is uploading.'}) + '
')); - return false; - } - attachments.push(this.attachment_ids[i].id); - } - - if (body.match(/\S+/)) { + if (this.do_check_attachment_upload() && (this.attachment_ids.length || body.match(/\S+/))) { + comment_node.val(''); //session.web.blockUI(); this.parent_thread.ds_thread.call('message_post_user_api', [ this.context.default_res_id, body, false, this.context.default_parent_id, - attachments, + _.map(this.attachment_ids, function (file) {return file.id;}), this.parent_thread.context ]).done(function (record) { var thread = self.parent_thread; From 61065b6d04248aa496765e1035c4c90cbdc38de7 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 30 Nov 2012 12:09:02 +0100 Subject: [PATCH 02/17] [IMP] mail: change access for create message for the attachments bzr revid: chm@openerp.com-20121130110902-1qzmgvinhc0q0i3j --- addons/mail/mail_message.py | 4 ++-- addons/mail/static/src/js/mail.js | 3 +-- addons/portal/security/ir.model.access.csv | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 3273870f5e0..8bb33df6d20 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -631,8 +631,8 @@ class mail_message(osv.Model): model_obj = self.pool.get(model) mids = model_obj.exists(cr, uid, mids) if operation in ['create', 'write', 'unlink']: - model_obj.check_access_rights(cr, uid, 'write') - model_obj.check_access_rule(cr, uid, mids, 'write', context=context) + model_obj.check_access_rights(cr, uid, 'read') + model_obj.check_access_rule(cr, uid, mids, 'read', context=context) else: model_obj.check_access_rights(cr, uid, operation) model_obj.check_access_rule(cr, uid, mids, operation, context=context) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index e08f828d272..3f424eebce7 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -569,7 +569,6 @@ openerp.mail = function (session) { var body = comment_node.val(); if (this.do_check_attachment_upload() && (this.attachment_ids.length || body.match(/\S+/))) { - comment_node.val(''); //session.web.blockUI(); this.parent_thread.ds_thread.call('message_post_user_api', [ this.context.default_res_id, @@ -589,8 +588,8 @@ openerp.mail = function (session) { var message = thread.create_message_object( data[0] ); // insert the message on dom thread.insert_message( message, root ? undefined : self.$el, root ); - self.on_cancel(); }); + self.on_cancel(); //session.web.unblockUI(); }); return true; diff --git a/addons/portal/security/ir.model.access.csv b/addons/portal/security/ir.model.access.csv index b9f98f81fd7..59ca37e213d 100644 --- a/addons/portal/security/ir.model.access.csv +++ b/addons/portal/security/ir.model.access.csv @@ -7,3 +7,4 @@ access_res_partner_category,res.partner_category,base.model_res_partner_category access_res_partner_title,res.partner_title,base.model_res_partner_title,portal.group_portal,1,0,0,0 access_acquirer,portal.payment.acquirer,portal.model_portal_payment_acquirer,,1,0,0,0 access_acquirer_all,portal.payment.acquirer,portal.model_portal_payment_acquirer,base.group_system,1,1,1,1 +access_ir_attachment_group_portal,ir.attachment group_portal,base.model_ir_attachment,portal.group_portal,1,0,1,0 \ No newline at end of file From 84ac690b92d92b9ed2ce0c54ae3dfe70dd2fda47 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 7 Dec 2012 09:46:10 +0100 Subject: [PATCH 03/17] [IMP] mail: fix attachment error bzr revid: chm@openerp.com-20121207084610-979a5om26shed1ak --- addons/mail/static/src/js/mail.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2d5d3e34475..12e83f8fccf 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -422,12 +422,11 @@ openerp.mail = function (session) { on_attachment_loaded: function (event, result) { if (result.erorr || !result.id ) { - - this.do_warn(result.title, result.erorr); + var error_title = result.error.split('\n')[0]; + var error_content = result.error.replace(/^.*\n/, ''); + this.do_warn(error_title, error_content); this.attachment_ids = _.filter(this.attachment_ids, function (val) { return !val.upload; }); - } else { - for (var i in this.attachment_ids) { if (this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { this.attachment_ids[i]={ @@ -438,10 +437,8 @@ openerp.mail = function (session) { }; } } - } this.display_attachments(); - var $input = this.$('input.oe_form_binary_file'); $input.after($input.clone(true)).remove(); this.$(".oe_attachment_file").show(); From f8c206b1b885d33286299d620c55bdcd9176b16e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 7 Dec 2012 10:09:41 +0100 Subject: [PATCH 04/17] [IMP] mail: display message attachment error bzr revid: chm@openerp.com-20121207090941-65b2vgwy066wlsmg --- addons/mail/static/src/js/mail.js | 4 +--- addons/mail/static/src/xml/mail.xml | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 12e83f8fccf..e1625089a51 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -422,9 +422,7 @@ openerp.mail = function (session) { on_attachment_loaded: function (event, result) { if (result.erorr || !result.id ) { - var error_title = result.error.split('\n')[0]; - var error_content = result.error.replace(/^.*\n/, ''); - this.do_warn(error_title, error_content); + this.do_warn( session.web.qweb.render('mail.error_upload'), result.error); this.attachment_ids = _.filter(this.attachment_ids, function (val) { return !val.upload; }); } else { for (var i in this.attachment_ids) { diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index cca908a5d98..f10770a27e1 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -179,6 +179,11 @@
No messages.
+ + Uploading error + Uploading error + Please, wait while the file is uploading.