From: Michael Tremer Date: Tue, 3 Mar 2026 14:21:26 +0000 (+0000) Subject: dbl: Make it more convenient to impersonate another user X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84225cd4159b9618b00176efe7fd3a61ee3ded81;p=ipfire.org.git dbl: Make it more convenient to impersonate another user Signed-off-by: Michael Tremer --- diff --git a/src/backend/dbl.py b/src/backend/dbl.py index a196bea4..8c94d630 100644 --- a/src/backend/dbl.py +++ b/src/backend/dbl.py @@ -20,7 +20,7 @@ from .decorators import * log = logging.getLogger(__name__) class DBL(Object): - async def _fetch(self, path, headers=None, args=None, body=None, **kwargs): + async def _fetch(self, path, headers=None, args=None, body=None, as_user=None, **kwargs): if headers is None: headers = {} @@ -43,6 +43,16 @@ class DBL(Object): "X-API-Key" : self.backend.settings.get("dbl-api-key", ""), } + # Impersonate a user + if as_user: + if isinstance(as_user, accounts.Account): + as_user = as_user.uid + + # Compose the headers + headers |= { + "X-Impersonated-Uid" : as_user, + } + # Serialize any content if body: headers |= { @@ -234,15 +244,6 @@ class List(Model): """ Submits a report """ - # Only submit the UID of the user - if isinstance(reported_by, accounts.Account): - reported_by = reported_by.uid - - # Compose the headers - headers = { - "X-Impersonated-Uid" : reported_by, - } - # Compose the request body body = { "name" : name, @@ -252,7 +253,7 @@ class List(Model): # Submit the report response = await self._backend.dbl._fetch( - "/lists/%s/reports" % self.slug, method="POST", body=body, + "/lists/%s/reports" % self.slug, method="POST", body=body, as_user=reported_by, ) # Return the report