Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access control checks to dashboard #978

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dashboard/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
VITE_OIDC_ENABLED=\$VITE_OIDC_ENABLED
VITE_OIDC_AUTHORITY=\$VITE_OIDC_AUTHORITY
VITE_OIDC_CLIENT_ID=\$VITE_OIDC_CLIENT_ID
VITE_OIDC_REDIRECT_URI=\$VITE_OIDC_REDIRECT_URI
VITE_OIDC_EXTRA_SCOPES=\$VITE_OIDC_EXTRA_SCOPES
VITE_OIDC_ABAC_ENABLED=\$VITE_OIDC_ABAC_ENABLED
VITE_OIDC_ABAC_CLAIM_PATH=\$VITE_OIDC_ABAC_CLAIM_PATH
VITE_OIDC_ABAC_CLAIM_PATH_SEPARATOR=\$VITE_OIDC_ABAC_CLAIM_PATH_SEPARATOR
VITE_OIDC_ABAC_CLAIM_VALUE_PREFIX=\$VITE_OIDC_ABAC_CLAIM_VALUE_PREFIX
7 changes: 6 additions & 1 deletion dashboard/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
VITE_OIDC_AUTHORITY=http://keycloak:7470/realms/enduro
VITE_OIDC_ENABLED=true
VITE_OIDC_AUTHORITY=http://keycloak:7470/realms/artefactual
VITE_OIDC_CLIENT_ID=enduro
VITE_OIDC_REDIRECT_URI=http://localhost:8080/user/signin-callback
VITE_OIDC_EXTRA_SCOPES=enduro
VITE_OIDC_ABAC_ENABLED=true
VITE_OIDC_ABAC_CLAIM_PATH=enduro
VITE_OIDC_ABAC_CLAIM_PATH_SEPARATOR=
VITE_OIDC_ABAC_CLAIM_VALUE_PREFIX=
81 changes: 81 additions & 0 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@pinia/plugin-debounce": "^1.0.1",
"@types/humanize-duration": "^3.27.4",
"@vueuse/core": "^10.7.0",
"buffer": "^6.0.3",
"humanize-duration": "^3.31.0",
"moment": "^2.30.1",
"oidc-client-ts": "^3.0.1",
Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<script setup lang="ts">
import { watch } from "vue";
import { client } from "@/client";
import { useLayoutStore } from "./stores/layout";
import { useAuthStore } from "@/stores/auth";
import Header from "@/components/Header.vue";
import Sidebar from "@/components/Sidebar.vue";
import { DialogWrapper } from "vue3-promise-dialog";

const layoutStore = useLayoutStore();
const authStore = useAuthStore();

