diff --git a/data_encryption_field/README.rst b/data_encryption_field/README.rst new file mode 100644 index 0000000..91609ed --- /dev/null +++ b/data_encryption_field/README.rst @@ -0,0 +1,91 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +===================== +Data Encryption Field +===================== + +Fields supporting encrypted data + +Installation +============ + +To install this module, you need to: + +#. Do this ... + +Configuration +============= + +To configure this module, you need to: + +#. Go to ... + +.. figure:: path/to/local/image.png + :alt: alternative description + :width: 600 px + +Usage +===== + +To use this module, you need to: + +#. Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +Known issues / Roadmap +====================== + +* ... + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Firstname Lastname +* Second Person + +Funders +------- + +The development of this module has been financially supported by: + +* Company 1 name +* Company 2 name + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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 https://odoo-community.org. diff --git a/data_encryption_field/__init__.py b/data_encryption_field/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/data_encryption_field/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/data_encryption_field/__manifest__.py b/data_encryption_field/__manifest__.py new file mode 100644 index 0000000..2b8fdbd --- /dev/null +++ b/data_encryption_field/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Data Encryption Field', + 'summary': """ + Fields supporting encrypted data""", + 'version': '12.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Open Source Integrators,Odoo Community Association (OCA)', + 'depends': [ + 'data_encryption' + ], + 'data': [ + 'views/res_partner.xml', + ], + 'demo': [ + ], +} diff --git a/data_encryption_field/models/__init__.py b/data_encryption_field/models/__init__.py new file mode 100644 index 0000000..b1e6f74 --- /dev/null +++ b/data_encryption_field/models/__init__.py @@ -0,0 +1,2 @@ +from . import base_encrypted_mixin +from . import res_partner diff --git a/data_encryption_field/models/base_encrypted_mixin.py b/data_encryption_field/models/base_encrypted_mixin.py new file mode 100644 index 0000000..658d4aa --- /dev/null +++ b/data_encryption_field/models/base_encrypted_mixin.py @@ -0,0 +1,12 @@ +# Copyright 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models, _ + + +class BaseEncryptedMixin(models.Model): + + _name = 'base.encrypted.mixin' + _description = 'Base Encrypted Mixin' # TODO + + name = fields.Char() diff --git a/data_encryption_field/models/res_partner.py b/data_encryption_field/models/res_partner.py new file mode 100644 index 0000000..8abe1d6 --- /dev/null +++ b/data_encryption_field/models/res_partner.py @@ -0,0 +1,38 @@ +# Copyright 2020 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + def _inverse_private_text(self): + field_names = ["private_text"] + EncryptedData = self.env["encrypted.data"].sudo() + for record in self: + encrypted_data_name = "fields:%s,%s" % ( + record._name, record.id) + # values = EncryptedData._encrypted_read_json( + # encrypted_data_name, env=env) + values = {x: getattr(record, x) for x in field_names} + EncryptedData._encrypted_store_json( + encrypted_data_name, values + ) + + def _compute_private_text(self): + EncryptedData = self.env["encrypted.data"].sudo() + for record in self: + field_names = ["private_text"] + encrypted_data_name = "fields:%s,%s" % ( + record._name, record.id) + stored_values = EncryptedData._encrypted_read_json( + encrypted_data_name) + values = {x: stored_values.get(x) for x in field_names} + for field in field_names: + setattr(record, field, values.get(field)) + + private_text = fields.Text( + compute="_compute_private_text", + inverse="_inverse_private_text", + ) diff --git a/data_encryption_field/readme/DESCRIPTION.rst b/data_encryption_field/readme/DESCRIPTION.rst new file mode 100644 index 0000000..3b704a3 --- /dev/null +++ b/data_encryption_field/readme/DESCRIPTION.rst @@ -0,0 +1,13 @@ +The configuration file needs to edited, to add: + +* ``running_env=test``: to set the environment to use, ``test`` in this example. +* ``encryption_key_test=xxxx``: to set the encryption key to use for a particular environment, ``test`` in this case. + +If no encryption key is set, the User Interface will suggest one when trying to save encrypted data. + +The data written in an ancrypted field is stored in a dedicated Model, +``encryted.data``, that also holds the logic to encrypt and decrypt data. + +Separate values are stored for each environment. +This means that if we set value "X" on the test environment, +this value will only be available when the test environment is the active one. diff --git a/data_encryption_field/static/description/icon.png b/data_encryption_field/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/data_encryption_field/static/description/icon.png differ diff --git a/data_encryption_field/views/res_partner.xml b/data_encryption_field/views/res_partner.xml new file mode 100644 index 0000000..186fde4 --- /dev/null +++ b/data_encryption_field/views/res_partner.xml @@ -0,0 +1,21 @@ + + + + + + + res.partner.form (in data_encryption_field) + res.partner + + + + + + + + + + + +