Skip to content

Commit

Permalink
fix: disable subscription crud
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Feb 2, 2024
1 parent c3af9dc commit a2b130d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
38 changes: 33 additions & 5 deletions bd_api/apps/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ class SubscriptionInline(admin.StackedInline):
extra = 0
ordering = ["-created_at"]

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 SuperUserListFilter(admin.SimpleListFilter):
title = gettext_lazy("Admin²")
Expand Down Expand Up @@ -165,13 +174,28 @@ def queryset(self, request, queryset):
return queryset.filter(internal_subscription__is_active=False)


class SubscriptionStatusListFilter(admin.SimpleListFilter):
title = gettext_lazy("Tipo")
parameter_name = "subscriber"

def lookups(self, request, model_admin):
return [
("trialing", gettext_lazy("Trial")),
("active", gettext_lazy("Active")),
("past_due", gettext_lazy("PastDue")),
("canceled", gettext_lazy("Canceled")),
("incomplete_expired", gettext_lazy("IncompleteExpired")),
]

def queryset(self, request, queryset):
if self.value():
return queryset.filter(subscription__status=self.value())


class AccountAdmin(BaseAccountAdmin):
form = AccountChangeForm
add_form = AccountCreationForm

# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = (
"email",
"username",
Expand All @@ -180,13 +204,13 @@ class AccountAdmin(BaseAccountAdmin):
"created_at",
"is_admin",
)
readonly_fields = ("uuid", "created_at", "updated_at", "deleted_at")
list_filter = (
SuperUserListFilter,
"is_admin",
"profile",
SubscriptionListFilter,
)
readonly_fields = ("uuid", "created_at", "updated_at", "deleted_at")
fieldsets = (
(
None,
Expand Down Expand Up @@ -285,20 +309,24 @@ class SubscriptionAdmin(admin.ModelAdmin):
"stripe_subscription_status",
"stripe_subscription_created_at",
)
list_filter = (SubscriptionStatusListFilter,)
search_fields = ("admin__full_name",)
readonly_fields = (
"id",
"admin",
"subscription",
)
ordering = ["admin__email", "subscription__created"]
ordering = ["-subscription__created"]

def has_add_permission(self, request):
return False

def has_change_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


admin.site.register(Account, AccountAdmin)
admin.site.register(Career, CareerAdmin)
Expand Down
5 changes: 4 additions & 1 deletion bd_api/apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class Meta:
verbose_name_plural = "Careers"

def __str__(self):
return f"{self.account.first_name} @{self.role}"
return f"{self.account.email} @{self.role}"

def get_team(self):
return self.team
Expand Down Expand Up @@ -465,6 +465,9 @@ class Meta:
verbose_name = "Subscription"
verbose_name_plural = "Subscriptions"

def __str__(self):
return f"{self.admin.email} @ {self.subscription.plan}"

@property
def admin_email(self):
return self.admin.email or "[email protected]"
Expand Down

0 comments on commit a2b130d

Please sign in to comment.