Skip to content

Commit

Permalink
avoid deleting facebook integrations that get removed from facebook
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Aug 19, 2024
1 parent a83eef6 commit c08a3c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _parse_dt(dt) -> datetime.datetime | None:

class BotIntegrationQuerySet(models.QuerySet):
@transaction.atomic()
def reset_fb_pages_for_user(
def add_fb_pages_for_user(
self, uid: str, fb_pages: list[dict]
) -> list["BotIntegration"]:
saved = []
Expand Down Expand Up @@ -454,13 +454,13 @@ def reset_fb_pages_for_user(
bi.name = bi.fb_page_name
bi.save()
saved.append(bi)
# delete pages that are no longer connected for this user
self.filter(
Q(platform=Platform.FACEBOOK) | Q(platform=Platform.INSTAGRAM),
billing_account_uid=uid,
).exclude(
id__in=[bi.id for bi in saved],
).delete()
# # delete pages that are no longer connected for this user
# self.filter(
# Q(platform=Platform.FACEBOOK) | Q(platform=Platform.INSTAGRAM),
# billing_account_uid=uid,
# ).exclude(
# id__in=[bi.id for bi in saved],
# ).delete()
return saved


Expand Down
2 changes: 1 addition & 1 deletion routers/facebook_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def fb_connect_redirect(request: Request):
)

map_parallel(_subscribe_to_page, fb_pages)
integrations = BotIntegration.objects.reset_fb_pages_for_user(
integrations = BotIntegration.objects.add_fb_pages_for_user(
request.user.uid, fb_pages
)

Expand Down

0 comments on commit c08a3c6

Please sign in to comment.