Files
speckle-server/packages/server/modules/workspaces/graph/mocks/workspaces.ts
T
Gergő Jedlicska 08e941f8af Poor man's SSO (#2641)
* Implemented workspace general page

* Added notifications to user input

* Allowed non-admins to view but not edit

* Added redirect to homeroute

* Fixed validation

* Squashed commit of the following:

commit 7bf14ab8af0f76b4c9d0aa87fc08085af7c34959
Author: Chuck Driesler <chuck@speckle.systems>
Date:   Tue Aug 6 19:40:50 2024 +0200

    mob next [ci-skip] [ci skip] [skip ci]

    lastFile:packages/server/modules/workspacesCore/migrations/20240806160740_workspace_domains.ts

commit 8aa3fb0cb052c10eeeb83bf9874ae0d1c065e480
Author: Alessandro Magionami <alessandro.magionami@gmail.com>
Date:   Tue Aug 6 18:54:15 2024 +0200

    mob next [ci-skip] [ci skip] [skip ci]

    lastFile:packages/server/modules/core/domain/userEmails/operations.ts

commit 66dfd0cf6c15a789c8f96a65a3168323e83a7b9e
Author: Chuck Driesler <chuck@speckle.systems>
Date:   Tue Aug 6 18:30:22 2024 +0200

    mob next [ci-skip] [ci skip] [skip ci]

    lastFile:packages/server/modules/workspacesCore/domain/types.ts

Co-authored-by: Alessandro Magionami <alessandro.magionami@gmail.com>

* Move General to workspaces folder

* feat(workspaces): inputs on security section

* feat(workspaces): add domain to workspace mutation

* chore(workspaces): add blocked domains list

* fix(workspaces): modals with buttons

* feat(workspaceDomains): delete domain

* fix(workspaces): use  mutation

* fix(workspaces): present user verified domains as options

* Moved sidebar menu to a composable

* Added coming soon tag back

* feat(workspaces): create domains resolver for workspace

* chore(workspaces): fix tests

* chore(workspaces): fix types

* chore(workspaces): fix linter

* fix(workspaces): do some delete I think

* chore(workspaces): add domainBasedMembershipProtectionEnabled field to workspace

* chore(workspaces): improve validation for email domain

* fix(workspace): query and do the thing

* chore(workspaces): add graphql schema for domainBasedMembershipProtection

* chore(workspaces): lint and test failures

* fix(workspaces): test issues w new field

* feat(workspaces): add discoverability flag

* chore(workspaces): they made me do it

* feat(workspaces): enable toggling domain protection

* feat(workspaces): add discoverability toggle to workspace settings

* feat(workspace): auto enable discoverability on first domain registration

* feat(workspace): discoverability toggle fixes

* fix(eventBus): fix tests

