66eb539aa0
* 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 * feat(workspaces): authorize project creation if workspace specified * feat(workspaces): emit project created event * feat(workspaces): assign roles on project create in workspace * feat(workspaces): update project roles when user added to workspace * fix(workspaces): perform automatic project role update in service function * fix(workspaces): also delete roles * fix(workspaces): broke tests again oops * fix(workspaces): update `onProjectCreated` listener to use new repo method * fix(workspaces): use service function in event listener * fix(workspaces): get workspace projects via existing stream repo functions * fix(workspaces): roles mapping in domain, use enum * fix(workspaces): repair type reference in tests * fix(workspaces): consolidate files, use different existing stream-getter * fix(workspaces): more specific error * fix(workspaces): yield per page * fix(workspaces): some test dry * fix(workspaces): superdry * fix(workspaces): classic --------- Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
99 lines
2.3 KiB
TypeScript
99 lines
2.3 KiB
TypeScript
import {
|
|
WorkspaceEvents,
|
|
WorkspaceEventsPayloads
|
|
} from '@/modules/workspacesCore/domain/events'
|
|
import { StreamRecord } from '@/modules/core/helpers/types'
|
|
import { Workspace, WorkspaceAcl } from '@/modules/workspacesCore/domain/types'
|
|
|
|
/** Workspace */
|
|
|
|
type UpsertWorkspaceArgs = {
|
|
workspace: Workspace
|
|
}
|
|
|
|
export type UpsertWorkspace = (args: UpsertWorkspaceArgs) => Promise<void>
|
|
|
|
type GetWorkspaceArgs = {
|
|
workspaceId: string
|
|
}
|
|
|
|
export type GetWorkspace = (args: GetWorkspaceArgs) => Promise<Workspace | null>
|
|
|
|
/** Workspace Roles */
|
|
|
|
type DeleteWorkspaceRoleArgs = {
|
|
workspaceId: string
|
|
userId: string
|
|
}
|
|
|
|
export type DeleteWorkspaceRole = (
|
|
args: DeleteWorkspaceRoleArgs
|
|
) => Promise<WorkspaceAcl | null>
|
|
|
|
type GetWorkspaceRolesArgs = {
|
|
workspaceId: string
|
|
}
|
|
|
|
/** Get all roles in a given workspaces. */
|
|
export type GetWorkspaceRoles = (args: GetWorkspaceRolesArgs) => Promise<WorkspaceAcl[]>
|
|
|
|
type GetWorkspaceRoleForUserArgs = {
|
|
userId: string
|
|
workspaceId: string
|
|
}
|
|
|
|
/** Get role for given user in a specific workspace. */
|
|
export type GetWorkspaceRoleForUser = (
|
|
args: GetWorkspaceRoleForUserArgs
|
|
) => Promise<WorkspaceAcl | null>
|
|
|
|
type GetWorkspaceRolesForUserArgs = {
|
|
userId: string
|
|
}
|
|
|
|
type GetWorkspaceRolesForUserOptions = {
|
|
/** If provided, limit results to roles in given workspaces. */
|
|
workspaceIdFilter?: string[]
|
|
}
|
|
|
|
/** Get roles for given user across several (or all) workspaces. */
|
|
export type GetWorkspaceRolesForUser = (
|
|
args: GetWorkspaceRolesForUserArgs,
|
|
options?: GetWorkspaceRolesForUserOptions
|
|
) => Promise<WorkspaceAcl[]>
|
|
|
|
export type UpsertWorkspaceRole = (args: WorkspaceAcl) => Promise<void>
|
|
|
|
/** Workspace Projects */
|
|
|
|
type GetAllWorkspaceProjectsForUserArgs = {
|
|
userId: string
|
|
workspaceId: string
|
|
}
|
|
|
|
export type GetAllWorkspaceProjectsForUser = (
|
|
args: GetAllWorkspaceProjectsForUserArgs
|
|
) => Promise<StreamRecord[]>
|
|
|
|
/** Workspace Project Roles */
|
|
|
|
type GrantWorkspaceProjectRolesArgs = {
|
|
projectId: string
|
|
workspaceId: string
|
|
}
|
|
|
|
export type GrantWorkspaceProjectRoles = (
|
|
args: GrantWorkspaceProjectRolesArgs
|
|
) => Promise<void>
|
|
|
|
/** Blob */
|
|
|
|
export type StoreBlob = (args: string) => Promise<string>
|
|
|
|
/** Events */
|
|
|
|
export type EmitWorkspaceEvent = <TEvent extends WorkspaceEvents>(args: {
|
|
eventName: TEvent
|
|
payload: WorkspaceEventsPayloads[TEvent]
|
|
}) => Promise<unknown[]>
|