diff --git a/frontend/middleware/admin-only.ts b/frontend/middleware/admin-only.ts index 66a4e00f3566..b55f603d5151 100644 --- a/frontend/middleware/admin-only.ts +++ b/frontend/middleware/admin-only.ts @@ -1,8 +1,8 @@ -interface AuthRedirectParams { +interface AdminRedirectParams { $auth: any redirect: (path: string) => void } -export default function ({ $auth, redirect }: AuthRedirectParams) { +export default function ({ $auth, redirect }: AdminRedirectParams) { // If the user is not an admin redirect to the home page if (!$auth.user.admin) { return redirect("/") diff --git a/frontend/middleware/advanced-only.ts b/frontend/middleware/advanced-only.ts new file mode 100644 index 000000000000..378e3044b3ea --- /dev/null +++ b/frontend/middleware/advanced-only.ts @@ -0,0 +1,11 @@ +interface AdvancedOnlyRedirectParams { + $auth: any + redirect: (path: string) => void +} +export default function ({ $auth, redirect }: AdvancedOnlyRedirectParams) { + // If the user is not allowed to access advanced features redirect to the home page + if (!$auth.user.advanced) { + console.warn("User is not allowed to access advanced features"); + return redirect("/") + } +} diff --git a/frontend/middleware/can-manage-only.ts b/frontend/middleware/can-manage-only.ts new file mode 100644 index 000000000000..9c09819ca3d6 --- /dev/null +++ b/frontend/middleware/can-manage-only.ts @@ -0,0 +1,12 @@ +interface CanManageRedirectParams { + $auth: any + redirect: (path: string) => void +} +export default function ({ $auth, redirect }: CanManageRedirectParams) { + // If the user is not allowed to manage group settings redirect to the home page + console.log($auth.user) + if (!$auth.user.canManage) { + console.warn("User is not allowed to manage group settings"); + return redirect("/") + } +} diff --git a/frontend/middleware/can-organize-only.ts b/frontend/middleware/can-organize-only.ts new file mode 100644 index 000000000000..93d6c5c5aabf --- /dev/null +++ b/frontend/middleware/can-organize-only.ts @@ -0,0 +1,11 @@ +interface CanOrganizeRedirectParams { + $auth: any + redirect: (path: string) => void +} +export default function ({ $auth, redirect }: CanOrganizeRedirectParams) { + // If the user is not allowed to organize redirect to the home page + if (!$auth.user.canOrganize) { + console.warn("User is not allowed to organize data"); + return redirect("/") + } +} diff --git a/frontend/middleware/group-only.ts b/frontend/middleware/group-only.ts new file mode 100644 index 000000000000..84f28f12725d --- /dev/null +++ b/frontend/middleware/group-only.ts @@ -0,0 +1,12 @@ +interface GroupOnlyRedirectParams { + $auth: any + route: any + redirect: (path: string) => void +} + +export default function ({ $auth, route, redirect }: GroupOnlyRedirectParams) { + // this can only be used for routes that have a groupSlug parameter (e.g. /g/:groupSlug/...) + if (route.params.groupSlug !== $auth.user.groupSlug) { + redirect("/") + } +} diff --git a/frontend/pages/g/_groupSlug/cookbooks/index.vue b/frontend/pages/g/_groupSlug/cookbooks/index.vue index 233c4ad887bd..064aa41ff5ca 100644 --- a/frontend/pages/g/_groupSlug/cookbooks/index.vue +++ b/frontend/pages/g/_groupSlug/cookbooks/index.vue @@ -98,31 +98,23 @@