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 @@
import datetime
import json
import logging
import os
import random
import select
import threading
......@@ -12,11 +13,16 @@ from odoo import api, fields, models, SUPERUSER_ID
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools import date_utils
from psycopg2 import sql
_logger = logging.getLogger(__name__)
# longpolling timeout connection
TIMEOUT = 50
# custom function to call instead of NOTIFY postgresql command (opt-in)
ODOO_NOTIFY_FUNCTION = os.environ.get('ODOO_NOTIFY_FUNCTION')
#----------------------------------------------------------
# Bus
#----------------------------------------------------------
......@@ -62,7 +68,11 @@ class ImBus(models.Model):
@self.env.cr.postcommit.add
def notify():
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
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