Allow checking account ID whitelist
This commit is contained in:
parent
ef546ce21b
commit
9b6180ac5b
|
@ -665,7 +665,7 @@ class LocalPlatformClient(ABC):
|
||||||
(
|
(
|
||||||
supported_currencies,
|
supported_currencies,
|
||||||
account_info,
|
account_info,
|
||||||
) = self.get_valid_account_details()
|
) = self.get_valid_account_details(ad)
|
||||||
# Let's get rid of the ad IDs and make it a tuple like dist_list
|
# 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]
|
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
|
||||||
if not our_ads:
|
if not our_ads:
|
||||||
|
@ -704,7 +704,7 @@ class LocalPlatformClient(ABC):
|
||||||
(
|
(
|
||||||
supported_currencies,
|
supported_currencies,
|
||||||
account_info,
|
account_info,
|
||||||
) = self.get_valid_account_details(self.name)
|
) = self.get_valid_account_details(ad)
|
||||||
if not our_ads:
|
if not our_ads:
|
||||||
log.error("Could not get our ads.")
|
log.error("Could not get our ads.")
|
||||||
return False
|
return False
|
||||||
|
@ -935,7 +935,7 @@ class LocalPlatformClient(ABC):
|
||||||
log.info(f"Sending bank details/reference for {trade_id}")
|
log.info(f"Sending bank details/reference for {trade_id}")
|
||||||
if self.instance.send is True:
|
if self.instance.send is True:
|
||||||
print("SEND IS TRUE")
|
print("SEND IS TRUE")
|
||||||
account_info = self.get_matching_account_details(currency)
|
account_info = self.get_matching_account_details(currency, ad)
|
||||||
print("ACCOUNT INFO", account_info)
|
print("ACCOUNT INFO", account_info)
|
||||||
formatted_account_info = self.format_payment_details(
|
formatted_account_info = self.format_payment_details(
|
||||||
currency, account_info, ad, real=True
|
currency, account_info, ad, real=True
|
||||||
|
@ -1141,14 +1141,24 @@ class LocalPlatformClient(ABC):
|
||||||
else:
|
else:
|
||||||
yield (asset, countrycode, currency, provider)
|
yield (asset, countrycode, currency, provider)
|
||||||
|
|
||||||
def get_valid_account_details(self):
|
def get_valid_account_details(self, ad):
|
||||||
currencies = self.instance.currencies
|
currencies = self.instance.currencies
|
||||||
account_info = self.instance.account_info
|
account_info = self.instance.account_info
|
||||||
|
print("GET VALID", ad)
|
||||||
|
account_whitelist = ad.account_whitelist
|
||||||
|
if account_whitelist:
|
||||||
|
whitelist = account_whitelist.splitlines()
|
||||||
|
else:
|
||||||
|
whitelist = None
|
||||||
|
print("WHITELIST", whitelist)
|
||||||
currency_account_info_map = {}
|
currency_account_info_map = {}
|
||||||
for currency in currencies:
|
for currency in currencies:
|
||||||
for bank, accounts in account_info.items():
|
for bank, accounts in account_info.items():
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
if account["currency"] == currency:
|
if account["currency"] == currency:
|
||||||
|
if whitelist:
|
||||||
|
if account["account_id"] not in whitelist:
|
||||||
|
continue
|
||||||
currency_account_info_map[currency] = account["account_number"]
|
currency_account_info_map[currency] = account["account_number"]
|
||||||
currency_account_info_map[currency]["bank"] = bank.split("_")[0]
|
currency_account_info_map[currency]["bank"] = bank.split("_")[0]
|
||||||
currency_account_info_map[currency]["recipient"] = account[
|
currency_account_info_map[currency]["recipient"] = account[
|
||||||
|
@ -1156,11 +1166,11 @@ class LocalPlatformClient(ABC):
|
||||||
]
|
]
|
||||||
return (currencies, currency_account_info_map)
|
return (currencies, currency_account_info_map)
|
||||||
|
|
||||||
def get_matching_account_details(self, currency):
|
def get_matching_account_details(self, currency, ad):
|
||||||
(
|
(
|
||||||
supported_currencies,
|
supported_currencies,
|
||||||
currency_account_info_map,
|
currency_account_info_map,
|
||||||
) = self.get_valid_account_details()
|
) = self.get_valid_account_details(ad)
|
||||||
if currency not in supported_currencies:
|
if currency not in supported_currencies:
|
||||||
return False
|
return False
|
||||||
return currency_account_info_map[currency]
|
return currency_account_info_map[currency]
|
||||||
|
|
|
@ -155,6 +155,7 @@ class AdForm(RestrictedFormMixin, ModelForm):
|
||||||
"provider_list",
|
"provider_list",
|
||||||
"platforms",
|
"platforms",
|
||||||
"aggregators",
|
"aggregators",
|
||||||
|
"account_whitelist",
|
||||||
"visible",
|
"visible",
|
||||||
"enabled",
|
"enabled",
|
||||||
)
|
)
|
||||||
|
@ -169,6 +170,7 @@ class AdForm(RestrictedFormMixin, ModelForm):
|
||||||
"provider_list": "List of providers to distribute ads for.",
|
"provider_list": "List of providers to distribute ads for.",
|
||||||
"platforms": "Enabled platforms for this ad",
|
"platforms": "Enabled platforms for this ad",
|
||||||
"aggregators": "Enabled aggregators for this ad",
|
"aggregators": "Enabled aggregators for this ad",
|
||||||
|
"account_whitelist": "List of account IDs to use, one per line.",
|
||||||
"visible": "Whether or not this ad is visible.",
|
"visible": "Whether or not this ad is visible.",
|
||||||
"enabled": "Whether or not this ad is enabled.",
|
"enabled": "Whether or not this ad is enabled.",
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,17 @@ log = logs.get_logger("polling")
|
||||||
|
|
||||||
INTERVAL = 5
|
INTERVAL = 5
|
||||||
|
|
||||||
|
|
||||||
async def poll_aggregator(aggregator):
|
async def poll_aggregator(aggregator):
|
||||||
print("Polling aggregator", aggregator)
|
print("Polling aggregator", aggregator)
|
||||||
|
|
||||||
|
|
||||||
async def poll_platform(platform):
|
async def poll_platform(platform):
|
||||||
print("Polling platform", platform)
|
print("Polling platform", platform)
|
||||||
client = await AgoraClient(platform)
|
client = await AgoraClient(platform)
|
||||||
await client.poll()
|
await client.poll()
|
||||||
|
|
||||||
|
|
||||||
async def job():
|
async def job():
|
||||||
platforms = Platform.objects.filter(enabled=True)
|
platforms = Platform.objects.filter(enabled=True)
|
||||||
aggregators = Aggregator.objects.filter(enabled=True)
|
aggregators = Aggregator.objects.filter(enabled=True)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.1.7 on 2023-03-10 15:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0013_platform_platform_ad_ids'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ad',
|
||||||
|
name='account_whitelist',
|
||||||
|
field=models.TextField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -225,6 +225,7 @@ class Ad(models.Model):
|
||||||
aggregators = models.ManyToManyField(Aggregator)
|
aggregators = models.ManyToManyField(Aggregator)
|
||||||
|
|
||||||
account_map = models.JSONField(default=dict)
|
account_map = models.JSONField(default=dict)
|
||||||
|
account_whitelist = models.TextField(null=True, blank=True)
|
||||||
|
|
||||||
visible = models.BooleanField(default=True)
|
visible = models.BooleanField(default=True)
|
||||||
enabled = models.BooleanField(default=True)
|
enabled = models.BooleanField(default=True)
|
||||||
|
|
Loading…
Reference in New Issue