Skip to content

Commit

Permalink
fix the admin query for integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 27, 2024
1 parent 75d9519 commit 191cf78
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 191cf78

Please sign in to comment.