From 669e123a771440a2589e0c18b6107639665c2df0 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Mon, 30 Sep 2019 12:02:31 +0200 Subject: [PATCH] [9.0][ADD] - base_user_role_history --- base_user_role_history/README.rst | 97 ++++ base_user_role_history/__init__.py | 1 + base_user_role_history/__openerp__.py | 33 ++ .../i18n/base_user_role_history.pot | 169 +++++++ base_user_role_history/i18n/fr.po | 170 +++++++ base_user_role_history/i18n/fr_BE.po | 170 +++++++ base_user_role_history/models/__init__.py | 2 + .../models/base_user_role_line_history.py | 145 ++++++ base_user_role_history/models/res_users.py | 75 +++ .../readme/CONTRIBUTORS.rst | 2 + base_user_role_history/readme/DESCRIPTION.rst | 4 + base_user_role_history/readme/ROADMAP.rst | 3 + base_user_role_history/readme/USAGE.rst | 1 + .../security/base_user_role_line_history.xml | 17 + .../static/description/index.html | 437 ++++++++++++++++++ base_user_role_history/tests/__init__.py | 1 + .../tests/test_base_user_role_history.py | 160 +++++++ .../views/base_user_role_line_history.xml | 90 ++++ base_user_role_history/views/res_users.xml | 29 ++ .../odoo_addons/__init__.py | 1 + .../odoo_addons/base_user_role_history | 1 + setup/base_user_role_history/setup.py | 6 + 22 files changed, 1614 insertions(+) create mode 100644 base_user_role_history/README.rst create mode 100644 base_user_role_history/__init__.py create mode 100644 base_user_role_history/__openerp__.py create mode 100644 base_user_role_history/i18n/base_user_role_history.pot create mode 100644 base_user_role_history/i18n/fr.po create mode 100644 base_user_role_history/i18n/fr_BE.po create mode 100644 base_user_role_history/models/__init__.py create mode 100644 base_user_role_history/models/base_user_role_line_history.py create mode 100644 base_user_role_history/models/res_users.py create mode 100644 base_user_role_history/readme/CONTRIBUTORS.rst create mode 100644 base_user_role_history/readme/DESCRIPTION.rst create mode 100644 base_user_role_history/readme/ROADMAP.rst create mode 100644 base_user_role_history/readme/USAGE.rst create mode 100644 base_user_role_history/security/base_user_role_line_history.xml create mode 100644 base_user_role_history/static/description/index.html create mode 100644 base_user_role_history/tests/__init__.py create mode 100644 base_user_role_history/tests/test_base_user_role_history.py create mode 100644 base_user_role_history/views/base_user_role_line_history.xml create mode 100644 base_user_role_history/views/res_users.xml create mode 100644 setup/base_user_role_history/odoo_addons/__init__.py create mode 120000 setup/base_user_role_history/odoo_addons/base_user_role_history create mode 100644 setup/base_user_role_history/setup.py diff --git a/base_user_role_history/README.rst b/base_user_role_history/README.rst new file mode 100644 index 00000000000..369df50bdae --- /dev/null +++ b/base_user_role_history/README.rst @@ -0,0 +1,97 @@ +====================== +Base User Role History +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/9.0/base_user_role_history + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-9-0/server-tools-9-0-base_user_role_history + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/149/9.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon provides history for roles modifications on users. +Each time a role is added/updated/unlinked on a user, a new role history line +is created mentioning what changes were made and who made them. +Theses informations are directly accessible from users via a smart button. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Changes on user roles are easily accessible via a button on user form view. + +Known issues / Roadmap +====================== + +Since roles on role history line have 'cascade' ondelete, role deletion leads +to role history line deletion. In order to keep history even in the case of +a role deletion, module could be upgraded. + +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 +~~~~~~~~~~~~ + +* Benoit Aimont (https://acsone.eu) +* Thomas Binsfeld (https://acsone.eu) + +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. + +.. |maintainer-ThomasBinsfeld| image:: https://github.com/ThomasBinsfeld.png?size=40px + :target: https://github.com/ThomasBinsfeld + :alt: ThomasBinsfeld + +Current `maintainer `__: + +|maintainer-ThomasBinsfeld| + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_user_role_history/__init__.py b/base_user_role_history/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/base_user_role_history/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_user_role_history/__openerp__.py b/base_user_role_history/__openerp__.py new file mode 100644 index 00000000000..15536a5a596 --- /dev/null +++ b/base_user_role_history/__openerp__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Base User Role History', + 'summary': """ + This module allows to track the changes on users roles.""", + 'version': '9.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV, ' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/server-tools', + 'depends': [ + # Odoo + 'base', + 'mail', + # OCA + 'base_user_role', + 'base_suspend_security', + ], + 'data': [ + 'security/base_user_role_line_history.xml', + 'views/base_user_role_line_history.xml', + 'views/res_users.xml', + ], + 'demo': [ + ], + 'development_status': 'Beta', + 'maintainers': [ + 'ThomasBinsfeld' + ], +} diff --git a/base_user_role_history/i18n/base_user_role_history.pot b/base_user_role_history/i18n/base_user_role_history.pot new file mode 100644 index 00000000000..dbf1e4c950e --- /dev/null +++ b/base_user_role_history/i18n/base_user_role_history.pot @@ -0,0 +1,169 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_user_role_history +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-09-30 11:50+0000\n" +"PO-Revision-Date: 2019-09-30 11:50+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.res_users_form_view +msgid "Last update of roles" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_performed_action +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Action" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_is_enabled +msgid "Active after edit" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_is_enabled +msgid "Active before edit" +msgstr "" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Add" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_create_uid +msgid "Created by" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_create_date +msgid "Created on" +msgstr "" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_tree_view +msgid "Date and time of edition" +msgstr "" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Delete" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_display_name +msgid "Display Name" +msgstr "" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Edit" +msgstr "" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +msgid "Edited user" +msgstr "" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_tree_view +msgid "Editor" +msgstr "" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Group By" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model,name:base_user_role_history.model_base_user_role_line_history +msgid "History of user roles" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_id +msgid "ID" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history___last_update +msgid "Last Modified on" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_write_uid +msgid "Last Updated by" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_write_date +msgid "Last Updated on" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_res_users_last_role_line_modification +msgid "Last roles modification" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_date_to +msgid "New end date" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_role_id +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "New role" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_date_from +msgid "New start date" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_date_to +msgid "Old end date" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_role_id +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Old role" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_date_from +msgid "Old start date" +msgstr "" + +#. module: base_user_role_history +#: code:addons/base_user_role_history/models/res_users.py:70 +#: model:ir.ui.view,arch_db:base_user_role_history.res_users_form_view +#, python-format +msgid "Roles history" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_user_id +msgid "User" +msgstr "" + +#. module: base_user_role_history +#: model:ir.model,name:base_user_role_history.model_res_users +msgid "Users" +msgstr "" + diff --git a/base_user_role_history/i18n/fr.po b/base_user_role_history/i18n/fr.po new file mode 100644 index 00000000000..39fbe849cff --- /dev/null +++ b/base_user_role_history/i18n/fr.po @@ -0,0 +1,170 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_user_role_history +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-09-30 11:51+0000\n" +"PO-Revision-Date: 2019-09-30 11:51+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.res_users_form_view +msgid "Last update of roles" +msgstr "Dernière modification des rôles" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_performed_action +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Action" +msgstr "Action" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_is_enabled +msgid "Active after edit" +msgstr "Actif après édition" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_is_enabled +msgid "Active before edit" +msgstr "Actif avant édition" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Add" +msgstr "Ajouter" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_create_uid +msgid "Created by" +msgstr "Créé par" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_create_date +msgid "Created on" +msgstr "Créé le" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_tree_view +msgid "Date and time of edition" +msgstr "Date et heure de modification" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Delete" +msgstr "Supprimer" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Edit" +msgstr "Modifier" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +msgid "Edited user" +msgstr "Utilisateur modifié" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_tree_view +msgid "Editor" +msgstr "Utilisateur modificateur" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Group By" +msgstr "Regrouper par" + +#. module: base_user_role_history +#: model:ir.model,name:base_user_role_history.model_base_user_role_line_history +msgid "History of user roles" +msgstr "Historique des rôles de l'utilisateur" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_id +msgid "ID" +msgstr "ID" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history___last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_write_uid +msgid "Last Updated by" +msgstr "Mis à jour par" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_write_date +msgid "Last Updated on" +msgstr "Mis à jour le" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_res_users_last_role_line_modification +msgid "Last roles modification" +msgstr "Dernière modification des rôles" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_date_to +msgid "New end date" +msgstr "Nouvelle date de fin" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_role_id +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "New role" +msgstr "Nouveau rôle" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_date_from +msgid "New start date" +msgstr "Nouvelle date de début" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_date_to +msgid "Old end date" +msgstr "Ancienne date de fin" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_role_id +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Old role" +msgstr "Ancien rôle" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_date_from +msgid "Old start date" +msgstr "Ancienne date de début" + +#. module: base_user_role_history +#: code:addons/base_user_role_history/models/res_users.py:70 +#: model:ir.ui.view,arch_db:base_user_role_history.res_users_form_view +#, python-format +msgid "Roles history" +msgstr "Historique des rôles" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_user_id +msgid "User" +msgstr "Utilisateur" + +#. module: base_user_role_history +#: model:ir.model,name:base_user_role_history.model_res_users +msgid "Users" +msgstr "Utilisateurs" + diff --git a/base_user_role_history/i18n/fr_BE.po b/base_user_role_history/i18n/fr_BE.po new file mode 100644 index 00000000000..457621b4402 --- /dev/null +++ b/base_user_role_history/i18n/fr_BE.po @@ -0,0 +1,170 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_user_role_history +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-09-30 11:50+0000\n" +"PO-Revision-Date: 2019-09-30 11:50+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: fr_BE\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.res_users_form_view +msgid "Last update of roles" +msgstr "Dernière modification des rôles" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_performed_action +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Action" +msgstr "Action" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_is_enabled +msgid "Active after edit" +msgstr "Actif après édition" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_is_enabled +msgid "Active before edit" +msgstr "Actif avant édition" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Add" +msgstr "Ajouter" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_create_uid +msgid "Created by" +msgstr "Créé par" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_create_date +msgid "Created on" +msgstr "Créé le" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_tree_view +msgid "Date and time of edition" +msgstr "Date et heure de modification" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Delete" +msgstr "Supprimer" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: base_user_role_history +#: selection:base.user.role.line.history,performed_action:0 +msgid "Edit" +msgstr "Modifier" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +msgid "Edited user" +msgstr "Utilisateur modifié" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_form_view +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_tree_view +msgid "Editor" +msgstr "Utilisateur modificateur" + +#. module: base_user_role_history +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Group By" +msgstr "Regrouper par" + +#. module: base_user_role_history +#: model:ir.model,name:base_user_role_history.model_base_user_role_line_history +msgid "History of user roles" +msgstr "Historique des rôles de l'utilisateur" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_id +msgid "ID" +msgstr "ID" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history___last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_write_uid +msgid "Last Updated by" +msgstr "Derniere fois mis à jour par" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_write_date +msgid "Last Updated on" +msgstr "Dernière mis à jour le" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_res_users_last_role_line_modification +msgid "Last roles modification" +msgstr "Dernière modification des rôles" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_date_to +msgid "New end date" +msgstr "Nouvelle date de fin" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_role_id +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "New role" +msgstr "Nouveau rôle" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_new_date_from +msgid "New start date" +msgstr "Nouvelle date de début" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_date_to +msgid "Old end date" +msgstr "Ancienne date de fin" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_role_id +#: model:ir.ui.view,arch_db:base_user_role_history.base_user_role_line_history_search_view +msgid "Old role" +msgstr "Ancien rôle" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_old_date_from +msgid "Old start date" +msgstr "Ancienne date de début" + +#. module: base_user_role_history +#: code:addons/base_user_role_history/models/res_users.py:70 +#: model:ir.ui.view,arch_db:base_user_role_history.res_users_form_view +#, python-format +msgid "Roles history" +msgstr "Historique des rôles" + +#. module: base_user_role_history +#: model:ir.model.fields,field_description:base_user_role_history.field_base_user_role_line_history_user_id +msgid "User" +msgstr "Utilisateur" + +#. module: base_user_role_history +#: model:ir.model,name:base_user_role_history.model_res_users +msgid "Users" +msgstr "Utilisateurs" + diff --git a/base_user_role_history/models/__init__.py b/base_user_role_history/models/__init__.py new file mode 100644 index 00000000000..9ce69302d92 --- /dev/null +++ b/base_user_role_history/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_users +from . import base_user_role_line_history diff --git a/base_user_role_history/models/base_user_role_line_history.py b/base_user_role_history/models/base_user_role_line_history.py new file mode 100644 index 00000000000..f89c2b85942 --- /dev/null +++ b/base_user_role_history/models/base_user_role_line_history.py @@ -0,0 +1,145 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, fields, models + + +class BaseUserRoleLineHistory(models.Model): + _name = 'base.user.role.line.history' + _description = "History of user roles" + _order = 'id desc' + + performed_action = fields.Selection( + string="Action", + selection=[ + ('add', 'Add'), + ('unlink', 'Delete'), + ('edit', 'Edit') + ], + required=True, + readonly=True, + ) + user_id = fields.Many2one( + string="User", + comodel_name='res.users', + ondelete='cascade', + readonly=True, + index=True, + ) + old_role_id = fields.Many2one( + string="Old role", + comodel_name='res.users.role', + ondelete='cascade', + readonly=True, + index=True, + ) + new_role_id = fields.Many2one( + string="New role", + comodel_name='res.users.role', + ondelete='cascade', + readonly=True, + index=True, + ) + old_date_from = fields.Date( + string="Old start date", + readonly=True, + ) + new_date_from = fields.Date( + string="New start date", + readonly=True, + ) + old_date_to = fields.Date( + string="Old end date", + readonly=True, + ) + new_date_to = fields.Date( + string="New end date", + readonly=True, + ) + old_is_enabled = fields.Boolean( + string="Active before edit", + readonly=True, + ) + new_is_enabled = fields.Boolean( + string="Active after edit", + readonly=True, + ) + + @api.model + def _prepare_create_from_vals( + self, + old_role_line_values_by_user, + new_role_line_values_by_user + ): + role_history_line_vals_by_role_line = {} + for key, value in new_role_line_values_by_user.items(): + old_vals = old_role_line_values_by_user.get(key, {}) + new_vals = value + # Manage deletion of role lines and old values of modified lines + for role_line_id, role_line_vals in old_vals.items(): + action = 'unlink' if role_line_id not in new_vals else 'edit' + if action == 'edit': + # Skip if no change + if not any( + role_line_vals[k] != new_vals[role_line_id][k] + for k in role_line_vals + ): + continue + role_history_line_vals_by_role_line.setdefault( + role_line_id, {} + ) + role_history_line_vals_by_role_line[role_line_id].update({ + 'performed_action': action, + 'user_id': role_line_vals['user_id'], + 'old_role_id': role_line_vals['role_id'], + 'old_date_from': role_line_vals['date_from'], + 'old_date_to': role_line_vals['date_to'], + 'old_is_enabled': role_line_vals['is_enabled'], + }) + # Manage addition of role lines and new values of modified ones + for role_line_id, role_line_vals in new_vals.items(): + action = 'add' if role_line_id not in old_vals else 'edit' + if action == 'edit': + # Skip if no change + if not any( + role_line_vals[k] != old_vals[role_line_id][k] + for k in role_line_vals + ): + continue + role_history_line_vals_by_role_line.setdefault( + role_line_id, {} + ) + role_history_line_vals_by_role_line[role_line_id].update({ + 'performed_action': action, + 'user_id': role_line_vals['user_id'], + 'new_role_id': role_line_vals['role_id'], + 'new_date_from': role_line_vals['date_from'], + 'new_date_to': role_line_vals['date_to'], + 'new_is_enabled': role_line_vals['is_enabled'], + }) + return role_history_line_vals_by_role_line + + @api.model + def create_from_vals( + self, + old_role_line_values_by_user, + new_role_line_values_by_user + ): + """ + This method creates user role line history objects based on given + old/new values. + old_role_line_values_by_user and new_role_line_values_by_user are like: + {user_id: + {role_line_id: + {role_line_values}, + }, + } + """ + role_history_line_vals_by_role_line = self._prepare_create_from_vals( + old_role_line_values_by_user, new_role_line_values_by_user + ) + # Create the history lines with suspend security + # (nobody has the create right) + for role_history_vals in role_history_line_vals_by_role_line.values(): + self.suspend_security().create(role_history_vals) diff --git a/base_user_role_history/models/res_users.py b/base_user_role_history/models/res_users.py new file mode 100644 index 00000000000..5f4dd4ab044 --- /dev/null +++ b/base_user_role_history/models/res_users.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, fields, models, _ + + +class ResUsers(models.Model): + _inherit = 'res.users' + + last_role_line_modification = fields.Datetime( + string="Last roles modification", + readonly=True, + ) + + @api.model + def _prepare_role_line_history_dict(self, role_line): + return { + 'user_id': role_line.user_id.id, + 'role_id': role_line.role_id.id, + 'date_from': fields.Date.from_string(role_line.date_from), + 'date_to': fields.Date.from_string(role_line.date_to), + 'is_enabled': role_line.is_enabled, + } + + @api.multi + def _get_role_line_values_by_user(self): + role_line_values_by_user = {} + for rec in self: + role_line_values_by_user.setdefault(rec, {}) + for role_line in rec.role_line_ids: + role_line_values_by_user[rec][role_line.id] = \ + self._prepare_role_line_history_dict(role_line) + return role_line_values_by_user + + @api.model + def create(self, vals): + res = super(ResUsers, self).create(vals) + if 'role_line_ids' not in vals: + return res + new_role_line_values_by_user = res._get_role_line_values_by_user() + self.env['base.user.role.line.history'].create_from_vals( + {}, + new_role_line_values_by_user + ) + res.last_role_line_modification = fields.Datetime.now() + return res + + @api.multi + def write(self, vals): + if 'role_line_ids' not in vals: + return super(ResUsers, self).write(vals) + old_role_line_values_by_user = self._get_role_line_values_by_user() + res = super(ResUsers, self).write(vals) + new_role_line_values_by_user = self._get_role_line_values_by_user() + self.env['base.user.role.line.history'].create_from_vals( + old_role_line_values_by_user, + new_role_line_values_by_user + ) + self.write({ + 'last_role_line_modification': fields.Datetime.now() + }) + return res + + @api.multi + def show_role_lines_history(self): # pragma: no cover + self.ensure_one() + domain = [('user_id', '=', self.id)] + return { + 'name': _("Roles history"), + 'type': 'ir.actions.act_window', + 'view_mode': 'tree,form', + 'res_model': 'base.user.role.line.history', + 'domain': domain, + } diff --git a/base_user_role_history/readme/CONTRIBUTORS.rst b/base_user_role_history/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..ce9dedf87c2 --- /dev/null +++ b/base_user_role_history/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Benoit Aimont (https://acsone.eu) +* Thomas Binsfeld (https://acsone.eu) diff --git a/base_user_role_history/readme/DESCRIPTION.rst b/base_user_role_history/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..ddc8ccf5ca9 --- /dev/null +++ b/base_user_role_history/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This addon provides history for roles modifications on users. +Each time a role is added/updated/unlinked on a user, a new role history line +is created mentioning what changes were made and who made them. +Theses informations are directly accessible from users via a smart button. diff --git a/base_user_role_history/readme/ROADMAP.rst b/base_user_role_history/readme/ROADMAP.rst new file mode 100644 index 00000000000..620ab9330d5 --- /dev/null +++ b/base_user_role_history/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +Since roles on role history line have 'cascade' ondelete, role deletion leads +to role history line deletion. In order to keep history even in the case of +a role deletion, module could be upgraded. diff --git a/base_user_role_history/readme/USAGE.rst b/base_user_role_history/readme/USAGE.rst new file mode 100644 index 00000000000..8c22abc62ad --- /dev/null +++ b/base_user_role_history/readme/USAGE.rst @@ -0,0 +1 @@ +Changes on user roles are easily accessible via a button on user form view. diff --git a/base_user_role_history/security/base_user_role_line_history.xml b/base_user_role_history/security/base_user_role_line_history.xml new file mode 100644 index 00000000000..c99c1365fe6 --- /dev/null +++ b/base_user_role_history/security/base_user_role_line_history.xml @@ -0,0 +1,17 @@ + + + + + + + base.user.role.line.history access user + + + + + + + + + diff --git a/base_user_role_history/static/description/index.html b/base_user_role_history/static/description/index.html new file mode 100644 index 00000000000..ad88ec88807 --- /dev/null +++ b/base_user_role_history/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +Base User Role History + + + +
+

Base User Role History

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

This addon provides history for roles modifications on users. +Each time a role is added/updated/unlinked on a user, a new role history line +is created mentioning what changes were made and who made them. +Theses informations are directly accessible from users via a smart button.

+

Table of contents

+ +
+

Usage

+

Changes on user roles are easily accessible via a button on user form view.

+
+
+

Known issues / Roadmap

+

Since roles on role history line have ‘cascade’ ondelete, role deletion leads +to role history line deletion. In order to keep history even in the case of +a role deletion, module could be upgraded.

+
+
+

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
  • +
+
+ +
+

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.

+

Current maintainer:

+

ThomasBinsfeld

+

This module is part of the OCA/server-tools project on GitHub.

+

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

+
+
+
+ + diff --git a/base_user_role_history/tests/__init__.py b/base_user_role_history/tests/__init__.py new file mode 100644 index 00000000000..c9a4ca3ca47 --- /dev/null +++ b/base_user_role_history/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_user_role_history diff --git a/base_user_role_history/tests/test_base_user_role_history.py b/base_user_role_history/tests/test_base_user_role_history.py new file mode 100644 index 00000000000..29fa717eda9 --- /dev/null +++ b/base_user_role_history/tests/test_base_user_role_history.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).µ + +from datetime import date, timedelta + +from openerp import fields +from openerp.tests.common import SavepointCase + + +class TestBaseUserRoleHistory(SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestBaseUserRoleHistory, cls).setUpClass() + + # MODELS + + cls.history_line_model = cls.env['base.user.role.line.history'] + cls.role_model = cls.env['res.users.role'] + cls.user_model = cls.env['res.users'] + + # INSTANCE + + cls.user_01 = cls.user_model.search([ + ('id', '!=', cls.env.user.id) + ], limit=1) + cls.role_01 = cls.role_model.create({ + 'name': "Role test 01", + }) + + def test_write_role_lines_on_user(self): + """ + Data : + - user with no role + Test case : + 1) add a role + 2) role modification with dates + 3) role modification with no change + 4) role unlink + Expected results : + 1) new role history line created with performed_action == 'add' + 2) new role history line created with performed_action == 'edit' + 3) no new role history line created + 4) new role history line created with performed_action == 'unlink' + """ + # 1 + history_lines_0 = self.history_line_model.search([ + ('user_id', '=', self.user_01.id) + ]) + self.assertFalse(history_lines_0) + self.user_01.write({ + 'role_line_ids': [ + (0, 0, { + 'role_id': self.role_01.id + }) + ] + }) + history_lines_1 = self.history_line_model.search([ + ('user_id', '=', self.user_01.id) + ]) + self.assertTrue(history_lines_1) + self.assertEqual(len(history_lines_1), 1) + self.assertEqual(history_lines_1.performed_action, 'add') + self.assertFalse(history_lines_1.old_role_id) + self.assertEqual(history_lines_1.new_role_id, self.role_01) + # 2 + self.user_01.write({ + 'role_line_ids': [ + (1, self.user_01.role_line_ids[0].id, { + 'date_from': date.today(), + 'date_to': date.today() + timedelta(days=5), + }) + ] + }) + history_lines_2 = self.history_line_model.search([ + ('user_id', '=', self.user_01.id), + ('id', 'not in', history_lines_1.ids) + ]) + self.assertTrue(history_lines_2) + self.assertEqual(len(history_lines_2), 1) + self.assertEqual(history_lines_2.performed_action, 'edit') + self.assertEqual(history_lines_2.old_role_id, self.role_01) + self.assertEqual(history_lines_2.new_role_id, self.role_01) + self.assertFalse(history_lines_2.old_date_from) + self.assertEqual(history_lines_2.new_date_from, + fields.Date.to_string(date.today())) + self.assertFalse(history_lines_2.old_date_to) + self.assertEqual(history_lines_2.new_date_to, + fields.Date.to_string( + date.today() + timedelta(days=5))) + self.user_01.write({ + 'role_line_ids': [(1, self.user_01.role_line_ids[0].id, {})] + }) + history_lines_3 = self.history_line_model.search([ + ('user_id', '=', self.user_01.id), + ('id', 'not in', (history_lines_1 | history_lines_2).ids) + ]) + self.assertFalse(history_lines_3) + # 4 + self.user_01.write({ + 'role_line_ids': [(2, self.user_01.role_line_ids[0].id, False)], + }) + history_lines_4 = self.history_line_model.search([ + ('user_id', '=', self.user_01.id), + ('id', 'not in', (history_lines_1 | history_lines_2).ids) + ]) + self.assertTrue(history_lines_4) + self.assertEqual(len(history_lines_4), 1) + self.assertEqual(history_lines_4.performed_action, 'unlink') + self.assertEqual(history_lines_4.old_role_id, self.role_01) + self.assertFalse(history_lines_4.new_role_id) + self.assertEqual(history_lines_4.old_date_from, + fields.Date.to_string(date.today())) + self.assertFalse(history_lines_4.new_date_from) + self.assertEqual(history_lines_4.old_date_to, + fields.Date.to_string( + date.today() + timedelta(days=5))) + self.assertFalse(history_lines_4.new_date_to) + + def test_create_role_lines_on_new_user(self): + """ + Data : / + Test case : + - create a user with a role + Expected results : + - new role history line created with performed_action == 'add' + """ + new_user = self.user_model.create({ + 'login': 'new_user', + 'name': 'new_user', + 'role_line_ids': [ + (0, 0, { + 'role_id': self.role_01.id, + }) + ] + }) + history_lines = self.history_line_model.search([ + ('user_id', '=', new_user.id) + ]) + self.assertTrue(history_lines) + self.assertEqual(len(history_lines), 1) + self.assertEqual(history_lines.performed_action, 'add') + + def test_no_create_role_lines_on_new_user(self): + """ + Data : / + Test case : + - create a user without role + Expected results : + - no role history line created + """ + new_user = self.user_model.create({ + 'login': 'new_user', + 'name': 'new_user', + }) + history_lines = self.history_line_model.search([ + ('user_id', '=', new_user.id) + ]) + self.assertFalse(history_lines) diff --git a/base_user_role_history/views/base_user_role_line_history.xml b/base_user_role_history/views/base_user_role_line_history.xml new file mode 100644 index 00000000000..f61b12081b8 --- /dev/null +++ b/base_user_role_history/views/base_user_role_line_history.xml @@ -0,0 +1,90 @@ + + + + + + + + + base.user.role.line.history.form (in base_user_role_history) + base.user.role.line.history + +
+
+
+ + + + + + + + + + + + + + + + +
+
+
+
+ + + + + base.user.role.line.history.tree (in base_user_role_history) + base.user.role.line.history + + + + + + + + + + + + + + + + + + + + + base.user.role.line.history.search (in base_user_role_history) + base.user.role.line.history + + + + + + + + + + + + + +
diff --git a/base_user_role_history/views/res_users.xml b/base_user_role_history/views/res_users.xml new file mode 100644 index 00000000000..8eea0cf0756 --- /dev/null +++ b/base_user_role_history/views/res_users.xml @@ -0,0 +1,29 @@ + + + + + + + + + res.users.form (in base_user_role_history) + res.users + + +
+ +
+
+
+ +
diff --git a/setup/base_user_role_history/odoo_addons/__init__.py b/setup/base_user_role_history/odoo_addons/__init__.py new file mode 100644 index 00000000000..de40ea7ca05 --- /dev/null +++ b/setup/base_user_role_history/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/base_user_role_history/odoo_addons/base_user_role_history b/setup/base_user_role_history/odoo_addons/base_user_role_history new file mode 120000 index 00000000000..0de76960359 --- /dev/null +++ b/setup/base_user_role_history/odoo_addons/base_user_role_history @@ -0,0 +1 @@ +../../../base_user_role_history \ No newline at end of file diff --git a/setup/base_user_role_history/setup.py b/setup/base_user_role_history/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/base_user_role_history/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)