a6287fc06d
* init db migration * WIP store view * create service call * WIP insertion * insert sort of works * moving code arounmd * creation tests * avoid duplicate entries * fixes from main * basic group retrieval works * group filtering works * WIP view listing * filter by acl * fixes + WIP single group retrieval * wip pivot * more pivot query fixes * tests fixed after pivot * views list tests * fixing test command * business plan only checks * more tests for coverage * .dts import fix * cli fix * anutha one * auth policy tests for business plan access * WIP saved views panel base * BE listing adjustments * WIP group rendering * group render done * WIP post create cache updates * listing fine? * my vs theirs * auto open * minor fixes * click load omg * nicely loading views * type fix * less spammy loading * another type fix: * more lint fix * test fix * codecov disable * moar coverage * fix sidebar flashin * more test coverage * more test cvoverage * minor adfjustments * adj * saved view wipe fixes * CSR viewer * more improvements * extra feature flag checks * lint fix * feature flags fix * more test fixes
115 lines
2.9 KiB
TypeScript
115 lines
2.9 KiB
TypeScript
import { basicWorkspaceFragment } from '@/modules/workspaces/tests/helpers/graphql'
|
|
import type { ProjectImplicitRoleCheckFragment } from '@/modules/core/graph/generated/graphql'
|
|
import type { MaybeNullOrUndefined } from '@speckle/shared'
|
|
import { Roles } from '@speckle/shared'
|
|
import { gql } from 'graphql-tag'
|
|
|
|
export const fullPermissionCheckResultFragment = gql(`
|
|
fragment FullPermissionCheckResult on PermissionCheckResult {
|
|
authorized
|
|
code
|
|
message
|
|
payload
|
|
errorMessage
|
|
}
|
|
`)
|
|
|
|
export const projectImplicitRoleCheckFragment = gql`
|
|
fragment ProjectImplicitRoleCheck on Project {
|
|
id
|
|
role
|
|
permissions {
|
|
# general access check
|
|
canRead {
|
|
...FullPermissionCheckResult
|
|
}
|
|
# implicit reviewer check
|
|
canReadSettings {
|
|
...FullPermissionCheckResult
|
|
}
|
|
# implicit owner check
|
|
canReadWebhooks {
|
|
...FullPermissionCheckResult
|
|
}
|
|
# implicit contributor check
|
|
canCreateModel {
|
|
...FullPermissionCheckResult
|
|
}
|
|
}
|
|
}
|
|
|
|
${fullPermissionCheckResultFragment}
|
|
`
|
|
|
|
export const getUserWorkspaceAccessQuery = gql`
|
|
query GetUserWorkspaceAccess($id: String!) {
|
|
workspace(id: $id) {
|
|
id
|
|
role
|
|
seatType
|
|
}
|
|
}
|
|
`
|
|
|
|
export const getUserWorkspaceProjectsWithAccessChecksQuery = gql`
|
|
query GetUserWorkspaceProjectsWithAccessChecks(
|
|
$id: String!
|
|
$limit: Int
|
|
$cursor: String
|
|
$filter: WorkspaceProjectsFilter
|
|
) {
|
|
workspace(id: $id) {
|
|
...BasicWorkspace
|
|
role
|
|
seatType
|
|
projects(limit: $limit, cursor: $cursor, filter: $filter) {
|
|
items {
|
|
...ProjectImplicitRoleCheck
|
|
}
|
|
cursor
|
|
totalCount
|
|
}
|
|
}
|
|
}
|
|
|
|
${basicWorkspaceFragment}
|
|
${projectImplicitRoleCheckFragment}
|
|
`
|
|
|
|
export const getUserProjectsWithAccessChecksQuery = gql`
|
|
query GetUserProjectsWithAccessChecks(
|
|
$limit: Int
|
|
$cursor: String
|
|
$filter: UserProjectsFilter
|
|
) {
|
|
activeUser {
|
|
id
|
|
projects(limit: $limit, cursor: $cursor, filter: $filter) {
|
|
items {
|
|
...ProjectImplicitRoleCheck
|
|
}
|
|
cursor
|
|
totalCount
|
|
}
|
|
}
|
|
}
|
|
${projectImplicitRoleCheckFragment}
|
|
`
|
|
|
|
export const projectImplicitRoleCheck = (
|
|
project: MaybeNullOrUndefined<ProjectImplicitRoleCheckFragment>
|
|
) => {
|
|
return {
|
|
hasAccess: !!project?.permissions?.canRead.authorized,
|
|
isReviewer: !!project?.permissions?.canReadSettings.authorized,
|
|
isContributor: !!project?.permissions?.canCreateModel.authorized,
|
|
isOwner: !!project?.permissions?.canReadWebhooks.authorized,
|
|
isExplicitOwner: project?.role === Roles.Stream.Owner,
|
|
isExplicitContributor: project?.role === Roles.Stream.Contributor,
|
|
isExplicitReviewer: project?.role === Roles.Stream.Reviewer,
|
|
hasExplicitRole: !!project?.role
|
|
}
|
|
}
|
|
|
|
export type ProjectImplicitRoleCheck = ReturnType<typeof projectImplicitRoleCheck>
|