e703bb7415
* 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>
14 lines
406 B
TypeScript
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
|
|
}
|