diff --git a/api/account/admin.py b/api/account/admin.py index 0ee5cf90c..bede7ea7f 100644 --- a/api/account/admin.py +++ b/api/account/admin.py @@ -22,6 +22,7 @@ Customization, AddressList, AddressListMember, + IncludedChainId, ) @@ -210,11 +211,16 @@ class AllowListInline(admin.TabularInline): extra = 0 +class IncludedChainIdInline(admin.TabularInline): + model = IncludedChainId + extra = 0 + + @admin.register(Customization) class CustomizationAdmin(ScorerModelAdmin): form = CustomizationForm raw_id_fields = ["scorer"] - inlines = [AllowListInline] + inlines = [AllowListInline, IncludedChainIdInline] fieldsets = [ ( None, diff --git a/api/account/api.py b/api/account/api.py index 1519808ad..d6ca9f982 100644 --- a/api/account/api.py +++ b/api/account/api.py @@ -611,6 +611,10 @@ def get_account_customization(request, dashboard_path: str): weights.update(customization.get_customization_dynamic_weights()) + included_chain_ids = list( + customization.included_chain_ids.values_list("chain_id", flat=True) + ) + return dict( key=customization.path, useCustomDashboardPanel=customization.use_custom_dashboard_panel, @@ -644,6 +648,7 @@ def get_account_customization(request, dashboard_path: str): "weights": weights, "id": customization.scorer.id, }, + includedChainIds=included_chain_ids, ) except Customization.DoesNotExist: diff --git a/api/account/migrations/0030_includedchainid.py b/api/account/migrations/0030_includedchainid.py new file mode 100644 index 000000000..b04ce97c4 --- /dev/null +++ b/api/account/migrations/0030_includedchainid.py @@ -0,0 +1,39 @@ +# Generated by Django 4.2.6 on 2024-06-20 18:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("account", "0029_alter_addresslist_name"), + ] + + operations = [ + migrations.CreateModel( + name="IncludedChainId", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("chain_id", models.CharField(max_length=200)), + ( + "customization", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="included_chain_ids", + to="account.customization", + ), + ), + ], + options={ + "unique_together": {("chain_id", "customization")}, + }, + ), + ] diff --git a/api/account/models.py b/api/account/models.py index 8e780f804..a203ce87b 100644 --- a/api/account/models.py +++ b/api/account/models.py @@ -504,6 +504,16 @@ async def aget_customization_dynamic_weights(self) -> dict: return weights +class IncludedChainId(models.Model): + chain_id = models.CharField(max_length=200, blank=False, null=False) + customization = models.ForeignKey( + Customization, on_delete=models.CASCADE, related_name="included_chain_ids" + ) + + class Meta: + unique_together = ["chain_id", "customization"] + + class AllowList(models.Model): address_list = models.ForeignKey( AddressList, on_delete=models.PROTECT, related_name="allow_lists"