diff --git a/attachment_metadata/README.rst b/attachment_metadata/README.rst new file mode 100644 index 000000000..f9640f29e --- /dev/null +++ b/attachment_metadata/README.rst @@ -0,0 +1,51 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +Attachment Metadata +====================== + +This module was written to extend the functionality of ir.attachment + +Installation +============ + +Installable without any requirements + +Usage +===== + +THe module just add some field to ir.attachment + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +Credits +======= + +* Joel Grand-Guillaume Camptocamp +* initOS +* Valentin CHEMIERE + +Contributors +------------ + +* Sebastien BEAU + +Maintainer +---------- + +* Valentin CHEMIERE + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/attachment_metadata/__init__.py b/attachment_metadata/__init__.py new file mode 100644 index 000000000..3e53cd607 --- /dev/null +++ b/attachment_metadata/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for OpenERP +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from . import attachment diff --git a/attachment_metadata/__openerp__.py b/attachment_metadata/__openerp__.py new file mode 100644 index 000000000..232b1f84a --- /dev/null +++ b/attachment_metadata/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for OpenERP +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +{'name': 'attachment_metadata', + 'version': '0.0.1', + 'author': 'Akretion', + 'website': 'www.akretion.com', + 'license': 'AGPL-3', + 'category': 'Generic Modules', + 'description': """ + Add some useful field to ir.attachment object like: + internal and external hash for coherence verification + """, + 'depends': [ + 'base', + 'mail' + ], + 'data': [ + 'attachment_view.xml', + 'security/ir.model.access.csv', + ], + 'installable': True, + 'application': False, + } diff --git a/attachment_metadata/attachment.py b/attachment_metadata/attachment.py new file mode 100644 index 000000000..b75ff47a6 --- /dev/null +++ b/attachment_metadata/attachment.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for OpenERP +# Copyright 2011-2012 Camptocamp SA +# @author: Joel Grand-Guillaume +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from openerp import models, fields, api, _ +from openerp.exceptions import Warning +import hashlib +from base64 import b64decode + + +class IrAttachmentMetadata(models.Model): + _name = 'ir.attachment.metadata' + _inherits = {'ir.attachment': 'attachment_id'} + + internal_hash = fields.Char(store=True, compute='_compute_hash') + external_hash = fields.Char() + attachment_id = fields.Many2one('ir.attachment', required=True, + ondelete='cascade') + + @api.depends('datas', 'external_hash') + def _compute_hash(self): + if self.datas: + self.internal_hash = hashlib.md5(b64decode(self.datas)).hexdigest() + if self.external_hash and self.internal_hash != self.external_hash: + raise Warning(_('File corrupted'), + _("Something was wrong with the retreived file, " + "please relaunch the task.")) diff --git a/attachment_metadata/attachment_view.xml b/attachment_metadata/attachment_view.xml new file mode 100644 index 000000000..a95535596 --- /dev/null +++ b/attachment_metadata/attachment_view.xml @@ -0,0 +1,17 @@ + + + + + + ir.attachment.metadata + + + + + + + + + + + diff --git a/attachment_metadata/security/ir.model.access.csv b/attachment_metadata/security/ir.model.access.csv new file mode 100644 index 000000000..9b01638c4 --- /dev/null +++ b/attachment_metadata/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_attachment_metadata_user,ir.attachment.metadata.user,model_ir_attachment_metadata,base.group_user,1,0,0,0