fix #5919 chore(nimbus): add isolation group/bucketrange readonly admin (#5920)

Because

* It will also be helpful to inspect all isolation groups and their assigned bucket ranges, not just per experiment
* They should be read only

This commit

* Adds isolation group directly to the admin as read only
This commit is contained in:
Jared Lockhart 2021-07-12 12:45:10 -04:00 коммит произвёл GitHub
Родитель 1718da251a
Коммит 47352d88fc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 27 добавлений и 4 удалений

Просмотреть файл

@ -9,9 +9,34 @@ from experimenter.experiments.models import (
NimbusDocumentationLink,
NimbusExperiment,
NimbusFeatureConfig,
NimbusIsolationGroup,
)
class ReadOnlyAdminMixin:
def has_add_permission(self, request, obj=None):
return False
def has_change_permission(self, request, obj=None):
return False
def has_delete_permission(self, request, obj=None):
return False
class NimbusBucketRangeInlineAdmin(ReadOnlyAdminMixin, admin.StackedInline):
model = NimbusBucketRange
extra = 0
class NimbusIsolationGroupAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
inlines = (NimbusBucketRangeInlineAdmin,)
class Meta:
model = NimbusIsolationGroup
exclude = ("id",)
class NimbusBranchInlineAdmin(admin.StackedInline):
model = NimbusBranch
extra = 0
@ -27,7 +52,7 @@ class NimbusExperimentChangeLogInlineAdmin(admin.StackedInline):
extra = 1
class NimbusExperimentBucketRangeInlineAdmin(admin.StackedInline):
class NimbusExperimentBucketRangeInlineAdmin(ReadOnlyAdminMixin, admin.StackedInline):
model = NimbusBucketRange
extra = 0
fields = (
@ -57,9 +82,6 @@ class NimbusExperimentBucketRangeInlineAdmin(admin.StackedInline):
def isolation_group_total(self, instance):
return instance.isolation_group.total
def has_add_permission(self, request, obj):
return False
class NimbusExperimentAdminForm(forms.ModelForm):
channel = forms.ChoiceField(choices=NimbusExperiment.Channel.choices)
@ -116,6 +138,7 @@ class NimbusFeatureConfigAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("name",)}
admin.site.register(NimbusIsolationGroup, NimbusIsolationGroupAdmin)
admin.site.register(NimbusExperiment, NimbusExperimentAdmin)
admin.site.register(NimbusFeatureConfig, NimbusFeatureConfigAdmin)
admin.site.register(NimbusDocumentationLink)