Skip to content
Snippets Groups Projects
Commit 7bedae38 authored by Fabien Meghazi's avatar Fabien Meghazi
Browse files

[ADD] bus: add support for custom functions in imbus notify


This patch provides the possibility to implement a custom security layer on top
of Odoo's bus notification system which uses postgresql's NOTIFY command.

The key addition is the `ODOO_NOTIFY_FUNCTION` environment variable (opt-in),
which can now define a postgresql function to be called instead of the NOTIFY
command. This allows for greater flexibility and control over the notification
and triggering mechanisms within Odoo.

closes odoo/odoo#130368

Signed-off-by: default avatarFabien Meghazi (fme) <fme@odoo.com>
parent 0d19b9e9
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import datetime import datetime
import json import json
import logging import logging
import os
import random import random
import select import select
import threading import threading
...@@ -12,11 +13,16 @@ from odoo import api, fields, models, SUPERUSER_ID ...@@ -12,11 +13,16 @@ from odoo import api, fields, models, SUPERUSER_ID
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools import date_utils from odoo.tools import date_utils
from psycopg2 import sql
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
# longpolling timeout connection # longpolling timeout connection
TIMEOUT = 50 TIMEOUT = 50
# custom function to call instead of NOTIFY postgresql command (opt-in)
ODOO_NOTIFY_FUNCTION = os.environ.get('ODOO_NOTIFY_FUNCTION')
#---------------------------------------------------------- #----------------------------------------------------------
# Bus # Bus
#---------------------------------------------------------- #----------------------------------------------------------
...@@ -62,7 +68,11 @@ class ImBus(models.Model): ...@@ -62,7 +68,11 @@ class ImBus(models.Model):
@self.env.cr.postcommit.add @self.env.cr.postcommit.add
def notify(): def notify():
with odoo.sql_db.db_connect('postgres').cursor() as cr: with odoo.sql_db.db_connect('postgres').cursor() as cr:
cr.execute("notify imbus, %s", (json_dump(list(channels)),)) if ODOO_NOTIFY_FUNCTION:
query = sql.SQL("SELECT {}('imbus', %s)").format(sql.Identifier(ODOO_NOTIFY_FUNCTION))
else:
query = "NOTIFY imbus, %s"
cr.execute(query, (json_dump(list(channels)), ))
@api.model @api.model
def sendone(self, channel, message): def sendone(self, channel, message):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment