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>
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { moduleLogger } from '@/logging/logging'
|
|
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
|
|
import { registerOrUpdateScopeFactory } from '@/modules/shared/repositories/scopes'
|
|
import db from '@/db/knex'
|
|
import { SpeckleModule } from '@/modules/shared/helpers/typeHelper'
|
|
import { workspaceRoles } from '@/modules/workspaces/roles'
|
|
import { workspaceScopes } from '@/modules/workspaces/scopes'
|
|
import { registerOrUpdateRole } from '@/modules/shared/repositories/roles'
|
|
import { initializeEventListenersFactory } from '@/modules/workspaces/events/eventListener'
|
|
|
|
const { FF_WORKSPACES_MODULE_ENABLED } = getFeatureFlags()
|
|
|
|
const initScopes = () => {
|
|
const registerFunc = registerOrUpdateScopeFactory({ db })
|
|
return Promise.all(workspaceScopes.map((scope) => registerFunc({ scope })))
|
|
}
|
|
|
|
const initRoles = () => {
|
|
const registerFunc = registerOrUpdateRole({ db })
|
|
return Promise.all(workspaceRoles.map((role) => registerFunc({ role })))
|
|
}
|
|
|
|
const workspacesModule: SpeckleModule = {
|
|
async init(_, isInitial) {
|
|
if (!FF_WORKSPACES_MODULE_ENABLED) return
|
|
moduleLogger.info('⚒️ Init workspaces module')
|
|
if (isInitial) {
|
|
initializeEventListenersFactory({ db })()
|
|
}
|
|
await Promise.all([initScopes(), initRoles()])
|
|
}
|
|
}
|
|
|
|
export = workspacesModule
|