Skip to content

Commit

Permalink
Add more fixes for endpoint /public/certificates (#460)
Browse files Browse the repository at this point in the history
* Add path check for endpoint /public/certificates

* Add redirect from start page to cloud page if already logged in

* Show empty message if no certificate exists
  • Loading branch information
anatheka authored Jul 18, 2023
1 parent bcf0673 commit 60af6e7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
63 changes: 30 additions & 33 deletions src/lib/Navigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,38 @@ function handleUpdate(event) {
isOpen = event.detail.isOpen;
}
let routes = [
{
url: '/cloud',
name: 'Cloud Services'
},
// We are hiding these paths for MEDINA, since they can be viewed on the service-specific views
// {
// url: '/discovery',
// name: 'Discovery'
// },
// {
// url: '/assessment',
// name: 'Assessment'
// },
{
url: '/metrics',
name: 'Metrics'
},
{
url: '/catalogs',
name: 'Catalogues'
},
{
url: '/certificates',
name: 'Certificates'
},
{
name: 'Help'
}
];
// let routes = [
// {
// url: '/cloud',
// name: 'Cloud Services'
// },
// // We are hiding these paths for MEDINA, since they can be viewed on the service-specific views
// // {
// // url: '/discovery',
// // name: 'Discovery'
// // },
// // {
// // url: '/assessment',
// // name: 'Assessment'
// // },
// {
// url: '/metrics',
// name: 'Metrics'
// },
// {
// url: '/catalogs',
// name: 'Catalogues'
// },
// {
// url: '/certificates',
// name: 'Certificates'
// },
// {
// name: 'Help'
// }
// ];
let loggedIn = localStorage.token ? true : false;
console.log($page.url);
</script>

<SvelteToast />
Expand Down Expand Up @@ -96,7 +94,6 @@ console.log($page.url);
<NavLink href="{base}/login">Login</NavLink>
</NavItem>
{/if}

<NavItem>
<NavLink href="https://medina-project.eu/wp-content/uploads/MEDINA_User_Manuals/MEDINA_Orchestrator_UserManual.pdf" target="_blank">
<Fa icon={faQuestion} /> Help
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function getVersionMessage(): string {
<Navigation />

<main>
<slot />
<slot />
</main>

<Button color="secondary" on:click={() => toggle()}>
Expand Down
14 changes: 9 additions & 5 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { getRuntimeInfo, listCatalogs, listControls, listMetrics } from "$lib/or
import { metrics, controls } from "$lib/stores";
import type { LayoutLoad } from "./$types";

export const load: LayoutLoad = async ({ fetch }) => {
export const load: LayoutLoad = async ({ fetch, url}) => {

// If the the path '/public/certificates' was called, we return here without calling the other endpoints.
if (url.pathname == "/public/certificates") {
console.info("public certificates endpoint called: ignore further load functionality")
return
}

// Since we want a map for convenience, we need to use a store, rather than
// exposing the metric through a layout data props. Layout data props need
// to be JSON and thus, a real ES6 map cannot be used.
Expand All @@ -16,7 +23,6 @@ export const load: LayoutLoad = async ({ fetch }) => {
.catch(() => {
// ignore, we will catch it later
console.error("error getting metrics")
return
});

listControls(null, null, fetch).then((list) => {
Expand All @@ -25,7 +31,6 @@ export const load: LayoutLoad = async ({ fetch }) => {
.catch(() => {
// ignore, we will catch it later
console.error("error getting controls")
return
});

try {
Expand All @@ -39,8 +44,7 @@ export const load: LayoutLoad = async ({ fetch }) => {
}
} catch (error) {
console.warn("error start page load function")
return
// return redirectLogin('/cloud');
return redirectLogin('/cloud');
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script lang="ts">
import { redirectLogin } from "$lib/oauth";
</script>

{redirectLogin('/cloud')}
2 changes: 1 addition & 1 deletion src/routes/public/certificates/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<h3>Certificates</h3>

{#if certificates}
{#if certificates.length > 0}
<Container class="mt-4 ms-0 me-0">
<Row cols={2} noGutters>
{#each certificates as certificate, i}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/public/certificates/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { redirectLogin } from '$lib/oauth';
/**
* @type {import('@sveltejs/kit').PageLoad}
*/
export async function load({ params, fetch }) {
export async function load({}) {
return listPublicCertificates()
.then((certificates) => {
return {
certificates: certificates
};
})
.catch(() => {
console.error("error listPublicCertificates")
redirectLogin('/cloud');
});
}

0 comments on commit 60af6e7

Please sign in to comment.