Skip to content

fix: ensure the web UI doesn't break when license telemetry required check fails #16667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions coderd/entitlements/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,30 @@ func New() *Set {
// These will be updated when coderd is initialized.
entitlements: codersdk.Entitlements{
Features: map[codersdk.FeatureName]codersdk.Feature{},
Warnings: nil,
Errors: nil,
Warnings: []string{},
Errors: []string{},
HasLicense: false,
Trial: false,
RequireTelemetry: false,
RefreshedAt: time.Time{},
},
right2Update: make(chan struct{}, 1),
}
// Ensure all features are present in the entitlements. Our frontend
// expects this.
for _, featureName := range codersdk.FeatureNames {
s.entitlements.AddFeature(featureName, codersdk.Feature{
Entitlement: codersdk.EntitlementNotEntitled,
Enabled: false,
})
}
s.right2Update <- struct{}{} // one token, serialized updates
return s
}

// ErrLicenseRequiresTelemetry is an error returned by a fetch passed to Update to indicate that the
// fetched license cannot be used because it requires telemetry.
var ErrLicenseRequiresTelemetry = xerrors.New("License requires telemetry but telemetry is disabled")
var ErrLicenseRequiresTelemetry = xerrors.New(codersdk.LicenseTelemetryRequiredErrorText)

func (l *Set) Update(ctx context.Context, fetch func(context.Context) (codersdk.Entitlements, error)) error {
select {
Expand Down
3 changes: 2 additions & 1 deletion codersdk/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

const (
LicenseExpiryClaim = "license_expires"
LicenseExpiryClaim = "license_expires"
LicenseTelemetryRequiredErrorText = "License requires telemetry but telemetry is disabled"
)

type AddLicenseRequest struct {
Expand Down
4 changes: 4 additions & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions site/src/modules/dashboard/LicenseBanner/LicenseBannerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useTheme,
} from "@emotion/react";
import Link from "@mui/material/Link";
import { LicenseTelemetryRequiredErrorText } from "api/typesGenerated";
import { Expander } from "components/Expander/Expander";
import { Pill } from "components/Pill/Pill";
import { type FC, useState } from "react";
Expand All @@ -14,6 +15,7 @@ export const Language = {
licenseIssue: "License Issue",
licenseIssues: (num: number): string => `${num} License Issues`,
upgrade: "Contact sales@coder.com.",
exception: "Contact sales@coder.com if you need an exception.",
exceeded: "It looks like you've exceeded some limits of your license.",
lessDetails: "Less",
moreDetails: "More",
Expand All @@ -26,6 +28,14 @@ const styles = {
},
} satisfies Record<string, Interpolation<Theme>>;

const formatMessage = (message: string) => {
// If the message ends with an alphanumeric character, add a period.
if (/[a-z0-9]$/i.test(message)) {
return `${message}.`;
}
return message;
};

export interface LicenseBannerViewProps {
errors: readonly string[];
warnings: readonly string[];
Expand Down Expand Up @@ -57,14 +67,16 @@ export const LicenseBannerView: FC<LicenseBannerViewProps> = ({
<div css={containerStyles}>
<Pill type={type}>{Language.licenseIssue}</Pill>
<div css={styles.leftContent}>
<span>{messages[0]}</span>
<span>{formatMessage(messages[0])}</span>
&nbsp;
<Link
color={textColor}
fontWeight="medium"
href="mailto:sales@coder.com"
>
{Language.upgrade}
{messages[0] === LicenseTelemetryRequiredErrorText
? Language.exception
: Language.upgrade}
</Link>
</div>
</div>
Expand All @@ -90,7 +102,7 @@ export const LicenseBannerView: FC<LicenseBannerViewProps> = ({
<ul css={{ padding: 8, margin: 0 }}>
{messages.map((message) => (
<li css={{ margin: 4 }} key={message}>
{message}
{formatMessage(message)}
</li>
))}
</ul>
Expand Down
Loading