[ADD] base: add support for custom imbus & cron_trigger postgres notifications
This patch provides the possibility to implement a custom security layer on top of Odoo's imbus notification system and ir_cron live triggering system. The key addition is the `ODOO_NOTIFY_FUNCTION` environment variable (opt-in), which can now define a custom postgresql function to be called instead of the default `pg_notify` function. This allows for greater flexibility and control over the notification and triggering mechanisms within Odoo. closes odoo/odoo#140089 Signed-off-by: Fabien Meghazi (fme) <fme@odoo.com>
This commit is contained in:
@@ -3,11 +3,12 @@ import contextlib
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import selectors
|
||||
import threading
|
||||
import time
|
||||
from psycopg2 import InterfaceError
|
||||
from psycopg2 import InterfaceError, sql
|
||||
|
||||
import odoo
|
||||
from odoo import api, fields, models
|
||||
@@ -20,6 +21,9 @@ _logger = logging.getLogger(__name__)
|
||||
# longpolling timeout connection
|
||||
TIMEOUT = 50
|
||||
|
||||
# custom function to call instead of default PostgreSQL's `pg_notify`
|
||||
ODOO_NOTIFY_FUNCTION = os.getenv('ODOO_NOTIFY_FUNCTION', 'pg_notify')
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Bus
|
||||
#----------------------------------------------------------
|
||||
@@ -77,7 +81,8 @@ 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)),))
|
||||
query = sql.SQL("SELECT {}('imbus', %s)").format(sql.Identifier(ODOO_NOTIFY_FUNCTION))
|
||||
cr.execute(query, (json_dump(list(channels)), ))
|
||||
|
||||
@api.model
|
||||
def _sendone(self, channel, notification_type, message):
|
||||
|
||||
Reference in New Issue
Block a user