// Connect to the package monitor API when the user is loaded successfully.
watch(
() => layoutStore.isUserValid,
() => authStore.isUserValid,
(valid) => {
if (valid) {
client.package.packageMonitorRequest().then(() => {
Expand All @@ -25,19 +25,19 @@ watch(
<div class="d-flex flex-column min-vh-100">
<div
class="visually-hidden-focusable p-3 border-bottom"
v-if="layoutStore.isUserValid"
v-if="authStore.isUserValid"
>
<a class="btn btn-sm btn-outline-primary" href="#main"
>Skip to main content</a
>
</div>
<Header v-if="layoutStore.isUserValid" />
<Header v-if="authStore.isUserValid" />
<div class="flex-grow-1 d-flex">
<Sidebar v-if="layoutStore.isUserValid" />
<Sidebar v-if="authStore.isUserValid" />
<main class="flex-grow-1 d-flex px-2 pt-3" id="main">
<router-view></router-view>
</main>
</div>
<DialogWrapper v-if="layoutStore.isUserValid" />
<DialogWrapper v-if="authStore.isUserValid" />
</div>
</template>
14 changes: 0 additions & 14 deletions dashboard/src/auth.ts

This file was deleted.

8 changes: 3 additions & 5 deletions dashboard/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import auth from "./auth";
import * as api from "./openapi-generator";
import * as runtime from "./openapi-generator/runtime";
import { useAuthStore } from "@/stores/auth";
import { usePackageStore } from "./stores/package";
import { useLayoutStore } from "@/stores/layout";

export interface Client {
package: api.PackageApi;
Expand Down Expand Up @@ -61,13 +60,12 @@ function connectPackageMonitor() {
function createClient(): Client {
const config: api.Configuration = new api.Configuration({
basePath: getPath(),
accessToken: () =>
auth.getUser().then((user) => (user ? user.access_token : "")),
accessToken: () => useAuthStore().getUserAccessToken,
middleware: [
{
post(context) {
if (context.response.status == 401) {
useLayoutStore().removeUser();
useAuthStore().removeUser();
return Promise.resolve();
}
return Promise.resolve(context.response);
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/Breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const layoutStore = useLayoutStore();
</script>

<template>
<span v-if="layoutStore.breadcrumb.length" class="text-muted me-2">/</span>
<nav aria-label="Breadcrumb" class="d-inline-block">
<ol class="breadcrumb mb-0">
<li
Expand Down
1 change: 0 additions & 1 deletion dashboard/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ onMounted(() => {
</router-link>

<div class="flex-grow-1 d-none d-md-block">
<span class="text-muted me-2">/</span>
<Breadcrumb />
</div>
</nav>
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/components/PackageDetailsCard.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup lang="ts">
import { storageServiceDownloadURL } from "@/client";
import StatusBadge from "@/components/StatusBadge.vue";
import { useAuthStore } from "@/stores/auth";
import { usePackageStore } from "@/stores/package";
import { computed, watch } from "vue";

const authStore = useAuthStore();
const packageStore = usePackageStore();

const download = () => {
Expand Down Expand Up @@ -48,6 +50,7 @@ watch(packageStore.ui.download, () => download());
View metadata summary
</button>
<button
v-if="authStore.checkAttributes(['storage:package:download'])"
:class="{
btn: true,
'btn-primary': true,
Expand Down
10 changes: 9 additions & 1 deletion dashboard/src/components/PackageLocationCard.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script setup lang="ts">
import UUID from "@/components/UUID.vue";
import { openPackageLocationDialog } from "@/dialogs";
import { useAuthStore } from "@/stores/auth";
import { usePackageStore } from "@/stores/package";

const authStore = useAuthStore();
const packageStore = usePackageStore();

let failed = $ref<boolean | null>(null);
Expand Down Expand Up @@ -37,7 +39,13 @@ const choose = async () => {
>
<span v-else><UUID :id="packageStore.current.locationId" /></span>
</p>
<div class="actions" v-if="!packageStore.isRejected">
<div
class="actions"
v-if="
!packageStore.isRejected &&
jraddaoui marked this conversation as resolved.
Show resolved Hide resolved
authStore.checkAttributes(['package:move'])
"
>
<button
type="button"
class="btn btn-primary btn-sm"
Expand Down
8 changes: 7 additions & 1 deletion dashboard/src/components/PreservationActionCollapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import type { api } from "@/client";
import PackageReviewAlert from "@/components/PackageReviewAlert.vue";
import StatusBadge from "@/components/StatusBadge.vue";
import { useAuthStore } from "@/stores/auth";
import Collapse from "bootstrap/js/dist/collapse";
import { onMounted, watch } from "vue";
import IconCircleChevronDown from "~icons/akar-icons/circle-chevron-down";
import IconCircleChevronUp from "~icons/akar-icons/circle-chevron-up";

const authStore = useAuthStore();

const { action, index, toggleAll } = defineProps<{
action: api.EnduroPackagePreservationAction;
index: number;
Expand Down Expand Up @@ -102,7 +105,10 @@ watch($$(expandCounter), () => show());
"
/>
-->
<PackageReviewAlert v-model:expandCounter="expandCounter" />
<PackageReviewAlert
v-model:expandCounter="expandCounter"
v-if="authStore.checkAttributes(['package:review'])"
/>

<div
ref="el"
Expand Down
Loading
Loading