From 179e8e93a719c7ae980420dfa9ceaa220ea140a9 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 12 Feb 2021 14:50:29 +0100 Subject: [PATCH 1/2] [ADD] setup.py --- .../base_export_anonymize/odoo/addons/base_export_anonymize | 1 + setup/base_export_anonymize/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/base_export_anonymize/odoo/addons/base_export_anonymize create mode 100644 setup/base_export_anonymize/setup.py diff --git a/setup/base_export_anonymize/odoo/addons/base_export_anonymize b/setup/base_export_anonymize/odoo/addons/base_export_anonymize new file mode 120000 index 0000000..e0c6418 --- /dev/null +++ b/setup/base_export_anonymize/odoo/addons/base_export_anonymize @@ -0,0 +1 @@ +../../../../base_export_anonymize \ No newline at end of file diff --git a/setup/base_export_anonymize/setup.py b/setup/base_export_anonymize/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/base_export_anonymize/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 23f1757b27def85e9d74a66edfee37b4ca56f6ad Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 12 Feb 2021 14:50:35 +0100 Subject: [PATCH 2/2] [12.0][ADD] - Base Export Anonymize Anonymize certain fields for a group of users when exporting them directly or via relational fields. --- base_export_anonymize/README.rst | 85 ++++ base_export_anonymize/__init__.py | 1 + base_export_anonymize/__manifest__.py | 22 + .../data/ir_config_parameter.xml | 12 + base_export_anonymize/models/__init__.py | 3 + base_export_anonymize/models/base.py | 42 ++ .../models/ir_model_fields.py | 23 + .../ir_model_fields_export_anonymize.py | 14 + base_export_anonymize/readme/CONTRIBUTORS.rst | 1 + base_export_anonymize/readme/DESCRIPTION.rst | 2 + base_export_anonymize/readme/USAGE.rst | 7 + base_export_anonymize/security/groups.xml | 10 + .../ir_model_fields_export_anonymize.xml | 27 ++ .../static/description/index.html | 432 ++++++++++++++++++ .../views/ir_model_fields.xml | 17 + .../ir_model_fields_export_anonymize.xml | 31 ++ 16 files changed, 729 insertions(+) create mode 100644 base_export_anonymize/README.rst create mode 100644 base_export_anonymize/__init__.py create mode 100644 base_export_anonymize/__manifest__.py create mode 100644 base_export_anonymize/data/ir_config_parameter.xml create mode 100644 base_export_anonymize/models/__init__.py create mode 100644 base_export_anonymize/models/base.py create mode 100644 base_export_anonymize/models/ir_model_fields.py create mode 100644 base_export_anonymize/models/ir_model_fields_export_anonymize.py create mode 100644 base_export_anonymize/readme/CONTRIBUTORS.rst create mode 100644 base_export_anonymize/readme/DESCRIPTION.rst create mode 100644 base_export_anonymize/readme/USAGE.rst create mode 100644 base_export_anonymize/security/groups.xml create mode 100644 base_export_anonymize/security/ir_model_fields_export_anonymize.xml create mode 100644 base_export_anonymize/static/description/index.html create mode 100644 base_export_anonymize/views/ir_model_fields.xml create mode 100644 base_export_anonymize/views/ir_model_fields_export_anonymize.xml diff --git a/base_export_anonymize/README.rst b/base_export_anonymize/README.rst new file mode 100644 index 0000000..1737245 --- /dev/null +++ b/base_export_anonymize/README.rst @@ -0,0 +1,85 @@ +===================== +Base Export Anonymize +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdata--protection-lightgray.png?logo=github + :target: https://github.com/OCA/data-protection/tree/12.0/base_export_anonymize + :alt: OCA/data-protection +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/data-protection-12-0/data-protection-12-0-base_export_anonymize + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/263/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Anonymize certain fields for a group of users when exporting them +directly or via relational fields. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to "Settings/Technical/Database Structure/Fields Export Anonymize" +* Add the filed to anonymize +* Add users to "Technical Settings / Anonymize data in export" group +* You can customize the displayed string when anonymizing from the system parameters. + +With a user of "Technical Settings / Anonymize data in export" group, export the +anonymized field. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Bejaoui Souheil + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/data-protection `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_export_anonymize/__init__.py b/base_export_anonymize/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/base_export_anonymize/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_export_anonymize/__manifest__.py b/base_export_anonymize/__manifest__.py new file mode 100644 index 0000000..82074db --- /dev/null +++ b/base_export_anonymize/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Base Export Anonymize", + "description": """ + Anonymize certain fields for a group of users when exporting them + directly or via relational fields. + """, + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + "website": "https://acsone.eu", + "depends": ["base"], + "data": [ + "data/ir_config_parameter.xml", + "security/groups.xml", + "security/ir_model_fields_export_anonymize.xml", + "views/ir_model_fields.xml", + "views/ir_model_fields_export_anonymize.xml", + ], +} diff --git a/base_export_anonymize/data/ir_config_parameter.xml b/base_export_anonymize/data/ir_config_parameter.xml new file mode 100644 index 0000000..7f0c698 --- /dev/null +++ b/base_export_anonymize/data/ir_config_parameter.xml @@ -0,0 +1,12 @@ + + + + + + + model.fields.export.anonymize.key + *********** + + + diff --git a/base_export_anonymize/models/__init__.py b/base_export_anonymize/models/__init__.py new file mode 100644 index 0000000..c34dc55 --- /dev/null +++ b/base_export_anonymize/models/__init__.py @@ -0,0 +1,3 @@ +from . import ir_model_fields +from . import ir_model_fields_export_anonymize +from . import base diff --git a/base_export_anonymize/models/base.py b/base_export_anonymize/models/base.py new file mode 100644 index 0000000..f610a38 --- /dev/null +++ b/base_export_anonymize/models/base.py @@ -0,0 +1,42 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class Base(models.AbstractModel): + + _inherit = "base" + + @api.model + def _export_anonymize(self, rows, index): + anonymize_key = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("model.fields.export.anonymize.key", "***********") + ) + for row in rows: + row[index] = anonymize_key + + @api.multi + def _export_rows(self, *args, **kwargs): + rows = super()._export_rows(*args, **kwargs) + if self.env.user.has_group( + "base_export_anonymize.group_anonymize_data_in_export" + ): + fields = args[0] + field_model = self.env["ir.model.fields"] + for index, path in enumerate(fields): + if len(path) == 1: + field_name = path[0] + if self._fields.get(field_name): + model_name = self._fields.get(field_name).model_name + field = field_model.search( + [ + ("model", "=", model_name), + ("name", "=", field_name), + ] + ) + if field.anonymize_in_export: + self._export_anonymize(rows, index) + return rows diff --git a/base_export_anonymize/models/ir_model_fields.py b/base_export_anonymize/models/ir_model_fields.py new file mode 100644 index 0000000..4529f44 --- /dev/null +++ b/base_export_anonymize/models/ir_model_fields.py @@ -0,0 +1,23 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class IrModelFields(models.Model): + + _inherit = "ir.model.fields" + + anonymize_in_export = fields.Boolean( + string="Anonymize In Export", + compute="_compute_anonymize_in_export", + inverse="_inverse_anonymize_in_export", + ) + + @api.multi + def _compute_anonymize_in_export(self): + fields_anonymize_model = self.env["ir.model.fields.export.anonymize"] + for rec in self: + rec.anonymize_in_export = False + if fields_anonymize_model.search([("field_id", "=", rec.id)]): + rec.anonymize_in_export = True diff --git a/base_export_anonymize/models/ir_model_fields_export_anonymize.py b/base_export_anonymize/models/ir_model_fields_export_anonymize.py new file mode 100644 index 0000000..298b81b --- /dev/null +++ b/base_export_anonymize/models/ir_model_fields_export_anonymize.py @@ -0,0 +1,14 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrModelFieldsExportAnonymize(models.Model): + + _name = "ir.model.fields.export.anonymize" + _description = "Ir Model Fields Export Anonymize" + + field_id = fields.Many2one( + comodel_name="ir.model.fields", string="Field", required=True, index=True + ) diff --git a/base_export_anonymize/readme/CONTRIBUTORS.rst b/base_export_anonymize/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..35c03ff --- /dev/null +++ b/base_export_anonymize/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Bejaoui Souheil diff --git a/base_export_anonymize/readme/DESCRIPTION.rst b/base_export_anonymize/readme/DESCRIPTION.rst new file mode 100644 index 0000000..e7ed8a5 --- /dev/null +++ b/base_export_anonymize/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Anonymize certain fields for a group of users when exporting them +directly or via relational fields. diff --git a/base_export_anonymize/readme/USAGE.rst b/base_export_anonymize/readme/USAGE.rst new file mode 100644 index 0000000..8153bd0 --- /dev/null +++ b/base_export_anonymize/readme/USAGE.rst @@ -0,0 +1,7 @@ +* Go to "Settings/Technical/Database Structure/Fields Export Anonymize" +* Add the filed to anonymize +* Add users to "Technical Settings / Anonymize data in export" group +* You can customize the displayed string when anonymizing from the system parameters. + +With a user of "Technical Settings / Anonymize data in export" group, export the +anonymized field. \ No newline at end of file diff --git a/base_export_anonymize/security/groups.xml b/base_export_anonymize/security/groups.xml new file mode 100644 index 0000000..2a9f591 --- /dev/null +++ b/base_export_anonymize/security/groups.xml @@ -0,0 +1,10 @@ + + + + + + Anonymize data in export + + + diff --git a/base_export_anonymize/security/ir_model_fields_export_anonymize.xml b/base_export_anonymize/security/ir_model_fields_export_anonymize.xml new file mode 100644 index 0000000..9b06077 --- /dev/null +++ b/base_export_anonymize/security/ir_model_fields_export_anonymize.xml @@ -0,0 +1,27 @@ + + + + + + + ir.model.fields.export.anonymize access all + + + + + + + + + + ir.model.fields.export.anonymize access group_erp_manager + + + + + + + + + diff --git a/base_export_anonymize/static/description/index.html b/base_export_anonymize/static/description/index.html new file mode 100644 index 0000000..7263c1e --- /dev/null +++ b/base_export_anonymize/static/description/index.html @@ -0,0 +1,432 @@ + + + + + + +Base Export Anonymize + + + +
+

