From e46c2ea51302b8c883ebfee814b0a51021cb2003 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Sun, 11 Aug 2024 01:01:24 +0200 Subject: [PATCH] fix: improve license key ui (#4220) * fix: improve license key ui * fix: stop schedules on key expiration * update ee ref --- backend/ee-repo-ref.txt | 2 +- backend/windmill-api/openapi.yaml | 12 +++++ backend/windmill-queue/src/schedule.rs | 8 ++++ .../lib/components/InstanceSettings.svelte | 46 +++++++++++++++---- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 5e59225745..67c39c95b6 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -9431876ca4dd2ce51a04b102557daa9f685dc5d5 \ No newline at end of file +80d9e507977b55d0b76272905c969c3d6e830083 \ No newline at end of file diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 3e5ac823f2..6e3a0fa543 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -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 diff --git a/backend/windmill-queue/src/schedule.rs b/backend/windmill-queue/src/schedule.rs index e1940708b3..aacfa87c10 100644 --- a/backend/windmill-queue/src/schedule.rs +++ b/backend/windmill-queue/src/schedule.rs @@ -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> { + 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()))?; diff --git a/frontend/src/lib/components/InstanceSettings.svelte b/frontend/src/lib/components/InstanceSettings.svelte index 2155da32e0..4d81ccad68 100644 --- a/frontend/src/lib/components/InstanceSettings.svelte +++ b/frontend/src/lib/components/InstanceSettings.svelte @@ -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 @@ {/if} {:else if setting.fieldType == 'license_key'} + {@const { valid, expiration } = parseLicenseKey(values[setting.key] ?? '')}
{#if values[setting.key]?.length > 0} - {#if parseDate(values[setting.key])} + {#if valid}
License key expires on {parseDate(values[setting.key])}License key expires on {expiration ?? ''}
+ {:else if expiration} +
+ + License key expired on {expiration} +
+ {:else} +
+ + Invalid license key format +
{/if} {/if} {#if latestKeyRenewalAttempt} @@ -581,7 +609,7 @@
{/if} - {#if $enterpriseLicense} + {#if valid || expiration}