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 = {}
"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 |= {
"""
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,
# 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