diff --git a/base_model_restrict_update/README.rst b/base_model_restrict_update/README.rst new file mode 100644 index 00000000000..a6710d01160 --- /dev/null +++ b/base_model_restrict_update/README.rst @@ -0,0 +1,98 @@ +===================== +Update Restrict Model +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bbcc1b9486884cea6b487847ab39a959539b77ae21276a8362033ed9280e90d8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/16.0/base_model_restrict_update + :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-16-0/server-tools-16-0-base_model_restrict_update + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a config to apply a global update restriction to specific model, +while only certain users can update the records if the config is enabled. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Enable the "Update Restrict Model" of specific model to restrict update from unpermitted users. +To set a user as a permitted user to update restricted model(s), click on "Unrestrict +Update" toggle button in the user form. + +Optionally, to set a user as read-only user to all models, click on "Read-only" toggle +button in the user form. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile Limited + +Contributors +~~~~~~~~~~~~ + +* Quartile Limited + + * Yoshi Tashiro + +* Ecosoft + + * Kitti U. + +Other credits +~~~~~~~~~~~~~ + +* This module borrows the idea from 'Moises Lopez ' + +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/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_model_restrict_update/__init__.py b/base_model_restrict_update/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/base_model_restrict_update/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_model_restrict_update/__manifest__.py b/base_model_restrict_update/__manifest__.py new file mode 100644 index 00000000000..c2ea27d7874 --- /dev/null +++ b/base_model_restrict_update/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2021 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": "Update Restrict Model", + "version": "16.0.1.0.0", + "depends": ["base"], + "website": "https://github.com/OCA/server-tools", + "author": "Odoo Community Association (OCA), Quartile Limited", + "category": "Others", + "license": "LGPL-3", + "data": ["views/ir_model_views.xml", "views/res_users_views.xml"], + "installable": True, +} diff --git a/base_model_restrict_update/i18n/base_model_restrict_update.po b/base_model_restrict_update/i18n/base_model_restrict_update.po new file mode 100644 index 00000000000..d7c1fc2a74a --- /dev/null +++ b/base_model_restrict_update/i18n/base_model_restrict_update.po @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_model_restrict_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Read-only" +msgstr "" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Unrestrict Update" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model_access +msgid "Model Access" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model +msgid "Models" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Ready User" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Set to true and the user are readonly user on all models" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Set to true and the user can update restricted model." +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Unrestrict Model Update" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__restrict_update +msgid "Update Restrict Model" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_res_users +msgid "Users" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_ir_model__restrict_update +msgid "" +"When selected, the model is restricted to read-only unless the user has the " +"special permission." +msgstr "" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/ir_model_access.py:0 +#, python-format +msgid "You are only allowed to read this record. (%(model)s - %(mode)s)" +msgstr "" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/res_users.py:0 +#, python-format +msgid "You cannot set admin user as a readonly user." +msgstr "" diff --git a/base_model_restrict_update/i18n/base_model_restrict_update.pot b/base_model_restrict_update/i18n/base_model_restrict_update.pot new file mode 100644 index 00000000000..2ab2873d370 --- /dev/null +++ b/base_model_restrict_update/i18n/base_model_restrict_update.pot @@ -0,0 +1,83 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_model_restrict_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \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_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Read-only" +msgstr "" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Unrestrict Update" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model_access +msgid "Model Access" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model +msgid "Models" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Ready User" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Set to true and the user are readonly user on all models" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Set to true and the user can update restricted model." +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Unrestrict Model Update" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__restrict_update +msgid "Update Restrict Model" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_res_users +msgid "Users" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_ir_model__restrict_update +msgid "" +"When selected, the model is restricted to read-only unless the user has the " +"special permission." +msgstr "" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/ir_model_access.py:0 +#, python-format +msgid "You are only allowed to read this record. (%(model)s - %(mode)s)" +msgstr "" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/res_users.py:0 +#, python-format +msgid "You cannot set admin user as a readonly user." +msgstr "" diff --git a/base_model_restrict_update/i18n/es.po b/base_model_restrict_update/i18n/es.po new file mode 100644 index 00000000000..49d151caa86 --- /dev/null +++ b/base_model_restrict_update/i18n/es.po @@ -0,0 +1,95 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_model_restrict_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-09 19:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Read-only" +msgstr "Solo-Lectura" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Unrestrict Update" +msgstr "" +"Actualización sin restricciones" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model_access +msgid "Model Access" +msgstr "Acceso Modelo" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model +msgid "Models" +msgstr "Modelos" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Ready User" +msgstr "Usuario listo" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Set to true and the user are readonly user on all models" +msgstr "" +"Establecer a true y el usuario son de sólo lectura en todos los modelos" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Set to true and the user can update restricted model." +msgstr "" +"Si se establece en true, el usuario puede actualizar el modelo restringido." + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Unrestrict Model Update" +msgstr "Actualización del modelo Sin restricciones" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__restrict_update +msgid "Update Restrict Model" +msgstr "Actualizar el modelo de restricciones" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_res_users +msgid "Users" +msgstr "Usuarios" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_ir_model__restrict_update +msgid "" +"When selected, the model is restricted to read-only unless the user has the " +"special permission." +msgstr "" +"Cuando se selecciona, el modelo se restringe a sólo lectura a menos que el " +"usuario tenga el permiso especial." + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/ir_model_access.py:0 +#, python-format +msgid "You are only allowed to read this record. (%(model)s - %(mode)s)" +msgstr "Sólo puede leer este registro. (%(model)s - %(mode)s)" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/res_users.py:0 +#, python-format +msgid "You cannot set admin user as a readonly user." +msgstr "No se puede establecer el usuario admin como usuario de sólo lectura." + +#, python-format +#~ msgid "You are only allowed to read this record. ({} - {})" +#~ msgstr "Sólo puede leer este registro. ({} - {})" diff --git a/base_model_restrict_update/i18n/es_AR.po b/base_model_restrict_update/i18n/es_AR.po new file mode 100644 index 00000000000..e18407abf22 --- /dev/null +++ b/base_model_restrict_update/i18n/es_AR.po @@ -0,0 +1,110 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_model_restrict_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-29 23:45+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Read-only" +msgstr "Solo lectura" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Unrestrict Update" +msgstr "Actualización Irrestricta" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model_access +msgid "Model Access" +msgstr "Modelo de Acceso" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model +msgid "Models" +msgstr "Modelos" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Ready User" +msgstr "Usuario Listo" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Set to true and the user are readonly user on all models" +msgstr "" +"Establezcalo como verdadero y el usuario es un usuario de solo lectura en " +"todos los modelos" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Set to true and the user can update restricted model." +msgstr "" +"Establezcalo como verdadero y bel usuario podrá actualizar el modelo " +"restringido." + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Unrestrict Model Update" +msgstr "Actualización del Modelo sin Restricciones" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__restrict_update +msgid "Update Restrict Model" +msgstr "Actualizar Modelo Restricto" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_res_users +msgid "Users" +msgstr "Usuarios" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_ir_model__restrict_update +msgid "" +"When selected, the model is restricted to read-only unless the user has the " +"special permission." +msgstr "" +"Cuando está seleccionado, el modelo está restringido a solo lectura a menos " +"que el usuario tenga permisos especiales." + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/ir_model_access.py:0 +#, python-format +msgid "You are only allowed to read this record. (%(model)s - %(mode)s)" +msgstr "Está permitido solo a leer este registro. (%(model)s - %(mode)s)" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/res_users.py:0 +#, python-format +msgid "You cannot set admin user as a readonly user." +msgstr "" +"No puede configurar al usuario administrador como un usuario de sólo lectura." + +#, python-format +#~ msgid "You are only allowed to read this record. ({} - {})" +#~ msgstr "Solo le está permitido leer este registro. ({} - {})" + +#~ msgid "Display Name" +#~ msgstr "Mostrar Nombre" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última modificación en" + +#, python-format +#~ msgid "You are only allowed to read this record. (%s - %s)" +#~ msgstr "No está permitido para leer este registro. (%s - %s)" diff --git a/base_model_restrict_update/i18n/ja_JP.po b/base_model_restrict_update/i18n/ja_JP.po new file mode 100644 index 00000000000..8b94c45b4b9 --- /dev/null +++ b/base_model_restrict_update/i18n/ja_JP.po @@ -0,0 +1,92 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_model_restrict_update +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-02-04 09:47+0000\n" +"PO-Revision-Date: 2021-02-04 09:47+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Read-only" +msgstr "" + +#. module: base_model_restrict_update +#: model_terms:ir.ui.view,arch_db:base_model_restrict_update.view_users_form +msgid "Unrestrict Update" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model_access +msgid "Model Access" +msgstr "モデルアクセス" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_ir_model +msgid "Models" +msgstr "モデル" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Ready User" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__is_readonly_user +msgid "Set to true and the user are readonly user on all models" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Set to true and the user can update restricted model." +msgstr "有効化にすると制限されたモデルを更新することができます。" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__unrestrict_model_update +msgid "Unrestrict Model Update" +msgstr "制限モデル更新許可" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__restrict_update +msgid "Update Restrict Model" +msgstr "更新制限モデル" + +#. module: base_model_restrict_update +#: model:ir.model,name:base_model_restrict_update.model_res_users +msgid "Users" +msgstr "ユーザ" + +#. module: base_model_restrict_update +#: model:ir.model.fields,help:base_model_restrict_update.field_ir_model__restrict_update +msgid "" +"When selected, the model is restricted to read-only unless the user has the " +"special permission." +msgstr "" +"有効化にすると、「制限モデル更新許可」を持ちユーザのみモデルレコードを更新で" +"きます。" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/ir_model_access.py:0 +#, python-format +msgid "You are only allowed to read this record. (%(model)s - %(mode)s)" +msgstr "" + +#. module: base_model_restrict_update +#: code:addons/base_model_restrict_update/models/res_users.py:0 +#, python-format +msgid "You cannot set admin user as a readonly user." +msgstr "" + +#, python-format +#~ msgid "You are only allowed to read this record. (%s - %s)" +#~ msgstr "レコードを更新することはできません。(%s - %s)" diff --git a/base_model_restrict_update/models/__init__.py b/base_model_restrict_update/models/__init__.py new file mode 100644 index 00000000000..4f02d73ba29 --- /dev/null +++ b/base_model_restrict_update/models/__init__.py @@ -0,0 +1,3 @@ +from . import ir_model_access +from . import ir_model +from . import res_users diff --git a/base_model_restrict_update/models/ir_model.py b/base_model_restrict_update/models/ir_model.py new file mode 100644 index 00000000000..a60b6b8759d --- /dev/null +++ b/base_model_restrict_update/models/ir_model.py @@ -0,0 +1,14 @@ +# Copyright 2021 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class IrModel(models.Model): + _inherit = "ir.model" + + restrict_update = fields.Boolean( + "Update Restrict Model", + help="When selected, the model is restricted to read-only unless the " + "user has the special permission.", + ) diff --git a/base_model_restrict_update/models/ir_model_access.py b/base_model_restrict_update/models/ir_model_access.py new file mode 100644 index 00000000000..5e46a3d3ea9 --- /dev/null +++ b/base_model_restrict_update/models/ir_model_access.py @@ -0,0 +1,60 @@ +# Copyright 2021 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import api, models +from odoo.exceptions import AccessError +from odoo.tools.translate import _ + + +class IrModelAccess(models.Model): + _inherit = "ir.model.access" + + @api.model + def _readonly_exclude_models(self): + """Models updtate/create by system, and should be excluded from checking""" + return ( + self.sudo() + .search( + [ + ("group_id", "=", False), + "|", + ("perm_write", "=", True), + "|", + ("perm_create", "=", True), + ("perm_unlink", "=", True), + ] + ) + .mapped("model_id.model") + ) + + @api.model + def _test_readonly(self, model): + exclude_models = self._readonly_exclude_models() + if model not in exclude_models and self.env.user.is_readonly_user: + return True + return False + + @api.model + def _test_restrict_update(self, model): + self.env.cr.execute( + "SELECT restrict_update FROM ir_model WHERE model = %s", (model,) + ) + query_res = self.env.cr.dictfetchone() + if query_res["restrict_update"] and not self.env.user.unrestrict_model_update: + return True + return False + + @api.model + def check(self, model, mode="read", raise_exception=True): + if self.env.su: + return True + res = super().check(model, mode, raise_exception) + if mode != "read" and raise_exception: + if self._test_readonly(model) or self._test_restrict_update(model): + raise AccessError( + _( + "You are only allowed to read this record. (%(model)s - %(mode)s)" + ) + % {"model": model, "mode": mode} + ) + return res diff --git a/base_model_restrict_update/models/res_users.py b/base_model_restrict_update/models/res_users.py new file mode 100644 index 00000000000..ebf122fa9db --- /dev/null +++ b/base_model_restrict_update/models/res_users.py @@ -0,0 +1,23 @@ +# Copyright 2021 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class ResUsers(models.Model): + _inherit = "res.users" + + unrestrict_model_update = fields.Boolean( + help="Set to true and the user can update restricted model.", + ) + is_readonly_user = fields.Boolean( + "Ready User", + help="Set to true and the user are readonly user on all models", + ) + + @api.constrains("is_readonly_user") + def _check_is_readonly_user(self): + for user in self: + if self.env.ref("base.group_system") in user.groups_id: + raise UserError(_("You cannot set admin user as a readonly user.")) diff --git a/base_model_restrict_update/readme/CONFIGURE.rst b/base_model_restrict_update/readme/CONFIGURE.rst new file mode 100644 index 00000000000..8594c5f79a6 --- /dev/null +++ b/base_model_restrict_update/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +Enable the "Update Restrict Model" of specific model to restrict update from unpermitted users. +To set a user as a permitted user to update restricted model(s), click on "Unrestrict +Update" toggle button in the user form. + +Optionally, to set a user as read-only user to all models, click on "Read-only" toggle +button in the user form. diff --git a/base_model_restrict_update/readme/CONTRIBUTORS.rst b/base_model_restrict_update/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..6a2d7b3a99c --- /dev/null +++ b/base_model_restrict_update/readme/CONTRIBUTORS.rst @@ -0,0 +1,7 @@ +* Quartile Limited + + * Yoshi Tashiro + +* Ecosoft + + * Kitti U. diff --git a/base_model_restrict_update/readme/CREDITS.rst b/base_model_restrict_update/readme/CREDITS.rst new file mode 100644 index 00000000000..ac1be061efa --- /dev/null +++ b/base_model_restrict_update/readme/CREDITS.rst @@ -0,0 +1 @@ +* This module borrows the idea from 'Moises Lopez ' diff --git a/base_model_restrict_update/readme/DESCRIPTION.rst b/base_model_restrict_update/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..0a8c8c551c1 --- /dev/null +++ b/base_model_restrict_update/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adds a config to apply a global update restriction to specific model, +while only certain users can update the records if the config is enabled. diff --git a/base_model_restrict_update/static/description/icon.png b/base_model_restrict_update/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/base_model_restrict_update/static/description/icon.png differ diff --git a/base_model_restrict_update/static/description/index.html b/base_model_restrict_update/static/description/index.html new file mode 100644 index 00000000000..5a4201752fe --- /dev/null +++ b/base_model_restrict_update/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +Update Restrict Model + + + +
+

