diff --git a/base_model_restrict_update/README.rst b/base_model_restrict_update/README.rst new file mode 100644 index 000000000..3bec3b05b --- /dev/null +++ b/base_model_restrict_update/README.rst @@ -0,0 +1,92 @@ +===================== +Update Restrict Model +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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/14.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-14-0/server-tools-14-0-base_model_restrict_update + :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/14.0 + :alt: Try me on Runbot + +|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 "Grant Update Permit" in user form. +Optionally, to set a user as readonly user to all models, click on "Readonly User" in 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 smashing 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 000000000..0650744f6 --- /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 000000000..e7cb33e6a --- /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": "15.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 000000000..f7ba20e35 --- /dev/null +++ b/base_model_restrict_update/i18n/base_model_restrict_update.po @@ -0,0 +1,58 @@ +# 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: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,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:31 +#, python-format +msgid "You are only allowed to read this record. (%s - %s)" +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 000000000..a4936a255 --- /dev/null +++ b/base_model_restrict_update/i18n/base_model_restrict_update.pot @@ -0,0 +1,94 @@ +# 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" +"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:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__display_name +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model_access__display_name +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__display_name +msgid "Display Name" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__id +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model_access__id +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__id +msgid "ID" +msgstr "" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model____last_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model_access____last_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users____last_update +msgid "Last Modified on" +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. (%s - %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_AR.po b/base_model_restrict_update/i18n/es_AR.po new file mode 100644 index 000000000..493801b2c --- /dev/null +++ b/base_model_restrict_update/i18n/es_AR.po @@ -0,0 +1,104 @@ +# 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: 2022-09-04 06:07+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.3.2\n" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__display_name +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model_access__display_name +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model__id +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model_access__id +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users__id +msgid "ID" +msgstr "ID" + +#. module: base_model_restrict_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model____last_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_ir_model_access____last_update +#: model:ir.model.fields,field_description:base_model_restrict_update.field_res_users____last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. 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. (%s - %s)" +msgstr "No está permitido para leer este registro. (%s - %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." 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 000000000..09564531b --- /dev/null +++ b/base_model_restrict_update/i18n/ja_JP.po @@ -0,0 +1,62 @@ +# 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: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,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:31 +#, 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 000000000..4f02d73ba --- /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 000000000..a60b6b875 --- /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 000000000..0742f43f8 --- /dev/null +++ b/base_model_restrict_update/models/ir_model_access.py @@ -0,0 +1,67 @@ +# Copyright 2021 Quartile Limited +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import api, models, tools +from odoo.exceptions import AccessError +from odoo.tools.translate import _ + + +class IrModelAccess(models.Model): + _inherit = "ir.model.access" + + @api.model + @tools.ormcache_context( + "self.env.uid", + "self.env.su", + "model", + "mode", + "raise_exception", + keys=("lang",), + ) + 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. ({} - {})").format( + model, mode + ) + ) + return res + + @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 _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") + ) 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 000000000..ebf122fa9 --- /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 000000000..8594c5f79 --- /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 000000000..6a2d7b3a9 --- /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 000000000..ac1be061e --- /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 000000000..0a8c8c551 --- /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 000000000..3a0328b51 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 000000000..8854975ba --- /dev/null +++ b/base_model_restrict_update/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Update Restrict Model + + + +
+

Update Restrict Model

+ + +

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

+

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 “Grant Update Permit” in user form. +Optionally, to set a user as readonly user to all models, click on “Readonly User” in 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 smashing 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 000000000..6b23d93c7 --- /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 000000000..b17bca480 --- /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 SavepointCase, tagged + + +@tagged("post_install", "-at_install") +class TestBaseModelRestrictUpdate(SavepointCase): + @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 000000000..0573ca08c --- /dev/null +++ b/base_model_restrict_update/views/ir_model_views.xml @@ -0,0 +1,15 @@ + + + + + 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 000000000..30fe4b1f3 --- /dev/null +++ b/base_model_restrict_update/views/res_users_views.xml @@ -0,0 +1,31 @@ + + + + + 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 000000000..5feb27721 --- /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 000000000..28c57bb64 --- /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, +)