feat(workspaces): code review changes
This commit is contained in:
@@ -34,4 +34,4 @@ export type GetWorkspacePlanByProjectId = ({
|
||||
|
||||
export type CreateWorkspaceSeat = (
|
||||
args: Pick<WorkspaceSeat, 'workspaceId' | 'userId' | 'type'>
|
||||
) => Promise<WorkspaceSeat>
|
||||
) => Promise<void>
|
||||
|
||||
@@ -22,9 +22,13 @@ export const countSeatsByTypeInWorkspaceFactory =
|
||||
export const createWorkspaceSeatFactory =
|
||||
({ db }: { db: Knex }): CreateWorkspaceSeat =>
|
||||
async ({ userId, workspaceId, type }) => {
|
||||
return await tables.workspaceSeats(db).insert({
|
||||
workspaceId,
|
||||
userId,
|
||||
type
|
||||
})
|
||||
await tables
|
||||
.workspaceSeats(db)
|
||||
.insert({
|
||||
workspaceId,
|
||||
userId,
|
||||
type
|
||||
})
|
||||
.onConflict(['workspaceId', 'userId'])
|
||||
.merge()
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ export type CopyProjectAutomations = (params: {
|
||||
|
||||
export type AssignWorkspaceSeat = (
|
||||
params: Pick<WorkspaceSeat, 'userId' | 'workspaceId'> & { type?: WorkspaceSeatType }
|
||||
) => Promise<WorkspaceSeat>
|
||||
) => Promise<void>
|
||||
export type CopyProjectComments = (params: {
|
||||
projectIds: string[]
|
||||
}) => Promise<Record<string, number>>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BaseError } from '@/modules/shared/errors'
|
||||
|
||||
export class InvalidWorkspaceSeatType extends BaseError {
|
||||
export class InvalidWorkspaceSeatTypeError extends BaseError {
|
||||
static defaultMessage = 'Workspace seat type is invalid'
|
||||
static code = 'INDALID_WORKSPACE_SEAT_TYPE'
|
||||
static code = 'INDALID_WORKSPACE_SEAT_TYPE_ERROR'
|
||||
static statusCode = 400
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
AssignWorkspaceSeat,
|
||||
GetWorkspaceRoleForUser
|
||||
} from '@/modules/workspaces/domain/operations'
|
||||
import { InvalidWorkspaceSeatType } from '@/modules/workspaces/errors/workspaceSeat'
|
||||
import { InvalidWorkspaceSeatTypeError } from '@/modules/workspaces/errors/workspaceSeat'
|
||||
import { Roles, WorkspaceRoles } from '@speckle/shared'
|
||||
import { z } from 'zod'
|
||||
|
||||
@@ -82,7 +82,7 @@ export const assignWorkspaceSeatFactory =
|
||||
workspaceSeatType: type
|
||||
})
|
||||
) {
|
||||
throw new InvalidWorkspaceSeatType(
|
||||
throw new InvalidWorkspaceSeatTypeError(
|
||||
`User with workspace role ${workspaceAcl.role} cannot have a seat of type ${type}`,
|
||||
{
|
||||
info: {
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from '@/modules/core/helpers/testHelpers'
|
||||
import { createWorkspaceSeatFactory } from '@/modules/gatekeeper/repositories/workspaceSeat'
|
||||
import { NotFoundError } from '@/modules/shared/errors'
|
||||
import { InvalidWorkspaceSeatType } from '@/modules/workspaces/errors/workspaceSeat'
|
||||
import { InvalidWorkspaceSeatTypeError } from '@/modules/workspaces/errors/workspaceSeat'
|
||||
import { getWorkspaceRoleForUserFactory } from '@/modules/workspaces/repositories/workspaces'
|
||||
import { assignWorkspaceSeatFactory } from '@/modules/workspaces/services/workspaceSeat'
|
||||
import {
|
||||
@@ -177,7 +177,51 @@ describe('Workspace workspaceSeat services', () => {
|
||||
})({ userId: user.id, workspaceId: workspace.id, type: 'viewer' })
|
||||
)
|
||||
|
||||
expect(err.name).to.eq(InvalidWorkspaceSeatType.name)
|
||||
expect(err.name).to.eq(InvalidWorkspaceSeatTypeError.name)
|
||||
})
|
||||
it('should update seat type on role change', async () => {
|
||||
const workspaceAdmin: BasicTestUser = {
|
||||
id: createRandomString(),
|
||||
name: createRandomString(),
|
||||
email: createRandomEmail(),
|
||||
role: Roles.Server.Admin,
|
||||
verified: true
|
||||
}
|
||||
await createTestUser(workspaceAdmin)
|
||||
|
||||
const workspace: BasicTestWorkspace = {
|
||||
id: createRandomString(),
|
||||
slug: createRandomString(),
|
||||
ownerId: workspaceAdmin.id,
|
||||
name: cryptoRandomString({ length: 6 }),
|
||||
description: cryptoRandomString({ length: 12 })
|
||||
}
|
||||
await createTestWorkspace(workspace, workspaceAdmin)
|
||||
|
||||
const user: BasicTestUser = {
|
||||
id: createRandomString(),
|
||||
name: createRandomString(),
|
||||
email: createRandomEmail(),
|
||||
role: Roles.Server.User,
|
||||
verified: true
|
||||
}
|
||||
await createTestUser(user)
|
||||
|
||||
await assignToWorkspace(workspace, user, Roles.Workspace.Member)
|
||||
const workspaceSeat = await db('workspace_seats')
|
||||
.where({ userId: user.id, workspaceId: workspace.id })
|
||||
.first()
|
||||
|
||||
expect(workspaceSeat.type).to.eq('viewer')
|
||||
|
||||
// Change workspace role
|
||||
await assignToWorkspace(workspace, user, Roles.Workspace.Admin)
|
||||
|
||||
const workspaceSeatUpdated = await db('workspace_seats')
|
||||
.where({ userId: user.id, workspaceId: workspace.id })
|
||||
.first()
|
||||
|
||||
expect(workspaceSeatUpdated.type).to.eq('editor')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user