Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac88c9b

Browse files
authored
fix: ensure the web UI doesn't break when license telemetry required check fails (#16667)
Addresses#16455.## Changes- Initialize default entitlements in a Set to include all features- Initialize entitlements' `Warnings` and `Errors` fields to arraysrather than `nil`s.- Minor changes in formatting on the frontend## ReasoningI had to change how entitlements are initialized to match the `codersdk`[generatedtypes](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/site/src/api/typesGenerated.ts#L727),which the frontend assumes are correct, and doesn't run additionalchecks on.- `features: Record<FeatureName, Feature>`: this type signifies thatevery `FeatureName` is present in the record, but on `main`, that's nottrue if there's a telemetry required error- `warnings: readonly string[];` and `errors: readonly string[];`: thesetypes mean that the fields are not `null`, but that's not always trueWith a valid license, the [`LicensesEntitlements`function](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/license/license.go#L92)ensures that all features are present in the entitlements. It's calledby the [`Entitlements`function](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/license/license.go#L42),which is called by[`api.updateEnittlements`](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/coderd.go#L687).However, when a license requires telemetry and telemetry is disabled,the entitlements with all features [arediscarded](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/coderd.go#L704)in an early exit from the same function. By initializing entitlementswith all the features from the get go, we avoid this problem.## License issue banner after the changes<img width="1512" alt="Screenshot 2025-02-23 at 20 25 42"src="https://github.com/user-attachments/assets/ee0134b3-f745-45d9-8333-bfa1661e33d2"/>
1 parentbebf2d5 commitac88c9b

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

‎coderd/entitlements/entitlements.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,30 @@ func New() *Set {
3030
// These will be updated when coderd is initialized.
3131
entitlements: codersdk.Entitlements{
3232
Features:map[codersdk.FeatureName]codersdk.Feature{},
33-
Warnings:nil,
34-
Errors:nil,
33+
Warnings:[]string{},
34+
Errors:[]string{},
3535
HasLicense:false,
3636
Trial:false,
3737
RequireTelemetry:false,
3838
RefreshedAt: time.Time{},
3939
},
4040
right2Update:make(chanstruct{},1),
4141
}
42+
// Ensure all features are present in the entitlements. Our frontend
43+
// expects this.
44+
for_,featureName:=rangecodersdk.FeatureNames {
45+
s.entitlements.AddFeature(featureName, codersdk.Feature{
46+
Entitlement:codersdk.EntitlementNotEntitled,
47+
Enabled:false,
48+
})
49+
}
4250
s.right2Update<-struct{}{}// one token, serialized updates
4351
returns
4452
}
4553

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

5058
func (l*Set)Update(ctx context.Context,fetchfunc(context.Context) (codersdk.Entitlements,error))error {
5159
select {

‎codersdk/licenses.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
)
1313

1414
const (
15-
LicenseExpiryClaim="license_expires"
15+
LicenseExpiryClaim="license_expires"
16+
LicenseTelemetryRequiredErrorText="License requires telemetry but telemetry is disabled"
1617
)
1718

1819
typeAddLicenseRequeststruct {

‎site/src/api/typesGenerated.ts

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎site/src/modules/dashboard/LicenseBanner/LicenseBannerView.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
useTheme,
77
}from"@emotion/react";
88
importLinkfrom"@mui/material/Link";
9+
import{LicenseTelemetryRequiredErrorText}from"api/typesGenerated";
910
import{Expander}from"components/Expander/Expander";
1011
import{Pill}from"components/Pill/Pill";
1112
import{typeFC,useState}from"react";
@@ -14,6 +15,7 @@ export const Language = {
1415
licenseIssue:"License Issue",
1516
licenseIssues:(num:number):string=>`${num} License Issues`,
1617
upgrade:"Contact sales@coder.com.",
18+
exception:"Contact sales@coder.com if you need an exception.",
1719
exceeded:"It looks like you've exceeded some limits of your license.",
1820
lessDetails:"Less",
1921
moreDetails:"More",
@@ -26,6 +28,14 @@ const styles = {
2628
},
2729
}satisfiesRecord<string,Interpolation<Theme>>;
2830

31+
constformatMessage=(message:string)=>{
32+
// If the message ends with an alphanumeric character, add a period.
33+
if(/[a-z0-9]$/i.test(message)){
34+
return`${message}.`;
35+
}
36+
returnmessage;
37+
};
38+
2939
exportinterfaceLicenseBannerViewProps{
3040
errors:readonlystring[];
3141
warnings:readonlystring[];
@@ -57,14 +67,16 @@ export const LicenseBannerView: FC<LicenseBannerViewProps> = ({
5767
<divcss={containerStyles}>
5868
<Pilltype={type}>{Language.licenseIssue}</Pill>
5969
<divcss={styles.leftContent}>
60-
<span>{messages[0]}</span>
70+
<span>{formatMessage(messages[0])}</span>
6171
&nbsp;
6272
<Link
6373
color={textColor}
6474
fontWeight="medium"
6575
href="mailto:sales@coder.com"
6676
>
67-
{Language.upgrade}
77+
{messages[0]===LicenseTelemetryRequiredErrorText
78+
?Language.exception
79+
:Language.upgrade}
6880
</Link>
6981
</div>
7082
</div>
@@ -90,7 +102,7 @@ export const LicenseBannerView: FC<LicenseBannerViewProps> = ({
90102
<ulcss={{padding:8,margin:0}}>
91103
{messages.map((message)=>(
92104
<licss={{margin:4}}key={message}>
93-
{message}
105+
{formatMessage(message)}
94106
</li>
95107
))}
96108
</ul>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp