Skip to content

Commit b65c555

Browse files
authored
fix: warn user if not entitled feature is enabled (#4377)
1 parent 8d14076 commit b65c555

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

enterprise/coderd/coderd.go

+27-9
Original file line numberDiff line numberDiff line change
@@ -267,27 +267,45 @@ func (api *API) serveEntitlements(rw http.ResponseWriter, r *http.Request) {
267267
Entitlement: entitlements.auditLogs,
268268
Enabled: api.AuditLogging,
269269
}
270-
if entitlements.auditLogs == codersdk.EntitlementGracePeriod && api.AuditLogging {
271-
resp.Warnings = append(resp.Warnings,
272-
"Audit logging is enabled but your license for this feature is expired.")
270+
if api.AuditLogging {
271+
if entitlements.auditLogs == codersdk.EntitlementNotEntitled {
272+
resp.Warnings = append(resp.Warnings,
273+
"Audit logging is enabled but your license is not entitled to this feature.")
274+
}
275+
if entitlements.auditLogs == codersdk.EntitlementGracePeriod {
276+
resp.Warnings = append(resp.Warnings,
277+
"Audit logging is enabled but your license for this feature is expired.")
278+
}
273279
}
274280

275281
resp.Features[codersdk.FeatureBrowserOnly] = codersdk.Feature{
276282
Entitlement: entitlements.browserOnly,
277283
Enabled: api.BrowserOnly,
278284
}
279-
if entitlements.browserOnly == codersdk.EntitlementGracePeriod && api.BrowserOnly {
280-
resp.Warnings = append(resp.Warnings,
281-
"Browser only connections are enabled but your license for this feature is expired.")
285+
if api.BrowserOnly {
286+
if entitlements.browserOnly == codersdk.EntitlementNotEntitled {
287+
resp.Warnings = append(resp.Warnings,
288+
"Browser only connections are enabled but your license is not entitled to this feature.")
289+
}
290+
if entitlements.browserOnly == codersdk.EntitlementGracePeriod {
291+
resp.Warnings = append(resp.Warnings,
292+
"Browser only connections are enabled but your license for this feature is expired.")
293+
}
282294
}
283295

284296
resp.Features[codersdk.FeatureWorkspaceQuota] = codersdk.Feature{
285297
Entitlement: entitlements.workspaceQuota,
286298
Enabled: api.UserWorkspaceQuota > 0,
287299
}
288-
if entitlements.workspaceQuota == codersdk.EntitlementGracePeriod && api.UserWorkspaceQuota > 0 {
289-
resp.Warnings = append(resp.Warnings,
290-
"Workspace quotas are enabled but your license for this feature is expired.")
300+
if api.UserWorkspaceQuota > 0 {
301+
if entitlements.workspaceQuota == codersdk.EntitlementNotEntitled {
302+
resp.Warnings = append(resp.Warnings,
303+
"Workspace quotas are enabled but your license is not entitled to this feature.")
304+
}
305+
if entitlements.workspaceQuota == codersdk.EntitlementGracePeriod {
306+
resp.Warnings = append(resp.Warnings,
307+
"Workspace quotas are enabled but your license for this feature is expired.")
308+
}
291309
}
292310

293311
httpapi.Write(ctx, rw, http.StatusOK, resp)

enterprise/coderd/coderd_test.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ func TestEntitlements(t *testing.T) {
3636
})
3737
t.Run("FullLicense", func(t *testing.T) {
3838
t.Parallel()
39-
client := coderdenttest.New(t, nil)
39+
client := coderdenttest.New(t, &coderdenttest.Options{
40+
AuditLogging: true,
41+
})
4042
_ = coderdtest.CreateFirstUser(t, client)
4143
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
4244
UserLimit: 100,
@@ -59,7 +61,9 @@ func TestEntitlements(t *testing.T) {
5961
})
6062
t.Run("FullLicenseToNone", func(t *testing.T) {
6163
t.Parallel()
62-
client := coderdenttest.New(t, nil)
64+
client := coderdenttest.New(t, &coderdenttest.Options{
65+
AuditLogging: true,
66+
})
6367
_ = coderdtest.CreateFirstUser(t, client)
6468
license := coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
6569
UserLimit: 100,
@@ -85,7 +89,8 @@ func TestEntitlements(t *testing.T) {
8589
t.Run("Warnings", func(t *testing.T) {
8690
t.Parallel()
8791
client := coderdenttest.New(t, &coderdenttest.Options{
88-
BrowserOnly: true,
92+
AuditLogging: true,
93+
BrowserOnly: true,
8994
})
9095
first := coderdtest.CreateFirstUser(t, client)
9196
for i := 0; i < 4; i++ {
@@ -192,15 +197,17 @@ func TestAuditLogging(t *testing.T) {
192197
t.Parallel()
193198
t.Run("Enabled", func(t *testing.T) {
194199
t.Parallel()
195-
client, _, api := coderdenttest.NewWithAPI(t, nil)
200+
client, _, api := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
201+
AuditLogging: true,
202+
})
196203
coderdtest.CreateFirstUser(t, client)
197204
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
198205
AuditLog: true,
199206
})
200207
auditor := *api.AGPL.Auditor.Load()
201208
ea := audit.NewAuditor(audit.DefaultFilter)
202209
t.Logf("%T = %T", auditor, ea)
203-
assert.Equal(t, reflect.ValueOf(ea).Type(), reflect.ValueOf(auditor).Type())
210+
assert.EqualValues(t, reflect.ValueOf(ea).Type(), reflect.ValueOf(auditor).Type())
204211
})
205212
t.Run("Disabled", func(t *testing.T) {
206213
t.Parallel()

enterprise/coderd/coderdenttest/coderdenttest.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func init() {
3636

3737
type Options struct {
3838
*coderdtest.Options
39+
AuditLogging bool
3940
BrowserOnly bool
4041
EntitlementsUpdateInterval time.Duration
4142
SCIMAPIKey []byte
@@ -57,7 +58,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
5758
}
5859
srv, cancelFunc, oop := coderdtest.NewOptions(t, options.Options)
5960
coderAPI, err := coderd.New(context.Background(), &coderd.Options{
60-
AuditLogging: true,
61+
AuditLogging: options.AuditLogging,
6162
BrowserOnly: options.BrowserOnly,
6263
SCIMAPIKey: options.SCIMAPIKey,
6364
UserWorkspaceQuota: options.UserWorkspaceQuota,

0 commit comments

Comments
 (0)