[ADD] Encrypted Fields

This commit is contained in:
Daniel Reis 2020-05-22 12:31:05 +01:00
parent 11d6745d41
commit 2d00028134
9 changed files with 197 additions and 0 deletions

View File

@ -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
<https://github.com/OCA/{project_repo}/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Firstname Lastname <email.address@example.org>
* Second Person <second.person@example.org>
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.

View File

@ -0,0 +1 @@
from . import models

View File

@ -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': [
],
}

View File

@ -0,0 +1,2 @@
from . import base_encrypted_mixin
from . import res_partner

View File

@ -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()

View File

@ -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",
)

View File

@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 Open Source Integrators
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="res_partner_form_view">
<field name="name">res.partner.form (in data_encryption_field)</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<page name="internal_notes" position="inside">
<separator string="Private Text"/>
<field name="private_text"/>
</page>
</field>
</record>
</odoo>