Skip to content

Commit

Permalink
display toast on login when license is nearing expiration (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche authored Nov 25, 2024
2 parents 02ae654 + 3fae532 commit 2f8d756
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
17 changes: 12 additions & 5 deletions enterprise/frontend/src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
// Most of your app wide CSS should be put in this file
import { safeTranslate } from '$lib/utils/i18n';
import { AppBar, AppShell } from '@skeletonlabs/skeleton';
import '../../app.postcss';
Expand Down Expand Up @@ -37,6 +36,12 @@
});
}
}
const licenseExpirationNotifyDays = data.LICENSE_EXPIRATION_NOTIFY_DAYS;
const licenseStatus: Record<string, any> = data.licenseStatus;
const licenseAboutToExpire =
licenseStatus?.status === 'active' && licenseStatus?.days_left <= licenseExpirationNotifyDays;
</script>

<!-- App Shell -->
Expand All @@ -48,11 +53,13 @@
<SideBar bind:open={sidebarOpen} />
</svelte:fragment>
<svelte:fragment slot="pageHeader">
{#if data.licenseStatus.status === 'expired'}
<aside class="variant-soft-warning text-center w-full items-center py-2">
<aside class="variant-soft-warning text-center w-full items-center py-2">
{#if data.licenseStatus.status === 'expired'}
{m.licenseExpiredMessage()}
</aside>
{/if}
{:else if licenseAboutToExpire}
{m.licenseAboutToExpireWarning({ days_left: licenseStatus.days_left })}
{/if}
</aside>
<AppBar background="bg-white" padding="py-2 px-4">
<span
class="text-2xl font-bold pb-1 bg-gradient-to-r from-pink-500 to-violet-600 bg-clip-text text-transparent"
Expand Down
6 changes: 5 additions & 1 deletion enterprise/frontend/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LayoutServerLoad } from './$types';
import type { GlobalSettings } from '$lib/utils/types';
import { BASE_API_URL } from '$lib/utils/constants';
import { env } from '$env/dynamic/public';

export const load: LayoutServerLoad = async ({ fetch, locals }) => {
let clientSettings: GlobalSettings;
Expand All @@ -16,5 +17,8 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => {
clientSettings.settings.favicon_hash = '';
clientSettings.settings.name = '';
}
return { featureFlags: locals.featureFlags, clientSettings, licenseStatus };
const LICENSE_EXPIRATION_NOTIFY_DAYS = Object.hasOwn(env, 'PUBLIC_LICENSE_EXPIRATION_NOTIFY_DAYS')
? env.PUBLIC_LICENSE_EXPIRATION_NOTIFY_DAYS
: 7;
return { featureFlags: locals.featureFlags, clientSettings, licenseStatus, LICENSE_EXPIRATION_NOTIFY_DAYS };
};
1 change: 1 addition & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@
"questionPlural": "Questions",
"fillMetadataURL": "Option 1: Fill the metadata url",
"fillSSOSLOURLx509cert": "Option 2: Fill the SSO URL, SLO URL and x509cert",
"licenseAboutToExpireWarning": "You have only {days_left} days before the end of your license.",
"proof": "Proof",
"privacy": "Privacy",
"safety": "Safety",
Expand Down
1 change: 1 addition & 0 deletions frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@
"questionPlural": "Questions",
"fillMetadataURL": "Option 1 : Remplissez l'URL des métadonnées",
"fillSSOSLOURLx509cert": "Option 2 : Remplissez l'URL SSO, l'URL SLO et le certificat x509",
"licenseAboutToExpireWarning": "Il reste {days_left} jours avant l'expiration de votre licence.",
"noExpirationDateSet": "Aucune date d'expiration définie",
"sumpageTotal": "total",
"sumpageActive": "actif",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/ModelTable/ModelTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
const user = $page.data.user;
$: canCreateObject = Object.hasOwn(user.permissions, `add_${model?.name}`);
$: canCreateObject = user?.permissions && Object.hasOwn(user.permissions, `add_${model?.name}`);
import { URL_MODEL_MAP } from '$lib/utils/crud';
import { listViewFields } from '$lib/utils/table';
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/lib/components/SideBar/SideBarNavigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
// Check and filter the sub-items based on user permissions
const filteredSubItems = item.items.filter((subItem) => {
if (subItem.exclude) {
return subItem.exclude.some((role) => !user.roles.includes(role));
return subItem.exclude.some((role) => user?.roles && !user.roles.includes(role));
} else if (subItem.permissions) {
return subItem.permissions.some((permission) =>
Object.hasOwn(user.permissions, permission)
return subItem.permissions?.some(
(permission) => user?.permissions && Object.hasOwn(user.permissions, permission)
);
} else if (Object.hasOwn(URL_MODEL_MAP, subItem.href.split('/')[1])) {
const model = URL_MODEL_MAP[subItem.href.split('/')[1]];
const canViewObject = Object.hasOwn(user.permissions, `view_${model.name}`);
const canViewObject =
user?.permissions && Object.hasOwn(user.permissions, `view_${model.name}`);
return canViewObject;
}
return false;
Expand Down

0 comments on commit 2f8d756

Please sign in to comment.