From 191cf78b76ec71bd4e4790e573f7083bc18d662a Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Tue, 27 Feb 2024 20:15:55 +0530 Subject: [PATCH] fix the admin query for integrations --- recipes/VideoBots.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/recipes/VideoBots.py b/recipes/VideoBots.py index b6b606730..5b66f6bdf 100644 --- a/recipes/VideoBots.py +++ b/recipes/VideoBots.py @@ -4,7 +4,7 @@ import os.path import typing -from django.db.models import QuerySet +from django.db.models import QuerySet, Q from furl import furl from pydantic import BaseModel, Field @@ -1029,14 +1029,21 @@ def messenger_bot_integration(self): *extract_query_params(gooey_get_query_params()) ) # type: ignore + integrations_q = Q(billing_account_uid=self.request.user.uid) + + # show admins all the bots connected to the current run + if self.is_current_user_admin(): + integrations_q |= Q(saved_run=current_run) + if published_run: + integrations_q |= Q( + saved_run__example_id=published_run.published_run_id + ) + integrations_q |= Q(published_run=published_run) + integrations: QuerySet[BotIntegration] = BotIntegration.objects.filter( - billing_account_uid=self.request.user.uid + integrations_q ).order_by("platform", "-created_at") - if self.is_current_user_admin(): - integrations |= BotIntegration.objects.filter( - published_run=published_run - ).order_by("platform", "-created_at") if not integrations: return