-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #898 from intuitem/CA-471-implement-license-expira…
…tion Ca 471 implement license expiration
- Loading branch information
Showing
18 changed files
with
180 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
from datetime import datetime | ||
|
||
import structlog | ||
from rest_framework import permissions | ||
|
||
logger = structlog.get_logger(__name__) | ||
|
||
|
||
class LicensePermission(permissions.BasePermission): | ||
def has_permission(self, request, view): | ||
expiration_date_str = os.environ.get("LICENSE_EXPIRATION") | ||
|
||
if not expiration_date_str: | ||
# Handle the case where no expiration date is set | ||
logger.warning("License expiration date is not set.") | ||
return True | ||
|
||
try: | ||
expiration_date = datetime.fromisoformat(expiration_date_str) | ||
except ValueError: | ||
logger.error( | ||
"Invalid expiration date format. Expiration date should follow ISO 8601 format.", | ||
expiration_date=expiration_date_str, | ||
) | ||
return False | ||
|
||
if expiration_date < datetime.now(): | ||
# License has expired, only allow read operations | ||
if request.method not in permissions.SAFE_METHODS: | ||
logger.warning( | ||
"License has expired, only read operations are allowed.", | ||
expiration_date=expiration_date, | ||
) | ||
return False | ||
|
||
# License is valid, allow all operations | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from django.urls import include, path | ||
|
||
|
||
from .views import get_build | ||
from .views import LicenseStatusView, get_build | ||
|
||
urlpatterns = [ | ||
path("build/", get_build, name="get_build"), | ||
path("license-status/", LicenseStatusView.as_view(), name="license-status"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<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'; | ||
import { browser } from '$app/environment'; | ||
import Breadcrumbs from '$lib/components/Breadcrumbs/Breadcrumbs.svelte'; | ||
import SideBar from '$lib/components/SideBar/SideBar.svelte'; | ||
import { deleteCookie, getCookie } from '$lib/utils/cookies'; | ||
import { clientSideToast, pageTitle } from '$lib/utils/stores'; | ||
import * as m from '$paraglide/messages'; | ||
import type { LayoutData } from './$types'; | ||
export let data: LayoutData; | ||
let sidebarOpen = true; | ||
$: classesSidebarOpen = (open: boolean) => (open ? 'ml-64' : 'ml-7'); | ||
$: if (browser) { | ||
const fromLogin = getCookie('from_login'); | ||
if (fromLogin === 'true') { | ||
deleteCookie('from_login'); | ||
fetch('/api/waiting-risk-acceptances').then(async (res) => { | ||
const data = await res.json(); | ||
const number = data.count ?? 0; | ||
if (number <= 0) return; | ||
clientSideToast.set({ | ||
message: m.waitingRiskAcceptances({ | ||
number: number, | ||
s: number > 1 ? 's' : '', | ||
itPlural: number > 1 ? 'i' : 'e' | ||
}), | ||
type: 'info' | ||
}); | ||
}); | ||
} | ||
} | ||
</script> | ||
|
||
<!-- App Shell --> | ||
<AppShell | ||
slotPageContent="p-8 bg-gradient-to-br from-violet-100 to-slate-200" | ||
regionPage="transition-all duration-300 {classesSidebarOpen(sidebarOpen)}" | ||
> | ||
<svelte:fragment slot="sidebarLeft"> | ||
<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"> | ||
{m.licenseExpiredMessage()} | ||
</aside> | ||
{/if} | ||
<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" | ||
id="page-title" | ||
> | ||
{safeTranslate($pageTitle)} | ||
</span> | ||
<hr class="w-screen my-1" /> | ||
<Breadcrumbs /> | ||
</AppBar> | ||
</svelte:fragment> | ||
<!-- Router Slot --> | ||
<slot /> | ||
<!-- ---- / ---- --> | ||
</AppShell> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import type { LayoutServerLoad } from './$types'; | ||
import type { GlobalSettings } from '$lib/utils/types'; | ||
import { BASE_API_URL } from '$lib/utils/constants'; | ||
|
||
export const load: LayoutServerLoad = async ({ fetch, locals }) => { | ||
let clientSettings: GlobalSettings; | ||
if (!locals.globalSettings) { | ||
const _settings = await fetch('/settings/client-settings').then((res) => res.json()); | ||
clientSettings = { name: 'clientSettings', settings: _settings }; | ||
} else clientSettings = locals.globalSettings; | ||
const licenseStatus = await fetch(`${BASE_API_URL}/license-status/`).then(res => res.json()) | ||
if (!locals.user && clientSettings.settings.show_images_unauthenticated !== true) { | ||
clientSettings.settings.logo = ''; | ||
clientSettings.settings.favicon = ''; | ||
clientSettings.settings.logo_hash = ''; | ||
clientSettings.settings.favicon_hash = ''; | ||
} | ||
return { featureFlags: locals.featureFlags, clientSettings }; | ||
return { featureFlags: locals.featureFlags, clientSettings, licenseStatus }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters