Skip to content

Commit 3da4645

Browse files
tmasternakWilliamBZAjohnsimons
authored
Using license extension URL from the ServiceControl API (#2108)
* using license extension url from the backend api * fix formatting * moar linter fixes * lint fixes * workaround the shared state between the tests * Update src/Frontend/test/preconditions/hasLicense.ts Co-authored-by: WilliamBZA <[email protected]> * Change license_extension_url to be nullable Co-authored-by: John Simons <[email protected]> --------- Co-authored-by: WilliamBZA <[email protected]> Co-authored-by: John Simons <[email protected]>
1 parent e1829ca commit 3da4645

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

src/Frontend/src/components/LicenseExpired.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { licenseStatus } from "../composables/serviceLicense";
2+
import { licenseStatus, license } from "../composables/serviceLicense";
33
import routeLinks from "@/router/routeLinks";
44
</script>
55

@@ -18,7 +18,7 @@ import routeLinks from "@/router/routeLinks";
1818
<h1>License expired</h1>
1919
<p>To continue using the Particular Service Platform, please extend your license</p>
2020
<div class="action-toolbar">
21-
<a class="btn btn-default btn-primary" href="https://particular.net/extend-your-trial?p=servicepulse" target="_blank">Extend your license <i class="fa fa-external-link"></i></a>
21+
<a class="btn btn-default btn-primary" :href="license.license_extension_url" target="_blank">Extend your license <i class="fa fa-external-link"></i></a>
2222
<RouterLink class="btn btn-default btn-secondary" :to="routeLinks.configuration.license.link">View license details</RouterLink>
2323
</div>
2424
</div>

src/Frontend/src/components/LicenseNotifications.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import routeLinks from "@/router/routeLinks";
88
import { useRouter } from "vue-router";
99
1010
const router = useRouter();
11+
const { license, getOrUpdateLicenseStatus } = useLicense();
1112
1213
function displayWarningMessage(licenseStatus: LicenseStatus) {
1314
const configurationRootLink = router.resolve(routeLinks.configuration.root).href;
@@ -18,7 +19,7 @@ function displayWarningMessage(licenseStatus: LicenseStatus) {
1819
break;
1920
}
2021
case "ValidWithExpiringTrial": {
21-
const trialExpiring = `<div><strong>Non-production development license expiring</strong><div>Your non-production development license will expire soon. To continue using the Particular Service Platform you'll need to extend your license.</div><a href="http://particular.net/extend-your-trial?p=servicepulse" class="btn btn-warning"><i class="fa fa-external-link-alt"></i> Extend your license</a><a href="${configurationRootLink}" class="btn btn-light">View license details</a></div>`;
22+
const trialExpiring = `<div><strong>Non-production development license expiring</strong><div>Your non-production development license will expire soon. To continue using the Particular Service Platform you'll need to extend your license.</div><a href="${license.license_extension_url}" class="btn btn-warning"><i class="fa fa-external-link-alt"></i> Extend your license</a><a href="${configurationRootLink}" class="btn btn-light">View license details</a></div>`;
2223
useShowToast(TYPE.WARNING, "", trialExpiring, true);
2324
break;
2425
}
@@ -40,8 +41,6 @@ function displayWarningMessage(licenseStatus: LicenseStatus) {
4041
}
4142
}
4243
43-
const { license, getOrUpdateLicenseStatus } = useLicense();
44-
4544
watch(
4645
() => license.license_status,
4746
(newValue, oldValue) => {

src/Frontend/src/components/configuration/PlatformLicense.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const loading = computed(() => {
6262
</span>
6363
<div class="license-expired-text" v-if="licenseStatus.isPlatformTrialExpired">Your license expired. To continue using the Particular Service Platform you'll need to extend your license.</div>
6464
<div class="license-page-extend-trial" v-if="licenseStatus.isPlatformTrialExpiring && licenseStatus.isPlatformTrialExpired">
65-
<a class="btn btn-default btn-primary" href="https://particular.net/extend-your-trial?p=servicepulse" target="_blank">Extend your license&nbsp;&nbsp;<i class="fa fa-external-link"></i></a>
65+
<a class="btn btn-default btn-primary" :href="license.license_extension_url" target="_blank">Extend your license&nbsp;&nbsp;<i class="fa fa-external-link"></i></a>
6666
</div>
6767
</div>
6868
</template>

src/Frontend/src/composables/serviceLicense.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const emptyLicense: License = {
2323
registered_to: "",
2424
status: "",
2525
license_status: LicenseStatus.Unavailable,
26+
license_extension_url: "",
2627
licenseEdition: computed(() => {
2728
return license.license_type && license.edition ? ", " + license.edition : "";
2829
}),
@@ -54,6 +55,7 @@ const licenseStatus = reactive({
5455
subscriptionDaysLeft: "",
5556
trialDaysLeft: "",
5657
warningLevel: LicenseWarningLevel.None,
58+
licenseExtensionUrl: "",
5759
});
5860

5961
function useLicense() {
@@ -70,6 +72,7 @@ async function getOrUpdateLicenseStatus() {
7072
license.instance_name = lic.instance_name;
7173
license.registered_to = lic.registered_to;
7274
license.status = lic.status;
75+
license.license_extension_url = lic.license_extension_url ?? "https://particular.net/extend-your-trial?p=servicepulse";
7376
license.upgrade_protection_expiration = lic.upgrade_protection_expiration;
7477

7578
licenseStatus.isSubscriptionLicense = isSubscriptionLicense(license);
@@ -86,6 +89,7 @@ async function getOrUpdateLicenseStatus() {
8689
licenseStatus.trialDaysLeft = getTrialDaysLeft(license);
8790
licenseStatus.warningLevel = getLicenseWarningLevel(license.license_status);
8891
licenseStatus.isExpired = licenseStatus.isPlatformExpired || licenseStatus.isPlatformTrialExpired || licenseStatus.isInvalidDueToUpgradeProtectionExpired;
92+
licenseStatus.licenseExtensionUrl = license.license_extension_url;
8993
}
9094

9195
export { useLicense, license, licenseStatus };
@@ -141,7 +145,7 @@ function getUpgradeDaysLeft(license: UnwrapNestedRefs<License>) {
141145

142146
async function getLicense() {
143147
try {
144-
const [, data] = await useTypedFetchFromServiceControl<LicenseInfo>("license?refresh=true");
148+
const [, data] = await useTypedFetchFromServiceControl<LicenseInfo>("license?refresh=true&clientName=servicepulse");
145149
return data;
146150
} catch (err) {
147151
console.log(err);

src/Frontend/src/resources/LicenseInfo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default interface LicenseInfo {
77
instance_name: string;
88
trial_license: boolean;
99
license_status: LicenseStatus;
10+
license_extension_url?: string;
1011
status: string;
1112
}
1213

src/Frontend/test/preconditions/hasLicense.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { activeLicenseResponse } from "../mocks/license-response-template";
22
import { SetupFactoryOptions } from "../driver";
33
import LicenseInfo, { LicenseStatus } from "@/resources/LicenseInfo";
4+
import { useLicense } from "@/composables/serviceLicense";
5+
6+
const { license } = useLicense();
47

58
export const hasActiveLicense = ({ driver }: SetupFactoryOptions) => {
69
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
@@ -16,11 +19,11 @@ export enum LicenseType {
1619
UpgradeProtection,
1720
}
1821

19-
export const hasExpiredLicense = (licenseType: LicenseType) => createLicenseMockedResponse(licenseType, false);
20-
export const hasExpiringLicense = (licenseType: LicenseType) => createLicenseMockedResponse(licenseType, true);
22+
export const hasExpiredLicense = (licenseType: LicenseType, licenseExtensionUrl: string = "https://particular.net/extend-your-trial?p=servicepulse") => createLicenseMockedResponse(licenseType, false, licenseExtensionUrl);
23+
export const hasExpiringLicense = (licenseType: LicenseType, licenseExtensionUrl: string = "https://particular.net/extend-your-trial?p=servicepulse") => createLicenseMockedResponse(licenseType, true, licenseExtensionUrl);
2124

2225
const createLicenseMockedResponse =
23-
(liceseType: LicenseType, expiring = false) =>
26+
(liceseType: LicenseType, expiring = false, licenseExtensionUrl: string) =>
2427
({ driver }: SetupFactoryOptions) => {
2528
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
2629
let status: LicenseStatus;
@@ -37,6 +40,9 @@ const createLicenseMockedResponse =
3740
break;
3841
}
3942

43+
//We need to reset the global state to ensure the warning toast is always triggered by the value changing between multiple test runs. See documented issue and proposed solution https://github.com/Particular/ServicePulse/issues/1905
44+
license.license_status = LicenseStatus.Unavailable;
45+
4046
driver.mockEndpoint(`${serviceControlInstanceUrl}license`, {
4147
body: <LicenseInfo>{
4248
registered_to: "ACME Software",
@@ -47,6 +53,7 @@ const createLicenseMockedResponse =
4753
instance_name: "Particular.ServiceControl",
4854
trial_license: status === LicenseStatus.ValidWithExpiringTrial || status === LicenseStatus.InvalidDueToExpiredTrial,
4955
license_status: status,
56+
license_extension_url: licenseExtensionUrl,
5057
},
5158
});
5259
};

src/Frontend/test/specs/licensing/license-enforcement.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ import { getAlertNotifications } from "./questions/alertNotifications";
88

99
describe("FEATURE: EXPIRING license detection", () => {
1010
describe("RULE: The user should be alerted while using the monitoring endpoint list functionality about an EXPIRING license", () => {
11-
test("EXAMPLE: Expiring trial", async ({ driver }) => {
12-
//Arrange
13-
await driver.setUp(precondition.serviceControlWithMonitoring);
14-
await driver.setUp(precondition.hasExpiringLicense(precondition.LicenseType.Trial));
11+
[{ licenseExtensionUrl: "https://particular.net/extend-your-trial?p=servicepulse" }, { licenseExtensionUrl: "http://custom-url?with-parts=value1" }].forEach(({ licenseExtensionUrl }) => {
12+
test(`EXAMPLE: Expiring trial with ${licenseExtensionUrl} as license extension url `, async ({ driver }) => {
13+
//Arrange
14+
await driver.setUp(precondition.serviceControlWithMonitoring);
15+
await driver.setUp(precondition.hasExpiringLicense(precondition.LicenseType.Trial, licenseExtensionUrl));
1516

16-
await driver.goTo("monitoring");
17+
await driver.goTo("monitoring");
1718

18-
const notification = (await getAlertNotifications()).find((n) => n.textMatches(/your non-production development license will expire soon\. to continue using the particular service platform you'll need to extend your license\./i));
19+
const notification = (await getAlertNotifications()).find((n) => n.textMatches(/your non-production development license will expire soon\. to continue using the particular service platform you'll need to extend your license\./i));
1920

20-
expect(notification).not.toBeUndefined();
21-
expect(notification?.hasLink({ caption: "Extend your license", address: "http://particular.net/extend-your-trial?p=servicepulse" })).toBeTruthy();
22-
expect(notification?.hasLink({ caption: "View license details", address: "#/configuration" })).toBeTruthy();
21+
expect(notification).not.toBeUndefined();
22+
expect(notification?.hasLink({ caption: "Extend your license", address: licenseExtensionUrl })).toBeTruthy();
23+
expect(notification?.hasLink({ caption: "View license details", address: "#/configuration" })).toBeTruthy();
24+
});
2325
});
2426

2527
[

0 commit comments

Comments
 (0)