Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ addon | version | maintainers | summary
[module_auto_update](module_auto_update/) | 19.0.1.0.0 | | Automatically update Odoo modules
[module_change_auto_install](module_change_auto_install/) | 19.0.1.0.0 | <a href='https://github.com/legalsylvain'><img src='https://github.com/legalsylvain.png' width='32' height='32' style='border-radius:50%;' alt='legalsylvain'/></a> | Customize auto installables modules by configuration
[onchange_helper](onchange_helper/) | 19.0.1.0.0 | | Technical module that ease execution of onchange in Python code
[rpc_helper](rpc_helper/) | 19.0.1.0.0 | <a href='https://github.com/simahawk'><img src='https://github.com/simahawk.png' width='32' height='32' style='border-radius:50%;' alt='simahawk'/></a> | Helpers for disabling RPC calls
[sequence_python](sequence_python/) | 19.0.1.0.0 | | Calculate a sequence number from a Python expression
[session_db](session_db/) | 19.0.1.0.0 | <a href='https://github.com/sbidoul'><img src='https://github.com/sbidoul.png' width='32' height='32' style='border-radius:50%;' alt='sbidoul'/></a> | Store sessions in DB
[test_auditlog](test_auditlog/) | 19.0.1.0.0 | | Additional unit tests for Audit Log based on accounting models
Expand Down
161 changes: 161 additions & 0 deletions rpc_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===========
Disable RPC
===========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:cf14fb401696321d4416e21e70663ab2c4685f77889013cf9b648c168a2270e8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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/19.0/rpc_helper
: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-19-0/server-tools-19-0-rpc_helper
: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=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Provide helpers to authorize RPC calls.

**Table of contents**

.. contents::
:local:

Configuration
=============

Enable debug mode and go to "Technical -> Database Structure -> Models".

Open the model that you like to configure and go to the tab "RPC
config".

There you see a text field which supports JSON configuration.

The configuration is the same you can pass via decorator. The only
difference is that you have to wrap values in a dictionary like
{"disable": [...values...]}.

To disable all calls:

::

{
"disable": ["all"]
}

To disable only some methods:

::

{
"disable": ["create", "write", "another_method"]
}

NOTE: on the resulting JSON will be automatically formatted on save for
better readability.

Usage
=====

Via code
--------

Decorate an Odoo model class like this:

::

from odoo.addons.rpc_helper.decorator import disable_rpc

@disable_rpc()
class AverageModel(models.Model):
_inherit = "avg.model"

This will disable ALL calls.

To selectively disable only some methods:

::

@disable_rpc("create", "write", "any_method")
class AverageModel(models.Model):
_inherit = "avg.model"

Via ir.model configuration
--------------------------

See "Configuration" section.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/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 <https://github.com/OCA/server-tools/issues/new?body=module:%20rpc_helper%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- Simone Orsi <simone.orsi@camptocamp.com>

Trobz

- Tuan Nguyen <tuanna@trobz.com>

Other credits
-------------



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-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk|

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/rpc_helper>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions rpc_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_load_hook
17 changes: 17 additions & 0 deletions rpc_helper/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Disable RPC",
"summary": """Helpers for disabling RPC calls""",
"version": "19.0.1.0.0",
"development_status": "Beta",
"license": "LGPL-3",
"website": "https://github.com/OCA/server-tools",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"depends": ["base_sparse_field"],
"data": ["views/ir_model_views.xml"],
"post_load": "post_load_hook",
}
19 changes: 19 additions & 0 deletions rpc_helper/decorator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).


def disable_rpc(*config):
"""Decorate classes to disable RPC calls.

Possible values:

* none, block all methods
* *("$method_name1", "$method_name2"), blocks calls to specific methods
"""

def _decorator(target):
target._disable_rpc = ("all",) if len(config) == 0 else config
return target

return _decorator
22 changes: 22 additions & 0 deletions rpc_helper/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging

from odoo.service import model

from .patch import protected__execute_cr

_logger = logging.getLogger(__name__)


def patch__model_execute_cr():
"""Patch rpc model handler."""
protected__execute_cr._orig__execute_cr = model.execute_cr
model.execute_cr = protected__execute_cr
_logger.info("PATCHED odoo.service.model.execute")


def post_load_hook():
patch__model_execute_cr()
66 changes: 66 additions & 0 deletions rpc_helper/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * rpc_helper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-09-03 00:15+0000\n"
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\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: rpc_helper
#: model:ir.model.fields,help:rpc_helper.field_ir_model__rpc_config_edit
msgid ""
"Configure RPC config via JSON. Value must be a list of methods to disable "
"wrapped by a dict with key `disable`. Eg: {'disable': ['search', 'do_this']}"
"To disable all methods, use `{'disable: ['all']}`"
msgstr ""
"Configurar RPC vía JSON. El valor debe ser una lista de métodos a "
"deshabilitar envueltos por un dict con la clave `disable`. Ej: {'disable': "
"['search', 'do_this']}Para deshabilitar todos los métodos, usa `{'disable: "
"['all']}`"

#. module: rpc_helper
#: model:ir.model,name:rpc_helper.model_ir_model
msgid "Models"
msgstr "Modelos"

#. module: rpc_helper
#. odoo-python
#: code:addons/rpc_helper/patch.py:0
msgid "Object %s doesn't exist"
msgstr "El objeto %s no existe"

#. module: rpc_helper
#. odoo-python
#: code:addons/rpc_helper/patch.py:0
msgid "RPC call on %s is not allowed"
msgstr "La llamada RPC en %s no está permitida"

#. module: rpc_helper
#: model_terms:ir.ui.view,arch_db:rpc_helper.view_model_form
msgid "RPC config"
msgstr "Configuración RPC"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__rpc_config
msgid "Rpc Config"
msgstr "Configuración Rpc"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__rpc_config_edit
msgid "Rpc Config Edit"
msgstr "Editar configuración Rpc"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__smart_search
msgid "Smart Search"
msgstr "Búsqueda inteligente"
Loading
Loading