Files
speckle-server/packages/server/modules/workspaces/utils/isUserLastWorkspaceAdmin.ts
T
Chuck Driesler e703bb7415 WEB-1140 manage user workspace membership services (#2460)
* feat(workspaces): drop createdByUserId from the dataschema

* feat(workspaces): repositories WIP

* merge

* protect against removing last admin in workspace

* quick impl and stub tests

* add tests

* services

* unit tests for role services

* fix(workspaces): maybe tests work like this

* fix(workspaces): dry

* fix(workspaces): initialize tests better

* fix(workspaces): so true

* fix(workspaces): right

* fix(workspaces): self nit

* fix(workspaces): better repository structure

* fix(workspaces): repair tests, use `example.org`

* fix(workspaces): add tests for new repo functions, repair other tests

* fix(workspaces): better distinction between service-level guarantees and repo-level guarantees

* fix(workspaces): review comments and stencil tests

* fix(workspaces): add tests

* fix(workspaces): tests work

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2024-07-09 18:26:59 +02:00

14 lines
406 B
TypeScript

import { WorkspaceAcl } from '@/modules/workspaces/domain/types'
export const isUserLastWorkspaceAdmin = (
workspaceRoles: WorkspaceAcl[],
userId: string
): boolean => {
const workspaceAdmins = workspaceRoles.filter(
({ role }) => role === 'workspace:admin'
)
const isUserAdmin = workspaceAdmins.some((role) => role.userId === userId)
return isUserAdmin && workspaceAdmins.length === 1
}