Skip to content

Commit b7acce9

Browse files
committed
feat: remove Feature.enable_by_default in favor of scope field
The scope field (GLOBAL/PER_CHAIN) now fully covers the use case that enable_by_default served, making the flag redundant.
1 parent 09fa0dc commit b7acce9

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

src/chains/admin.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
from .models import Chain, Feature, GasPrice, Service, Wallet
99

1010

11-
class FeatureInlineFormSet(BaseInlineFormSet[Model, Model, ModelForm[Model]]):
12-
def __init__(self, *args: Any, **kwargs: Any) -> None:
13-
super().__init__(*args, **kwargs)
14-
if self.instance.pk is None:
15-
default_features = list(Feature.objects.filter(enable_by_default=True))
16-
self.initial = [{"feature": feature.id} for feature in default_features]
17-
self.extra = len(default_features)
18-
19-
2011
class WalletInlineFormSet(BaseInlineFormSet[Model, Model, ModelForm[Model]]):
2112
def __init__(self, *args: Any, **kwargs: Any) -> None:
2213
super().__init__(*args, **kwargs)
@@ -51,7 +42,6 @@ class GasPriceInline(admin.TabularInline[Model, Model]):
5142

5243
class FeatureInline(admin.TabularInline[Model, Model]):
5344
model = Feature.chains.through
54-
formset = FeatureInlineFormSet
5545
extra = 0
5646
verbose_name_plural = "Features enabled for this chain"
5747

@@ -115,15 +105,15 @@ class ServiceAdmin(admin.ModelAdmin[Service]):
115105
@admin.register(Feature)
116106
class FeatureAdmin(admin.ModelAdmin[Feature]):
117107
form = FeatureAdminForm
118-
list_display = ("key", "scope", "description", "enable_by_default")
119-
list_editable = ("enable_by_default", "scope")
108+
list_display = ("key", "scope", "description")
109+
list_editable = ("scope",)
120110
list_filter = ("scope", "services")
121111
fieldsets = (
122112
(None, {"fields": ("key", "description")}),
123113
(
124114
"Scope Configuration",
125115
{
126-
"fields": ("scope", "chains", "enable_by_default", "services"),
116+
"fields": ("scope", "chains", "services"),
127117
"description": "Configure which chains and services have access to this feature.",
128118
},
129119
),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 6.0.2 on 2026-02-19 14:37
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('chains', '0052_feature_scope_services'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='feature',
15+
name='enable_by_default',
16+
),
17+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django.db.migrations.state import StateApps
2+
3+
from chains.migrations.tests.utils import TestMigrations
4+
5+
6+
class Migration0053TestCase(TestMigrations):
7+
migrate_from = "0052_feature_scope_services"
8+
migrate_to = "0053_remove_feature_enable_by_default"
9+
10+
def setUpBeforeMigration(self, apps: StateApps) -> None:
11+
Feature = apps.get_model("chains", "Feature")
12+
Feature.objects.create(
13+
key="test-feature",
14+
description="Test feature",
15+
enable_by_default=True,
16+
scope="PER_CHAIN",
17+
)
18+
19+
def test_feature_preserved(self) -> None:
20+
Feature = self.apps_registry.get_model("chains", "Feature")
21+
feature = Feature.objects.get(key="test-feature")
22+
self.assertEqual(feature.description, "Test feature")
23+
24+
def test_enable_by_default_removed(self) -> None:
25+
Feature = self.apps_registry.get_model("chains", "Feature")
26+
field_names = [f.name for f in Feature._meta.get_fields()]
27+
self.assertNotIn("enable_by_default", field_names)

src/chains/models.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@ class Scope(models.TextChoices):
290290
help_text="The unique name/key that identifies this feature",
291291
)
292292
description = models.CharField(max_length=255, default="")
293-
enable_by_default = models.BooleanField(
294-
default=False,
295-
help_text="If checked, this feature will be automatically enabled when creating a chain.",
296-
)
297293
scope = models.CharField(
298294
max_length=10,
299295
choices=Scope.choices,

0 commit comments

Comments
 (0)