Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][BKP] rpc_helper #3130

Merged
merged 23 commits into from
Nov 27, 2024
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
139 changes: 139 additions & 0 deletions rpc_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
===========
Disable RPC
===========

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

.. |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/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-14-0/server-tools-14-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=14.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:%2014.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 <[email protected]>

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/14.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 <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Disable RPC",
"summary": """Helpers for disabling RPC calls""",
"version": "12.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 <[email protected]>
# 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 <[email protected]>
# 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()
106 changes: 106 additions & 0 deletions rpc_helper/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * rpc_helper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-04-21 22:42+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\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,field_description:rpc_helper.field_ir_model__changeset_change_ids
msgid "Changeset Changes"
msgstr "Cambios en el Conjunto de Modificaciones"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__changeset_ids
msgid "Changesets"
msgstr "Conjuntos de Cambios"

#. 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.fields,field_description:rpc_helper.field_ir_model__count_pending_changeset_changes
msgid "Count Pending Changeset Changes"
msgstr "Recuento de Cambios Pendientes"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__count_pending_changesets
msgid "Count Pending Changesets"
msgstr "Recuento de Cambios Pendientes"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__display_name
msgid "Display Name"
msgstr "Nombre para Mostrar"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__id
msgid "ID"
msgstr "ID (identificación)"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model____last_update
msgid "Last Modified on"
msgstr "Última Modificación el"

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

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

#. module: rpc_helper
#: code:addons/rpc_helper/patch.py:0
#, python-format
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"

#. module: rpc_helper
#: model:ir.model.fields,field_description:rpc_helper.field_ir_model__user_can_see_changeset
msgid "User Can See Changeset"
msgstr "Usuario Puede ver Conjunto de Cambios"
Loading
Loading