fix: improve license key ui (#4220)

* fix: improve license key ui

* fix: stop schedules on key expiration

* update ee ref
This commit is contained in:
HugoCasa
2024-08-11 01:01:24 +02:00
committed by GitHub
parent fd0626e230
commit e46c2ea513
4 changed files with 58 additions and 10 deletions
+1 -1
View File
@@ -1 +1 @@
9431876ca4dd2ce51a04b102557daa9f685dc5d5
80d9e507977b55d0b76272905c969c3d6e830083
+12
View File
@@ -845,6 +845,12 @@ paths:
operationId: renewLicenseKey
tags:
- setting
parameters:
- name: license_key
in: query
required: false
schema:
type: string
responses:
"200":
description: status
@@ -859,6 +865,12 @@ paths:
operationId: createCustomerPortalSession
tags:
- setting
parameters:
- name: license_key
in: query
required: false
schema:
type: string
responses:
"200":
description: url to portal
+8
View File
@@ -14,6 +14,7 @@ use sqlx::{query_scalar, Postgres, Transaction};
use std::collections::HashMap;
use std::str::FromStr;
use windmill_common::db::Authed;
use windmill_common::ee::LICENSE_KEY_VALID;
use windmill_common::flows::Retry;
use windmill_common::jobs::JobPayload;
use windmill_common::schedule::schedule_to_user;
@@ -31,6 +32,13 @@ pub async fn push_scheduled_job<'c, R: rsmq_async::RsmqConnection + Send + 'c>(
schedule: &Schedule,
authed: Option<&Authed>,
) -> Result<QueueTransaction<'c, R>> {
if !*LICENSE_KEY_VALID.read().await {
return Err(error::Error::BadRequest(
"License key is not valid. Go to your superadmin settings to update your license key."
.to_string(),
));
}
let sched = cron::Schedule::from_str(schedule.schedule.as_ref())
.map_err(|e| error::Error::BadRequest(e.to_string()))?;
@@ -144,16 +144,27 @@
let resourceName = ''
function parseDate(license_key: string): string | undefined {
let splitted = license_key.split('.')
function parseLicenseKey(key: string): {
valid: boolean
expiration?: string
} {
let splitted = key.split('.')
if (splitted.length >= 3) {
try {
let i = parseInt(splitted[1])
let date = new Date(i * 1000)
return date.toLocaleDateString()
const stringDate = date.toLocaleDateString()
if (stringDate !== 'Invalid Date') {
return {
valid: date.getTime() > Date.now(),
expiration: date.toLocaleDateString()
}
}
} catch {}
}
return undefined
return {
valid: false
}
}
let to: string = ''
@@ -191,7 +202,9 @@
export async function renewLicenseKey() {
renewing = true
try {
await SettingService.renewLicenseKey()
await SettingService.renewLicenseKey({
licenseKey: values['license_key'] || undefined
})
sendUserToast('Key renewal successful')
loadSettings()
} catch (err) {
@@ -206,7 +219,9 @@
export async function openCustomerPortal() {
opening = true
try {
const url = await SettingService.createCustomerPortalSession()
const url = await SettingService.createCustomerPortalSession({
licenseKey: values['license_key'] || undefined
})
window.open(url, '_blank')
} finally {
opening = false
@@ -492,6 +507,7 @@
</div>
{/if}
{:else if setting.fieldType == 'license_key'}
{@const { valid, expiration } = parseLicenseKey(values[setting.key] ?? '')}
<div class="flex gap-2">
<Password
small
@@ -516,13 +532,25 @@
</div>
<div class="mt-1 flex flex-col gap-1 items-start">
{#if values[setting.key]?.length > 0}
{#if parseDate(values[setting.key])}
{#if valid}
<div class="flex flex-row gap-1 items-center">
<Info size={12} class="text-tertiary" />
<span class="text-tertiary text-xs"
>License key expires on {parseDate(values[setting.key])}</span
>License key expires on {expiration ?? ''}</span
>
</div>
{:else if expiration}
<div class="flex flex-row gap-1 items-center">
<AlertCircle size={12} class="text-red-600" />
<span class="text-red-600 text-xs"
>License key expired on {expiration}</span
>
</div>
{:else}
<div class="flex flex-row gap-1 items-center">
<AlertCircle size={12} class="text-red-600" />
<span class="text-red-600 text-xs">Invalid license key format</span>
</div>
{/if}
{/if}
{#if latestKeyRenewalAttempt}
@@ -581,7 +609,7 @@
</div>
{/if}
{#if $enterpriseLicense}
{#if valid || expiration}
<div class="flex flex-row gap-2 mt-1">
<Button
on:click={renewLicenseKey}