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

feat: add expiration warning#7264

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rodrimaia merged 6 commits intomainfromadd_expiration_warning
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionsenterprise/coderd/coderd_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,7 @@ func TestEntitlements(t *testing.T) {
codersdk.FeatureAdvancedTemplateScheduling: 1,
codersdk.FeatureWorkspaceProxy: 1,
},
GraceAt: time.Now().Add(59 * 24 * time.Hour),
})
res, err := client.Entitlements(context.Background())
require.NoError(t, err)
Expand Down
18 changes: 18 additions & 0 deletionsenterprise/coderd/license/license.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import (
"context"
"crypto/ed25519"
"fmt"
"math"
"time"

"github.com/golang-jwt/jwt/v4"
Expand DownExpand Up@@ -70,6 +71,23 @@ func Entitlements(
// LicenseExpires we must be in grace period.
entitlement = codersdk.EntitlementGracePeriod
}

// Add warning if license is expiring soon
daysToExpire := int(math.Ceil(claims.LicenseExpires.Sub(now).Hours() / 24))
isTrial := entitlements.Trial
showWarningDays := 30
if isTrial {
showWarningDays = 7
}
isExpiringSoon := daysToExpire > 0 && daysToExpire < showWarningDays
if isExpiringSoon {
day := "day"
if daysToExpire > 1 {
day = "days"
}
entitlements.Warnings = append(entitlements.Warnings, fmt.Sprintf("Your license expires in %d %s.", daysToExpire, day))
}

for featureName, featureValue := range claims.Features {
// Can this be negative?
if featureValue <= 0 {
Expand Down
123 changes: 121 additions & 2 deletionsenterprise/coderd/license/license_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,123 @@ func TestEntitlements(t *testing.T) {
fmt.Sprintf("%s is enabled but your license for this feature is expired.", codersdk.FeatureAuditLog.Humanize()),
)
})
t.Run("Expiration warning", func(t *testing.T) {
t.Parallel()
db := dbfake.New()
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureUserLimit: 100,
codersdk.FeatureAuditLog: 1,
},

GraceAt: time.Now().AddDate(0, 0, 2),
ExpiresAt: time.Now().AddDate(0, 0, 5),
}),
Exp: time.Now().AddDate(0, 0, 5),
})

entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, all)

require.NoError(t, err)
require.True(t, entitlements.HasLicense)
require.False(t, entitlements.Trial)

require.Equal(t, codersdk.EntitlementEntitled, entitlements.Features[codersdk.FeatureAuditLog].Entitlement)
require.Contains(
t, entitlements.Warnings,
"Your license expires in 2 days.",
)
})

t.Run("Expiration warning for license expiring in 1 day", func(t *testing.T) {
t.Parallel()
db := dbfake.New()
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureUserLimit: 100,
codersdk.FeatureAuditLog: 1,
},

GraceAt: time.Now().AddDate(0, 0, 1),
ExpiresAt: time.Now().AddDate(0, 0, 5),
}),
Exp: time.Now().AddDate(0, 0, 5),
})

entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, all)

require.NoError(t, err)
require.True(t, entitlements.HasLicense)
require.False(t, entitlements.Trial)

require.Equal(t, codersdk.EntitlementEntitled, entitlements.Features[codersdk.FeatureAuditLog].Entitlement)
require.Contains(
t, entitlements.Warnings,
"Your license expires in 1 day.",
)
})

t.Run("Expiration warning for trials", func(t *testing.T) {
t.Parallel()
db := dbfake.New()
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureUserLimit: 100,
codersdk.FeatureAuditLog: 1,
},

Trial: true,
GraceAt: time.Now().AddDate(0, 0, 8),
ExpiresAt: time.Now().AddDate(0, 0, 5),
}),
Exp: time.Now().AddDate(0, 0, 5),
})

entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, all)

require.NoError(t, err)
require.True(t, entitlements.HasLicense)
require.True(t, entitlements.Trial)

require.Equal(t, codersdk.EntitlementEntitled, entitlements.Features[codersdk.FeatureAuditLog].Entitlement)
require.NotContains( // it should not contain a warning since it is a trial license
t, entitlements.Warnings,
"Your license expires in 8 days.",
)
})

t.Run("Expiration warning for non trials", func(t *testing.T) {
t.Parallel()
db := dbfake.New()
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureUserLimit: 100,
codersdk.FeatureAuditLog: 1,
},

GraceAt: time.Now().AddDate(0, 0, 30),
ExpiresAt: time.Now().AddDate(0, 0, 5),
}),
Exp: time.Now().AddDate(0, 0, 5),
})

entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, all)

require.NoError(t, err)
require.True(t, entitlements.HasLicense)
require.False(t, entitlements.Trial)

require.Equal(t, codersdk.EntitlementEntitled, entitlements.Features[codersdk.FeatureAuditLog].Entitlement)
require.NotContains( // it should not contain a warning since it is a trial license
t, entitlements.Warnings,
"Your license expires in 30 days.",
)
})

t.Run("SingleLicenseNotEntitled", func(t *testing.T) {
t.Parallel()
db := dbfake.New()
Expand DownExpand Up@@ -164,16 +281,18 @@ func TestEntitlements(t *testing.T) {
Features: license.Features{
codersdk.FeatureUserLimit: 10,
},
GraceAt: time.Now().Add(59 * 24 * time.Hour),
}),
Exp: time.Now().Add(time.Hour),
Exp: time.Now().Add(60 * 24 *time.Hour),
})
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureUserLimit: 1,
},
GraceAt: time.Now().Add(59 * 24 * time.Hour),
}),
Exp: time.Now().Add(time.Hour),
Exp: time.Now().Add(60 * 24 *time.Hour),
})
entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, empty)
require.NoError(t, err)
Expand Down
4 changes: 3 additions & 1 deletionsite/src/components/Dashboard/DashboardLayout.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,10 +25,12 @@ export const DashboardLayout: FC = () => {
})
const { error: updateCheckError, updateCheck } = updateCheckState.context

const canViewDeployment = Boolean(permissions.viewDeploymentValues)

return (
<DashboardProvider>
<ServiceBanner />
<LicenseBanner />
{canViewDeployment &&<LicenseBanner />}

<div className={styles.site}>
<Navbar />
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp