Skip to content

Commit

Permalink
Bug/kob fix authentication and redirect admin (#51)
Browse files Browse the repository at this point in the history
* Fix admin routing and redirect for non admins

* Update core.router.ts

* Update main.ts

* Update main.ts

* Update main.ts

* Update core.router.ts

* Update the-drawer-main-store.module.ts

* Update the-admin-overview.vue

* Update u-finder.routes.ts

* Change admin view based on type

* Fix typescript errors

* Add Admin roles and improvements

* Add missing route to menu for department admin

* clean up

* Fix theme on redirect

---------

Co-authored-by: Thomas Fink <[email protected]>
  • Loading branch information
ThomasAFink and ThomasAFink authored May 21, 2024
1 parent d298770 commit 3c5e65a
Show file tree
Hide file tree
Showing 30 changed files with 811 additions and 688 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ dist/
nbdist/
.nb-gradle/

# Intellij
.run/kobit-frontend.run.xml


3 changes: 0 additions & 3 deletions frontend/src/core/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import Vue from "vue";
import TheBackground from "@/features/the-background/the-background.vue";
import TheFooterMain from "@/features/the-footer-main/the-footer-main.vue";
import TheAppBar from "@/features/the-app-bar/the-app-bar.vue";
import {
initAnlaufstellen
} from "@/features/the-unterstuetzungsfinder/features/the-contact-points/the-contact-points-store.module";
import TheDisclaimer from "@/features/the-disclaimer/the-disclaimer.vue";
import DownloadProvider from "@/core/services/downloads/download-provider.mixin.vue";
Expand Down
188 changes: 94 additions & 94 deletions frontend/src/core/core.router.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
import Vue from "vue";
import Router from "vue-router";
// Add this import at the top of core.router.ts
import vuetify, { adminTheme, kobitTheme } from "@/core/plugins/vuetify";
import Vue from 'vue';
import Router from 'vue-router';
import vuetify, { adminTheme, kobitTheme } from '@/core/plugins/vuetify';

import {theMainRoutes} from "@/features/the-main/the-main.routes";
import {erfahreMehrRoutes} from "@/features/the-additional/the-additional.routes";
import {
conflictPreventionRoutes
} from "@/features/the-additional/features/the-conflict-prevention/the-conflict-prevention.routes";
import {downloadsRoutes} from "@/features/the-additional/features/the-downloads/the-downloads.routes";
import {faqRoutes} from "@/features/the-additional/features/the-faq/the-faq.routes";
import {glossarRoutes} from "@/features/the-additional/features/the-glossar/the-glossar.routes";
import {
leadershipCooperationRoutes
} from "@/features/the-additional/features/the-leadership-cooperation/the-leadership-cooperation.routes";
import {dvFairRoutes} from "@/features/the-additional/features/the-dv-fair/the-dv-fair.routes";
import {
escalationStepsRoutes
} from "@/features/the-additional/features/the-escalation-steps/the-escalation-steps.routes";
import {
theAnlaufstellenRoutes
} from "@/features/the-unterstuetzungsfinder/features/the-contact-points/the-contact-points.routes";
import {theAngeboteRoutes} from "@/features/the-angebote/the-angebote.routes";
import {theUnterstuetzungsfinderRoutes} from "@/features/the-unterstuetzungsfinder/the-unterstuetzungsfinder.routes";
import {
theAnlaufstellenDetailsRoutes
} from "@/features/the-unterstuetzungsfinder/features/the-contact-points/the-contact-points-details.routes";
import {adminUFinderRoutes} from "@/features/admin/components/u-finder/u-finder.routes";
import { theMainRoutes } from '@/features/the-main/the-main.routes';
import { erfahreMehrRoutes } from '@/features/the-additional/the-additional.routes';
import { conflictPreventionRoutes } from '@/features/the-additional/features/the-conflict-prevention/the-conflict-prevention.routes';
import { downloadsRoutes } from '@/features/the-additional/features/the-downloads/the-downloads.routes';
import { faqRoutes } from '@/features/the-additional/features/the-faq/the-faq.routes';
import { glossarRoutes } from '@/features/the-additional/features/the-glossar/the-glossar.routes';
import { leadershipCooperationRoutes } from '@/features/the-additional/features/the-leadership-cooperation/the-leadership-cooperation.routes';
import { dvFairRoutes } from '@/features/the-additional/features/the-dv-fair/the-dv-fair.routes';
import { escalationStepsRoutes } from '@/features/the-additional/features/the-escalation-steps/the-escalation-steps.routes';
import { theAnlaufstellenRoutes } from '@/features/the-unterstuetzungsfinder/features/the-contact-points/the-contact-points.routes';
import { theAngeboteRoutes } from '@/features/the-angebote/the-angebote.routes';
import { theUnterstuetzungsfinderRoutes } from '@/features/the-unterstuetzungsfinder/the-unterstuetzungsfinder.routes';
import { theAnlaufstellenDetailsRoutes } from '@/features/the-unterstuetzungsfinder/features/the-contact-points/the-contact-points-details.routes';

import {adminRoutes} from "@/features/admin/the-admin-routes";
import {adminContactPointsRoutes} from "@/features/admin/features/the-contact-points/the-contact-points-routes";
import {adminExperienceMoreRoutes} from "@/features/admin/features/the-additional/the-additional-overview-routes";
import {
adminConflictPreventionRoutes
} from "@/features/admin/features/the-additional/features/the-conflict-prevention/the-conflict-prevention.routes";
import {
adminDownloadsRoutes
} from "@/features/admin/features/the-additional/features/the-downloads/the-downloads.routes";
import {
adminFaqRoutes
} from "@/features/admin/features/the-additional/features/the-faq/the-faq.routes";
import {
adminGlossarRoutes
} from "@/features/admin/features/the-additional/features/the-glossar/the-glossar.routes";
import {
adminLeadershipCooperationRoutes
} from "@/features/admin/features/the-additional/features/the-leadership-cooperation/the-leadership-cooperation.routes";
import { adminRoutes } from '@/features/admin/the-admin-routes';
import { adminContactPointsRoutes } from '@/features/admin/features/the-contact-points/the-contact-points-routes';
import { adminAdditionalRoutes } from '@/features/admin/features/the-additional/the-additional-overview-routes';
import { adminConflictPreventionRoutes } from '@/features/admin/features/the-additional/features/the-conflict-prevention/the-conflict-prevention.routes';
import { adminDownloadsRoutes } from '@/features/admin/features/the-additional/features/the-downloads/the-downloads.routes';
import { adminFaqRoutes } from '@/features/admin/features/the-additional/features/the-faq/the-faq.routes';
import { adminGlossarRoutes } from '@/features/admin/features/the-additional/features/the-glossar/the-glossar.routes';
import { adminLeadershipCooperationRoutes } from '@/features/admin/features/the-additional/features/the-leadership-cooperation/the-leadership-cooperation.routes';
import { adminUnterstuetzungsfinderRoutes } from '@/features/admin/components/u-finder/u-finder.routes';

Vue.use(Router);
import { getAdminUserInfo } from '@/features/admin/components/userinformation/api/AdminInfoClient';

/*
* Preventing "NavigationDuplicated" errors in console in Vue-router >= 3.1.0
* https://github.com/vuejs/vue-router/issues/2881#issuecomment-520554378
* */
/* eslint-disable @typescript-eslint/no-explicit-any */
const routerMethods = ['push', 'replace'];
routerMethods.forEach((method: string) => {
const originalCall = (Router.prototype as any)[method];
(Router.prototype as any)[method] = function (location: any, onResolve: any, onReject: any): Promise<any> {
if (onResolve || onReject) {
return originalCall.call(this, location, onResolve, onReject);
}
return (originalCall.call(this, location) as any).catch((err: any) => err);
};
});
/* eslint-enable @typescript-eslint/no-explicit-any */
Vue.use(Router);

const baseRoutes = [
theMainRoutes,
theUnterstuetzungsfinderRoutes,
erfahreMehrRoutes,
conflictPreventionRoutes,
downloadsRoutes,
faqRoutes,
glossarRoutes,
leadershipCooperationRoutes,
dvFairRoutes,
escalationStepsRoutes,
theAnlaufstellenRoutes,
theAnlaufstellenDetailsRoutes,
theAngeboteRoutes
];

const router = new Router({
base: process.env.BASE_URL,
routes: [
theMainRoutes,
theUnterstuetzungsfinderRoutes,
erfahreMehrRoutes,
conflictPreventionRoutes,
downloadsRoutes,
faqRoutes,
glossarRoutes,
leadershipCooperationRoutes,
dvFairRoutes,
escalationStepsRoutes,
theAnlaufstellenRoutes,
theAnlaufstellenDetailsRoutes,
theAngeboteRoutes,
adminRoutes,
adminContactPointsRoutes,
adminExperienceMoreRoutes,
adminConflictPreventionRoutes,
adminDownloadsRoutes,
adminFaqRoutes,
adminGlossarRoutes,
adminLeadershipCooperationRoutes,
adminUFinderRoutes
]
routes: baseRoutes
});

router.beforeEach((to, _, next) => {
if (to.path === '/admin' || to.path.startsWith('/admin/')) {
vuetify.framework.theme.themes.light = adminTheme.themes.light;
vuetify.framework.theme.themes.dark = adminTheme.themes.dark;
let adminRoutesAdded = false;

router.beforeEach(async (to, from, next) => {
if (!adminRoutesAdded && to.path.startsWith('/admin')) {
try {
const adminUserInfo = await getAdminUserInfo();

let adminRoutesToAdd: string | any[] = [];

if (adminUserInfo.isCentralAdmin) {
adminRoutesToAdd = [
...adminRoutesToAdd,
adminRoutes,
adminContactPointsRoutes,
adminAdditionalRoutes,
adminConflictPreventionRoutes,
adminDownloadsRoutes,
adminFaqRoutes,
adminGlossarRoutes,
adminLeadershipCooperationRoutes,
adminUnterstuetzungsfinderRoutes
];
} else if (adminUserInfo.isDepartmentAdmin) {
adminRoutesToAdd = [
...adminRoutesToAdd,
adminRoutes,
adminContactPointsRoutes,
adminUnterstuetzungsfinderRoutes
];
}

if (adminRoutesToAdd.length > 0) {
router.addRoutes(adminRoutesToAdd);
adminRoutesAdded = true;

vuetify.framework.theme.themes.light = adminTheme.themes.light;
vuetify.framework.theme.themes.dark = adminTheme.themes.dark;

next({ path: to.path, query: to.query, replace: true });
} else {
vuetify.framework.theme.themes.light = kobitTheme.themes.light;
vuetify.framework.theme.themes.dark = kobitTheme.themes.dark;
next({ path: '/' });
}
} catch (error) {
vuetify.framework.theme.themes.light = kobitTheme.themes.light;
vuetify.framework.theme.themes.dark = kobitTheme.themes.dark;
next({ path: '/' });
}
} else {
vuetify.framework.theme.themes.light = kobitTheme.themes.light;
vuetify.framework.theme.themes.dark = kobitTheme.themes.dark;
next();
}
next();
});


export default router;
export default router;
3 changes: 2 additions & 1 deletion frontend/src/core/services/downloads/privacypolicy.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<p>
<p class="pt-0 mt-4">
<v-btn
v-if="item !== undefined"
plain
:href="item.textItemView[0].link"
:download="item.textItemView[0].header"
:loading="isLoading"
class="pt-0 mt-0"
>
Datenschutzhinweis <v-icon>mdi-download</v-icon>
</v-btn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const mapAdminInfoToText = (adminInfo: AdminUserInfo): AdminTextInfo => {
}

export const useGetAdminUserInfoText = () =>
useQuery<AdminTextInfo>(['adminInfo'],
useQuery<AdminTextInfo>(['adminInfoText'],
() => getAdminUserInfo().then(mapAdminInfoToText)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import SupportFinderAdmin from "@/features/admin/components/u-finder/SupportFinderAdmin.vue";

export const THE_UNTERSTUETZUNGSFINDER_ADMIN_ROUTE_PATH = "/admin/unterstuetzungsfinder";
export const THE_UNTERSTUETZUNGSFINDER_ADMIN_ROUTE_NAME = "Unterstützungsfinder - Admin Bereich";
export const THE_UNTERSTUETZUNGSFINDER_ROUTE_PATH = "/admin/unterstuetzungsfinder";
export const THE_UNTERSTUETZUNGSFINDER_ROUTE_NAME = "Unterstützungsfinder bearbeiten";
export const THE_UNTERSTUETZUNGSFINDER_ROUTE_META_ICON = "mdi-arrow-decision";
export const THE_UNTERSTUETZUNGSFINDER_ADMIN_ROUTE_META_INFO_TEXT = `Hier können sie den einzelnen Pfaden des Unterstützungsfinder entsprechende Anlaufstellen zuordnen. Dafür müssen die einzelnen Pfade genau wie im "normalen" Unterstützungsfinder durchlaufen werden.`;
export const THE_UNTERSTUETZUNGSFINDER_ROUTE_META_INFO_TEXT = `Hier können sie den einzelnen Pfaden des Unterstützungsfinder entsprechende Anlaufstellen zuordnen. Dafür müssen die einzelnen Pfade genau wie im "normalen" Unterstützungsfinder durchlaufen werden.`;

export const adminUFinderRoutes = {
name: THE_UNTERSTUETZUNGSFINDER_ADMIN_ROUTE_NAME,
path: THE_UNTERSTUETZUNGSFINDER_ADMIN_ROUTE_PATH,
export const adminUnterstuetzungsfinderRoutes = {
name: THE_UNTERSTUETZUNGSFINDER_ROUTE_NAME,
path: THE_UNTERSTUETZUNGSFINDER_ROUTE_PATH,
component: SupportFinderAdmin,
meta: {
icon: THE_UNTERSTUETZUNGSFINDER_ROUTE_META_ICON,
infoText: THE_UNTERSTUETZUNGSFINDER_ADMIN_ROUTE_META_INFO_TEXT
infoText: THE_UNTERSTUETZUNGSFINDER_ROUTE_META_INFO_TEXT
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<v-col cols="12">
<v-text-field
v-model="addedItem.header"
color="secondary"
:label="headerLabel"
:rules="[headerRule]"
max-file-name-input-length="250"
Expand All @@ -32,6 +33,7 @@
<v-col cols="12">
<v-textarea
v-model="addedItem.entry"
color="secondary"
:label="entryLabel"
:rules="[entryRule]"
max-file-name-input-length="1500"
Expand Down Expand Up @@ -89,7 +91,7 @@
</template>

<script lang="ts">
import { defineComponent, watch, PropType, computed, ref, onMounted, getCurrentInstance } from "vue";
import { defineComponent, watch, PropType, computed, ref, getCurrentInstance } from "vue";
import { TextItem } from "@/features/commons/types/Item";
import { VDialog, VCard, VCardTitle, VCardText, VCardActions, VSpacer, VBtn, VCol, VContainer, VFileInput, VForm, VIcon, VRow, VSnackbar, VTextarea, VTextField } from "vuetify/lib";

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VDialog' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VDialog' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCard' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCard' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardTitle' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardTitle' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardText' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardText' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardActions' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardActions' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VDialog' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VDialog' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCard' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCard' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardTitle' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardTitle' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardText' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardText' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardActions' is defined but never used

Check warning on line 96 in frontend/src/features/admin/features/the-additional/commons/AddTextItemDialog.vue

View workflow job for this annotation

GitHub Actions / build

'VCardActions' is defined but never used
import { useCreateNewTextItem } from "../features/middelware/useTextItem";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<v-icon>mdi-cancel</v-icon> Abbruch
</v-btn>
<v-btn
color="green darken-1 white--text"
color="error"
@click="deleteItem"
>
<v-icon>mdi-delete</v-icon> Löschen
Expand All @@ -33,7 +33,7 @@
<v-snackbar
v-model="isSnackbarActive"
:timeout="SNACKBAR_TIMEOUT"
color="green darken-1"
color="error"
bottom
>
<p class="pa-0 ma-0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<v-col cols="12">
<v-text-field
v-model="editedItem.header"
color="secondary"
:label="headerLabel"
:rules="[headerRule]"
max-file-name-input-length="250"
Expand All @@ -32,6 +33,7 @@
<v-col cols="12">
<v-textarea
v-model="editedItem.entry"
color="secondary"
:label="entryLabel"
:rules="[entryRule]"
max-file-name-input-length="1500"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<v-icon>mdi-pencil</v-icon> Bearbeiten
</v-btn>
<v-btn
color="green darken-1 ml-2 white--text"
color="error ml-2"
@click="openDeleteDialog(item)"
>
<v-icon>mdi-delete</v-icon> Löschen
Expand Down Expand Up @@ -150,5 +150,6 @@ export default defineComponent({
overflow-wrap: break-word;
white-space: pre-wrap;
max-width: 100%;
text-indent: 0em !important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ export const putTextItem = async (id: string, pageType: string, textItem: TextIt
}

export const deleteTextItem = async (id: string, pageType: string, link: string) => {
const deleteOldFile = `/s3/delete?link=${encodeURIComponent(link.toString())}`;
await httpDeleteS3File(deleteOldFile);
const url = `/additional/${pageType}/text-item/${id}?link=${encodeURIComponent(link)}`;

if(link){
const deleteOldFile = `/s3/delete?link=${encodeURIComponent(link.toString())}`;
await httpDeleteS3File(deleteOldFile);
}

const url = `/additional/${pageType}/text-item/${id}`;
return httpDeleteJson(url);
}
Loading

0 comments on commit 3c5e65a

Please sign in to comment.