Base Export Anonymize

+ + +

Beta License: AGPL-3 OCA/data-protection Translate me on Weblate Try me on Runbot

+

Anonymize certain fields for a group of users when exporting them +directly or via relational fields.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to “Settings/Technical/Database Structure/Fields Export Anonymize”
  • +
  • Add the filed to anonymize
  • +
  • Add users to “Technical Settings / Anonymize data in export” group
  • +
  • You can customize the displayed string when anonymizing from the system parameters.
  • +
+

With a user of “Technical Settings / Anonymize data in export” group, export the +anonymized field.

+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/data-protection project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_export_anonymize/views/ir_model_fields.xml b/base_export_anonymize/views/ir_model_fields.xml new file mode 100644 index 0000000..cf23839 --- /dev/null +++ b/base_export_anonymize/views/ir_model_fields.xml @@ -0,0 +1,17 @@ + + + + + + + ir.model.fields + + + + + + + + + diff --git a/base_export_anonymize/views/ir_model_fields_export_anonymize.xml b/base_export_anonymize/views/ir_model_fields_export_anonymize.xml new file mode 100644 index 0000000..7b9e862 --- /dev/null +++ b/base_export_anonymize/views/ir_model_fields_export_anonymize.xml @@ -0,0 +1,31 @@ + + + + + + + ir.model.fields.export.anonymize + + + + + + + + + Fields Export Anonymize + ir.model.fields.export.anonymize + tree + [] + {} + + + + Fields Export Anonymize + + + + + +