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
10 changes: 10 additions & 0 deletions bacula_base_automation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
====================================================
Automation Rules customizations for Bacula Systems
====================================================

* adds following objects to server action eval context:

* Cerb
* make_request
* get_stack
* requote_uri
1 change: 1 addition & 0 deletions bacula_base_automation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions bacula_base_automation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": """Automation Rules customizations for Bacula Systems""",
"version": "19.0.0.1.0",
"author": "IT-Projects LLC, Eugene Molotov",
"support": "it@it-projects.info",
"website": "https://github.com/it-projects-llc/bacula-addons",
"license": "LGPL-3",
"depends": [
"base_automation",
],
"data": [],
"demo": [],
}
1 change: 1 addition & 0 deletions bacula_base_automation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ir_actions_server
29 changes: 29 additions & 0 deletions bacula_base_automation/models/ir_actions_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import traceback

from requests import request
from requests.utils import requote_uri

from odoo import models

try:
from cerbapi import Cerb
except ImportError:
Cerb = None


class IrActionsServer(models.Model):
_inherit = "ir.actions.server"

def _get_eval_context(self, action=None):
eval_context = super()._get_eval_context(action)

def get_stack():
return "\n".join(traceback.format_stack())

eval_context.update(
Cerb=Cerb,
requote_uri=requote_uri,
get_stack=get_stack,
make_request=request,
)
return eval_context
3 changes: 3 additions & 0 deletions bacula_base_automation/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions bacula_base_automation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_minimal
32 changes: 32 additions & 0 deletions bacula_base_automation/tests/test_minimal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from odoo.tests import tagged
from odoo.tests.common import TransactionCase


@tagged("post_install", "-at_install")
class TestMinimal(TransactionCase):
def test_eval_context(self):
action = self.env["ir.actions.server"].create(
{
"name": "TestAction",
"model_id": self.env.ref("base.model_res_partner").id,
"model_name": "res.partner",
"state": "code",
"code": 'record.write({"comment": "test"})',
}
)

ectx = self.env["ir.actions.server"]._get_eval_context(action)

# in previous versions of Odoo, b64* methods did not exist
self.assertEqual(ectx["b64encode"](b"a"), b"YQ==")
self.assertEqual(ectx["b64decode"](b"YQ=="), b"a")

stack = ectx["get_stack"]()
self.assertIn("test_eval_context", stack)

self.assertEqual(
"https://www.somerandom.com/?name=Something%20Cool",
ectx["requote_uri"]("https://www.somerandom.com/?name=Something Cool"),
)

self.assertIn("Cerb", ectx)