diff --git a/app/urls.py b/app/urls.py index 23265fb..5b01f4b 100644 --- a/app/urls.py +++ b/app/urls.py @@ -20,7 +20,7 @@ from django.contrib.auth.views import LogoutView from django.urls import include, path from two_factor.urls import urlpatterns as tf_urls -from core.views import ads, aggregators, banks, base, notifications, platforms +from core.views import aggregators, banks, base, notifications, platforms, ads # from core.views.stripe_callbacks import Callback @@ -175,6 +175,11 @@ urlpatterns = [ ads.AdDist.as_view(), name="ad_dist", ), + path( + "ops/ads/nuke/", + ads.AdNuke.as_view(), + name="ad_nuke", + ), path( "ops/ads/redist/", ads.AdRedist.as_view(), diff --git a/core/clients/platform.py b/core/clients/platform.py index d9d7b09..1b674c9 100644 --- a/core/clients/platform.py +++ b/core/clients/platform.py @@ -667,14 +667,17 @@ class LocalPlatformClient(ABC): account_info, ) = self.get_valid_account_details(ad) # Let's get rid of the ad IDs and make it a tuple like dist_list - our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] - if not our_ads: - log.error("Could not get our ads.") + if our_ads in [None, False]: + log.error("Could not get our ads") return False + our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] + to_return = [] for asset, countrycode, currency, provider in dist_list: if (asset, countrycode, currency, provider) not in our_ads: if currency in supported_currencies: + if currency not in account_info: + continue # Create the actual ad and pass in all the stuff rtrn = await self.create_ad( asset, diff --git a/core/lib/schemas/agora_s.py b/core/lib/schemas/agora_s.py index 3d5b73d..40fcbf3 100644 --- a/core/lib/schemas/agora_s.py +++ b/core/lib/schemas/agora_s.py @@ -14,7 +14,8 @@ class ContactDataAd(BaseModel): trade_type: str advertiser: ContactDataBuyerSeller asset: str - id: str + id: str | None + contact_id: str | None class ContactData(BaseModel): @@ -51,8 +52,8 @@ class ContactData(BaseModel): class ContactActions(BaseModel): - advertisement_public_view: str - advertisement_url: str + advertisement_public_view: str | None + advertisement_url: str | None message_post_url: str messages_url: str release_url: str diff --git a/core/views/ads.py b/core/views/ads.py index 6dc71e3..2b05ad8 100644 --- a/core/views/ads.py +++ b/core/views/ads.py @@ -17,6 +17,18 @@ from core.models import Ad from core.util import logs from core.views.helpers import synchronize_async_helper +class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View): + template_name = "mixins/partials/notify.html" + + def get(self, request): + ads = Ad.objects.filter(user=request.user, enabled=True) + for ad in ads: + for platform in ad.platforms.all(): + run = synchronize_async_helper(AgoraClient(platform)) + synchronize_async_helper(run.nuke_ads()) + + context = {"class": "success", "message": "Nuking ads"} + return render(request, self.template_name, context) class AdDist(LoginRequiredMixin, OTPRequiredMixin, View): template_name = "mixins/partials/notify.html" @@ -73,6 +85,13 @@ class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList): "label": "Update ads", "icon": "fa-solid fa-refresh", }, + { + "url": reverse("ad_nuke"), + "action": "nuke", + "method": "get", + "label": "Nuke ads", + "icon": "fa-solid fa-bomb", + }, ] return context