5f88f562d3
* a bunch more tests * updated GQL resolvers * project create checks implemented * project update/settings related checks in FE * a bunch of tests * tests fix * disable app schema check
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { graphql } from '~/lib/common/generated/gql'
|
|
import { useApolloClientFromNuxt } from '~~/lib/common/composables/graphql'
|
|
import { convertThrowIntoFetchResult } from '~~/lib/common/helpers/graphql'
|
|
import { projectRoute } from '~~/lib/common/helpers/route'
|
|
|
|
const canViewProjectSettingsQuery = graphql(`
|
|
query CanViewProjectSettings($projectId: String!) {
|
|
project(id: $projectId) {
|
|
id
|
|
permissions {
|
|
canReadSettings {
|
|
...FullPermissionCheckResult
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`)
|
|
|
|
/**
|
|
* 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: canViewProjectSettingsQuery,
|
|
variables: { projectId }
|
|
})
|
|
.catch(convertThrowIntoFetchResult)
|
|
|
|
if (!data?.project) {
|
|
return navigateTo(projectRoute(projectId))
|
|
}
|
|
|
|
const canReadSettings = data.project.permissions.canReadSettings.authorized
|
|
if (!canReadSettings) {
|
|
return navigateTo(projectRoute(projectId))
|
|
}
|
|
|
|
return undefined
|
|
})
|