Update Restrict Model

+ + +

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

This module adds a config to apply a global update restriction to specific model, +while only certain users can update the records if the config is enabled.

+

Table of contents

+ +
+

Configuration

+

Enable the “Update Restrict Model” of specific model to restrict update from unpermitted users. +To set a user as a permitted user to update restricted model(s), click on “Unrestrict +Update” toggle button in the user form.

+

Optionally, to set a user as read-only user to all models, click on “Read-only” toggle +button in the user form.

+
+
+

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

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile Limited
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+ +
+
+

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/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_model_restrict_update/tests/__init__.py b/base_model_restrict_update/tests/__init__.py new file mode 100644 index 00000000000..6b23d93c704 --- /dev/null +++ b/base_model_restrict_update/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_model_restrict_update diff --git a/base_model_restrict_update/tests/test_base_model_restrict_update.py b/base_model_restrict_update/tests/test_base_model_restrict_update.py new file mode 100644 index 00000000000..9927dff90c3 --- /dev/null +++ b/base_model_restrict_update/tests/test_base_model_restrict_update.py @@ -0,0 +1,63 @@ +# Copyright 2021 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.exceptions import AccessError +from odoo.tests import common, tagged + + +@tagged("post_install", "-at_install") +class TestBaseModelRestrictUpdate(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner_model = cls.env["ir.model"].search([("model", "=", "res.partner")])[ + 0 + ] + cls.partner_model.restrict_update = True + cls.test_partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.restrict_test_user = cls.env["res.users"].create( + { + "name": "Resticted user", + "login": "resticted@example.com", + "unrestrict_model_update": False, + } + ) + cls.permit_test_user = cls.env["res.users"].create( + { + "name": "Permit user", + "login": "permit@example.com", + "email": "permit@example.com", + "unrestrict_model_update": True, + } + ) + + def test_01_create_partner(self): + with self.assertRaises(AccessError): + self.env["res.partner"].with_user(self.restrict_test_user.id).create( + {"name": "Test Partner"} + ) + self.env["res.partner"].with_user(self.permit_test_user.id).create( + {"name": "Test Partner"} + ) + + def test_02_update_partner(self): + with self.assertRaises(AccessError): + self.test_partner.with_user(self.restrict_test_user.id).update( + {"name": "Test Partner 2"} + ) + self.test_partner.with_user(self.permit_test_user.id).update( + {"name": "Test Partner 2"} + ) + + def test_03_unlink_partner(self): + test_partner = self.test_partner.sudo().copy() + with self.assertRaises(AccessError): + test_partner.with_user(self.restrict_test_user.id).unlink() + test_partner.with_user(self.permit_test_user.id).unlink() + + def test_04_readonly_user_update_partner(self): + self.permit_test_user.write({"is_readonly_user": True}) + with self.assertRaises(AccessError): + self.test_partner.with_user(self.permit_test_user.id).update( + {"name": "Test Partner 2"} + ) diff --git a/base_model_restrict_update/views/ir_model_views.xml b/base_model_restrict_update/views/ir_model_views.xml new file mode 100644 index 00000000000..e4b754e6dd3 --- /dev/null +++ b/base_model_restrict_update/views/ir_model_views.xml @@ -0,0 +1,13 @@ + + + + ir.model form + ir.model + + + + + + + + diff --git a/base_model_restrict_update/views/res_users_views.xml b/base_model_restrict_update/views/res_users_views.xml new file mode 100644 index 00000000000..819c64a8d26 --- /dev/null +++ b/base_model_restrict_update/views/res_users_views.xml @@ -0,0 +1,29 @@ + + + + res.users.form + res.users + + +
+
+ Unrestrict Update + +
+
+ Read-only + +
+
+
+
+
diff --git a/setup/base_model_restrict_update/odoo/addons/base_model_restrict_update b/setup/base_model_restrict_update/odoo/addons/base_model_restrict_update new file mode 120000 index 00000000000..5feb2772198 --- /dev/null +++ b/setup/base_model_restrict_update/odoo/addons/base_model_restrict_update @@ -0,0 +1 @@ +../../../../base_model_restrict_update \ No newline at end of file diff --git a/setup/base_model_restrict_update/setup.py b/setup/base_model_restrict_update/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/base_model_restrict_update/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)