From c005d37cd70ee7f2aba06ebeceebcc61fcf39c8b Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 17 May 2024 19:22:15 -0600 Subject: [PATCH] Removing all the weird org type check functions --- admin/routes.go | 5 +++++ models/organization.go | 28 ++++++++++++---------------- templates/admin_org_detail.html | 12 +----------- templates/admin_user_detail.html | 12 +----------- templates/org_list.html | 15 +-------------- 5 files changed, 20 insertions(+), 52 deletions(-) diff --git a/admin/routes.go b/admin/routes.go index a9b6fdd..b99e9e5 100644 --- a/admin/routes.go +++ b/admin/routes.go @@ -1410,6 +1410,11 @@ func (s *Service) UserDetail(c echo.Context) error { ownerId ownerName createdOn + settings { + billing { + status + } + } } } }`) diff --git a/models/organization.go b/models/organization.go index dca6a6d..f31e273 100644 --- a/models/organization.go +++ b/models/organization.go @@ -7,9 +7,11 @@ import ( "encoding/json" "errors" "fmt" + "links/internal/localizer" "time" sq "github.com/Masterminds/squirrel" + "github.com/labstack/echo/v4" "netlandish.com/x/gobwebs/database" "netlandish.com/x/gobwebs/timezone" ) @@ -246,26 +248,20 @@ func (o *Organization) IsRestricted(restrictedStatus []int) bool { return false } -// XXX We should remove these and make the fetching of status with translations -// via a helper function that takes a context func (o *Organization) IsFreeAccount() bool { return o.Settings.Billing.Status == BillingStatusFree } -func (o *Organization) IsPersonalAccount() bool { - return o.Settings.Billing.Status == BillingStatusPersonal -} - -func (o *Organization) IsBusinessAccount() bool { - return o.Settings.Billing.Status == BillingStatusBusiness -} - -func (o *Organization) IsOpenSourceAccount() bool { - return o.Settings.Billing.Status == BillingStatusOpenSource -} - -func (o *Organization) IsSponsoredAccount() bool { - return o.Settings.Billing.Status == BillingStatusSponsored +func (o *Organization) DisplayBillingStatus(c echo.Context) string { + lt := localizer.GetSessionLocalizer(c) + status := map[int]string{ + BillingStatusFree: lt.Translate("Free"), + BillingStatusPersonal: lt.Translate("Personal"), + BillingStatusBusiness: lt.Translate("Business"), + BillingStatusOpenSource: lt.Translate("Open Source"), + BillingStatusSponsored: lt.Translate("Sponsored"), + } + return status[o.Settings.Billing.Status] } // This function ennable or disable based on the boolean flag a batch of organization diff --git a/templates/admin_org_detail.html b/templates/admin_org_detail.html index f4b0c1f..8922342 100644 --- a/templates/admin_org_detail.html +++ b/templates/admin_org_detail.html @@ -25,17 +25,7 @@ {{.pd.Data.subscription}} - - {{ if .org.IsFreeAccount }} - {{.pd.Data.free}} - {{ else if .org.IsPersonalAccount }} - {{$.pd.Data.personal}} ({{.pd.Data.paid}}) - {{ else if .org.IsBusinessAccount }} - {{$.pd.Data.business}} ({{.pd.Data.paid}}) - {{ else if .org.IsOpenSourceAccount }} - {{$.pd.Data.open_source}} - {{end}} - + {{ .org.DisplayBillingStatus .context }} {{.pd.Data.created_on}} diff --git a/templates/admin_user_detail.html b/templates/admin_user_detail.html index ee74abd..e3dcac5 100644 --- a/templates/admin_user_detail.html +++ b/templates/admin_user_detail.html @@ -57,17 +57,7 @@ {{.Name}} {{.Slug}} - - {{ if .IsFreeAccount }} - {{$.pd.Data.free}} - {{ else if .IsPersonalAccount }} - {{$.pd.Data.personal}} ({{$.pd.Data.paid}}) - {{ else if .IsBusinessAccount }} - {{$.pd.Data.business}} ({{$.pd.Data.paid}}) - {{ else if .IsOpenSourceAccount }} - {{$.pd.Data.open_source}} - {{end}} - + {{ .DisplayBillingStatus $.context }} {{if .IsActive}} {{$.pd.Data.enabled}} diff --git a/templates/org_list.html b/templates/org_list.html index a0f2aeb..3043125 100644 --- a/templates/org_list.html +++ b/templates/org_list.html @@ -20,20 +20,7 @@ {{.Name}} {{.Slug}} - - {{/* NOTE: we should implement here context translation */}} - {{ if .IsFreeAccount }} - {{$.pd.Data.free}} - {{ else if .IsPersonalAccount }} - {{$.pd.Data.personal}} ({{$.pd.Data.paid}}) - {{ else if .IsBusinessAccount }} - {{$.pd.Data.business}} ({{$.pd.Data.paid}}) - {{ else if .IsOpenSourceAccount }} - {{$.pd.Data.open_source}} - {{ else if .IsSponsoredAccount }} - {{$.pd.Data.sponsored}} - {{end}} - + {{ .DisplayBillingStatus $.context }} {{if .IsActive}} -- 2.45.2