batches: surface batch change feature availability in JS context (#52044)

Surfaces license information about the availability of Batch Changes on a site license via the JS Context `LicenseInfo` object. The information surfaced mirrors the structure which which it is defined at the license plan level.
This commit is contained in:
Kelli Rockwell 2023-05-17 08:51:59 -07:00 committed by GitHub
parent ad3e7dcb10
commit baee619e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 4 deletions

View File

@ -9,15 +9,26 @@ import (
// middleware. The client is authenticated when PostAuthMiddleware is called.
var PostAuthMiddleware func(http.Handler) http.Handler
// FeatureBatchChanges describes if and how the Batch Changes feature is available on
// the given license plan. It mirrors the type licensing.FeatureBatchChanges.
type FeatureBatchChanges struct {
// If true, there is no limit to the number of changesets that can be created.
Unrestricted bool `json:"unrestricted"`
// Maximum number of changesets that can be created per batch change.
// If Unrestricted is true, this is ignored.
MaxNumChangesets int `json:"maxNumChangesets"`
}
// LicenseInfo contains information about the legitimate usage of the current
// license on the instance.
type LicenseInfo struct {
CurrentPlan string `json:"currentPlan"`
CodeScaleLimit string `json:"codeScaleLimit"`
CodeScaleCloseToLimit bool `json:"codeScaleCloseToLimit"`
CodeScaleExceededLimit bool `json:"codeScaleExceededLimit"`
KnownLicenseTags []string `json:"knownLicenseTags"`
CodeScaleLimit string `json:"codeScaleLimit"`
CodeScaleCloseToLimit bool `json:"codeScaleCloseToLimit"`
CodeScaleExceededLimit bool `json:"codeScaleExceededLimit"`
KnownLicenseTags []string `json:"knownLicenseTags"`
BatchChanges *FeatureBatchChanges `json:"batchChanges"`
}
var GetLicenseInfo = func(isSiteAdmin bool) *LicenseInfo { return nil }

View File

@ -170,6 +170,12 @@ type JSContext struct {
Branding *schema.Branding `json:"branding"`
// BatchChangesEnabled is true if:
// * Batch Changes is NOT disabled by a flag in the site config
// * Batch Changes is NOT limited to admins-only, or it is, but the user issuing
// the request is an admin and thus can access batch changes
// It does NOT reflect whether or not the site license has batch changes available.
// Use LicenseInfo for that.
BatchChangesEnabled bool `json:"batchChangesEnabled"`
BatchChangesDisableWebhooksWarning bool `json:"batchChangesDisableWebhooksWarning"`
BatchChangesWebhookLogsEnabled bool `json:"batchChangesWebhookLogsEnabled"`

View File

@ -94,6 +94,22 @@ func Init(
licenseInfo.KnownLicenseTags = append(licenseInfo.KnownLicenseTags, feature.FeatureName())
}
licenseInfo.KnownLicenseTags = append(licenseInfo.KnownLicenseTags, licensing.MiscTags...)
} else {
bcFeature := &licensing.FeatureBatchChanges{}
if err := licensing.Check(bcFeature); err == nil {
if bcFeature.Unrestricted {
licenseInfo.BatchChanges = &hooks.FeatureBatchChanges{
Unrestricted: true,
// Superceded by being unrestricted
MaxNumChangesets: -1,
}
} else {
max := int(bcFeature.MaxNumChangesets)
licenseInfo.BatchChanges = &hooks.FeatureBatchChanges{
MaxNumChangesets: max,
}
}
}
}
return licenseInfo