* feat(workspaces): user discoverable workspaces (#2620)

* feat(workspaces): it works just trust me

* fix(workspaces): don't worry about it

* fix(workspaces); happy path success

* fix(workspaces): almost there

* fix(workspaces): successful tests!

* fix(workspaces): we have DISCOVERED (#2621)

* Fixed linting issue

* Updated query

* Updated validation rules

* Updated validation rules

* Fix unsaved file with type export

* Addressed PR comments

* Updated cache

* Updated item classes, add fragment back

* Gergo/web 1574 join workspaces via discovery (#2623)

* chore(useremails): add find verified emails by user function

* chore(workspace): table helper for workspace domains

* chore(workspace): get workspace with domains function

* chore(workspace): test get workspace with domains function

* feat(workspace): restrict workspace membership when updating workspace role

* chore(workspaces): fix types

* feat(workspaces): WIP join

* feat(workspaces): join button makes u join

* chore(useremails): fix type for find verified emails function

* feat(workspaces): join

* feat(workspace): prevent inviting user without email matching domain

* chore(workspaces): fix linter

* fix(workspaces): invoke join (gergo wrote this)

* fuck

* fix(workspaces): properly get discoverable workspaces

* fix(workspaces): test

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
Co-authored-by: Chuck Driesler <chuck@speckle.systems>

* fix(workspaces): some query stuff

* fix(workspaces): mutate cache instead of refetch

* fix(workspaces): more adjustments to gql query and fragment structure

* fix(workspaces): queries, style, structure

* fix(workspaces): match discoverability with current styles

* chore(workspaces): lint lint lint

* fix(workspaces): got it twisted

* chore(workspaces): fix test

* fix(workspaces): route to joined workspace on join

---------

Co-authored-by: Mike Tasset <mike.tasset@gmail.com>
Co-authored-by: Chuck Driesler <chuck@speckle.systems>
Co-authored-by: Alessandro Magionami <alessandro.magionami@gmail.com>
2024-08-26 13:33:16 +02:00

250 lines
7.9 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-unsafe-return */
import { listMock, SpeckleModuleMocksConfig } from '@/modules/shared/helpers/mocks'
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
import { faker } from '@faker-js/faker'
import { Roles } from '@speckle/shared'
import { omit, times } from 'lodash'
import { WorkspaceNotFoundError } from '@/modules/workspaces/errors/workspace'
const { FF_WORKSPACES_MODULE_ENABLED } = getFeatureFlags()
const workspaceName = () =>
`${faker.person.firstName()} ${faker.commerce.productName()}`
const config: SpeckleModuleMocksConfig = FF_WORKSPACES_MODULE_ENABLED
? {
resolvers: ({
helpers: {
getFieldValue,
getMockRef,
resolveFromMockParent,
addMockRefValues,
resolveAndCache,
setMockValues
}
}) => {
return {
WorkspaceMutations: {
create: (_parent, args) => {
if (args.input.name === 'error') {
throw new Error('Fake workspace create error')
}
return getMockRef('Workspace', { values: omit(args.input, ['logo']) })
},
delete: () => {
const val = faker.datatype.boolean()
if (!val) {
throw new Error('Fake workspace delete error')
}
return val
},
update: (_parent, args) => {
if (args.input.name === 'error') {
throw new Error('Fake workspace update error')
}
setMockValues(
{
type: 'Workspace',
id: args.input.id
},
omit(args.input, ['logo', 'id'])
)
return getMockRef('Workspace', { id: args.input.id })
},
updateRole: (_parent, args) => {
const val = faker.datatype.boolean()
if (val) {
throw new Error('Fake update role error')
}
return getMockRef('Workspace', {
id: args.input.workspaceId
})
}
},
WorkspaceInviteMutations: {
create: (_parent, args) => {
const val = faker.datatype.boolean()
if (val) {
throw new Error('Fake invite create error')
}
return getMockRef('Workspace', {
id: args.workspaceId
})
},
batchCreate: (_parent, args) => {
const val = faker.datatype.boolean()
if (val) {
throw new Error('Fake batch create invite error')
}
return getMockRef('Workspace', {
id: args.workspaceId
})
},
use: () => {
const val = faker.datatype.boolean()
if (!val) {
throw new Error('Fake use invite error')
}
return val
},
cancel: (_parent, args) => {
const val = faker.datatype.boolean()
if (val) {
throw new Error('Fake cancel invite error')
}
return getMockRef('Workspace', {
id: args.workspaceId
})
}
},
Query: {
workspace: (_parent, args) => {
if (args.id === '404') {
throw new WorkspaceNotFoundError('Workspace not found')
}
return getMockRef('Workspace', {
id: args.id
})
},
workspaceInvite: (_parent, args) => {
const getResult = () => getMockRef('PendingWorkspaceCollaborator')
if (args.token) {
return getResult()
}
return faker.datatype.boolean() ? getResult() : null
}
},
User: {
discoverableWorkspaces: resolveAndCache(() => [
{
id: faker.string.uuid(),
name: workspaceName(),
description: faker.lorem.sentence(),
defaultLogoIndex: 0,
logo: null
}
]),
workspaces: resolveAndCache((_parent, args) =>
getMockRef('WorkspaceCollection', {
values: {
cursor: args.cursor ? null : undefined
}
})
),
workspaceInvites: resolveAndCache(() =>
times(faker.number.int({ min: 0, max: 2 }), () =>
getMockRef('PendingWorkspaceCollaborator')
)
)
},
Workspace: {
role: resolveFromMockParent(),
team: resolveFromMockParent(),
invitedTeam: resolveFromMockParent({
mapRefs: (mock, { parent }) =>
addMockRefValues(mock, {
workspaceId: getFieldValue(parent, 'id'),
workspaceName: getFieldValue(parent, 'name')
})
}),
projects: resolveAndCache((_parent, args) =>
getMockRef('ProjectCollection', {
values: {
cursor: args.cursor ? null : undefined
}
})
),
domains: resolveAndCache(() => [
{
id: faker.string.uuid(),
domain: 'speckle.systems'
},
{
id: faker.string.uuid(),
domain: 'example.org'
}
])
},
WorkspaceCollaborator: {
role: resolveFromMockParent(),
user: resolveFromMockParent()
},
PendingWorkspaceCollaborator: {
user: resolveAndCache((parent) => {
const title = getFieldValue<string>(parent, 'title')
const isEmail = title.includes('@')
if (isEmail) return null
return getMockRef('LimitedUser', { values: { name: title } })
}),
invitedBy: resolveAndCache(() => getMockRef('LimitedUser')),
workspaceName: resolveFromMockParent(),
token: resolveFromMockParent()
},
Project: {
workspace: resolveAndCache(() => {
return faker.datatype.boolean() ? getMockRef('Workspace') : null
})
},
AdminQueries: {
workspaceList: resolveAndCache((_parent, args) =>
getMockRef('WorkspaceCollection', {
values: {
cursor: args.cursor ? null : undefined
}
})
)
},
WorkspaceCollection: {
items: resolveAndCache((parent) => {
const count = getFieldValue(parent, 'totalCount')
return times(count, () => getMockRef('Workspace'))
})
}
}
},
mocks: {
Workspace: () => ({
name: workspaceName(),
description: faker.lorem.sentence(),
role: faker.helpers.arrayElement(Object.values(Roles.Workspace)),
team: listMock(1, 5),
invitedTeam: listMock(1, 5)
}),
WorkspaceCollaborator: () => ({
role: () => faker.helpers.arrayElement(Object.values(Roles.Server))
}),
PendingWorkspaceCollaborator: () => ({
inviteId: faker.string.uuid(),
workspaceId: faker.string.uuid(),
workspaceName: workspaceName(),
title: faker.datatype.boolean()
? faker.internet.email()
: faker.person.fullName(),
role: faker.helpers.arrayElement(Object.values(Roles.Workspace)),
token: faker.string.alphanumeric(32)
}),
WorkspaceCollection: () => ({
totalCount: faker.number.int({ min: 0, max: 10 })
})
}
}
: {}
export default config