~netlandish/links

c005d37cd70ee7f2aba06ebeceebcc61fcf39c8b — Peter Sanchez 5 months ago ec32d73
Removing all the weird org type check functions
M admin/routes.go => admin/routes.go +5 -0
@@ 1410,6 1410,11 @@ func (s *Service) UserDetail(c echo.Context) error {
					ownerId
					ownerName
					createdOn
					settings {
						billing {
							status
						}
					}
				}
			}
		}`)

M models/organization.go => models/organization.go +12 -16
@@ 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

M templates/admin_org_detail.html => templates/admin_org_detail.html +1 -11
@@ 25,17 25,7 @@
      </tr>
      <tr>
        <th>{{.pd.Data.subscription}}</th>
        <td>
            {{ 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}}
        </td>
        <td>{{ .org.DisplayBillingStatus .context }}</td>
      </tr>
      <tr>
        <th>{{.pd.Data.created_on}}</th>

M templates/admin_user_detail.html => templates/admin_user_detail.html +1 -11
@@ 57,17 57,7 @@
              <tr>
                <td><a href="{{reverse "admin:org_detail" .ID}}">{{.Name}}</a></td>
                <td><a href="{{reverse "admin:org_detail" .ID}}">{{.Slug}}</a></td>
                <td>
                    {{ 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}}
                </td>
                <td>{{ .DisplayBillingStatus $.context }}</td>
                <td>
                    {{if .IsActive}}
                        {{$.pd.Data.enabled}}

M templates/org_list.html => templates/org_list.html +1 -14
@@ 20,20 20,7 @@
             <tr {{if eq .Slug $.dOrgSlug }}class="active-row"{{end}}>
                <td>{{.Name}}</td>
                <td>{{.Slug}}</td>
                <td>
                    {{/* 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}}
                </td>
                <td>{{ .DisplayBillingStatus $.context }}</td>
                <td>
                    {{if .IsActive}}
                        <svg style="width:20px" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-primary">