-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe2): Hide settings tab for logged out users (#2261)
* Hide settings for logged out users * Hide settings tab for non-logged in users * Add middleware to settings to login * Add middleware * Update to webhooks middleware * Updates to middleware * Changes to middleware * Update comments
- Loading branch information
1 parent
7a1d4ba
commit 69decaf
Showing
8 changed files
with
130 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useApolloClientFromNuxt } from '~~/lib/common/composables/graphql' | ||
import { convertThrowIntoFetchResult } from '~~/lib/common/helpers/graphql' | ||
import { projectRoute } from '~~/lib/common/helpers/route' | ||
import { projectRoleCheckQuery } from '~~/lib/projects/graphql/queries' | ||
|
||
/** | ||
* Apply this to a page to prevent unauthenticated access to settings ensuring the user is a collaborator | ||
*/ | ||
export default defineNuxtRouteMiddleware(async (to) => { | ||
const client = useApolloClientFromNuxt() | ||
|
||
// Fetch project role data to check if the user is a collaborator | ||
const projectId = to.params.id as string | ||
const { data } = await client | ||
.query({ | ||
query: projectRoleCheckQuery, | ||
variables: { id: projectId } | ||
}) | ||
.catch(convertThrowIntoFetchResult) | ||
|
||
if (!data?.project) { | ||
return navigateTo(projectRoute(projectId)) | ||
} | ||
|
||
// Check if the user is a collaborator of the project | ||
const hasRole = computed(() => data.project.role) | ||
|
||
if (!hasRole.value) { | ||
return navigateTo(projectRoute(projectId)) | ||
} | ||
|
||
return undefined | ||
}) |
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,30 @@ | ||
import { Roles } from '@speckle/shared' | ||
import { useApolloClientFromNuxt } from '~~/lib/common/composables/graphql' | ||
import { convertThrowIntoFetchResult } from '~~/lib/common/helpers/graphql' | ||
import { projectSettingsRoute } from '~~/lib/common/helpers/route' | ||
import { projectRoleCheckQuery } from '~~/lib/projects/graphql/queries' | ||
|
||
/** | ||
* Apply this to a page to prevent unauthenticated access to webhooks and ensure the user is the owner | ||
*/ | ||
export default defineNuxtRouteMiddleware(async (to) => { | ||
const client = useApolloClientFromNuxt() | ||
|
||
// Fetch project role data to check if the user is the owner | ||
const projectId = to.params.id as string | ||
const { data } = await client | ||
.query({ | ||
query: projectRoleCheckQuery, | ||
variables: { id: projectId } | ||
}) | ||
.catch(convertThrowIntoFetchResult) | ||
|
||
// Check if the user is the owner of the project | ||
const isOwner = data?.project.role === Roles.Stream.Owner | ||
|
||
if (!isOwner) { | ||
return navigateTo(projectSettingsRoute(projectId)) | ||
} | ||
|
||
return undefined | ||
}) |
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
5 changes: 5 additions & 0 deletions
5
packages/frontend-2/pages/projects/[id]/index/settings/webhooks.vue
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,3 +1,8 @@ | ||
<template> | ||
<ProjectPageSettingsWebhooks /> | ||
</template> | ||
<script setup lang="ts"> | ||
definePageMeta({ | ||
middleware: ['can-view-webhooks'] | ||
}) | ||
</script> |