perf(core): Cache roles (#6803)

* refactor: Create `RoleService`

* refactor: Refactor to use service

* refactor: Move `getUserRoleForWorkflow`

* refactor: Clear out old `RoleService`

* refactor: Consolidate utils into service

* refactor: Remove unused methods

* test: Add tests

* refactor: Remove redundant return types

* refactor: Missing utility

* chore: Remove commented out bit

* refactor: Make `Db.collections.Repository` inaccessible

* chore: Cleanup

* feat: Prepopulate cache

* chore: Remove logging

* fix: Account for tests where roles are undefined

* fix: Restore `prettier.prettierPath`

* test: Account for cache enabled and disabled

* fix: Restore `Role` in `Db.collections`

* refactor: Simplify by removing `orFail`

* refactor: Rename for clarity

* refactor: Use `cacheKey` for readability

* refactor: Validate role before creation

* refacator: Remove redundant `cache` prefix

* ci: Lint fix

* test: Fix e2e
This commit is contained in:
Iván Ovejero
2023-08-03 08:58:36 +02:00
committed by GitHub
parent f93270abd5
commit e4f041815a
33 changed files with 280 additions and 214 deletions

View File

@@ -9,51 +9,7 @@ export class RoleRepository extends Repository<Role> {
super(Role, dataSource.manager);
}
async findGlobalOwnerRole(): Promise<Role | null> {
return this.findRole('global', 'owner');
}
async findGlobalOwnerRoleOrFail(): Promise<Role> {
return this.findRoleOrFail('global', 'owner');
}
async findGlobalMemberRole(): Promise<Role | null> {
return this.findRole('global', 'member');
}
async findGlobalMemberRoleOrFail(): Promise<Role> {
return this.findRoleOrFail('global', 'member');
}
async findWorkflowOwnerRole(): Promise<Role | null> {
return this.findRole('workflow', 'owner');
}
async findWorkflowOwnerRoleOrFail(): Promise<Role> {
return this.findRoleOrFail('workflow', 'owner');
}
async findWorkflowEditorRoleOrFail(): Promise<Role> {
return this.findRoleOrFail('workflow', 'editor');
}
async findCredentialOwnerRole(): Promise<Role | null> {
return this.findRole('credential', 'owner');
}
async findCredentialOwnerRoleOrFail(): Promise<Role> {
return this.findRoleOrFail('credential', 'owner');
}
async findCredentialUserRole(): Promise<Role | null> {
return this.findRole('credential', 'user');
}
async findRole(scope: RoleScopes, name: RoleNames): Promise<Role | null> {
async findRole(scope: RoleScopes, name: RoleNames) {
return this.findOne({ where: { scope, name } });
}
async findRoleOrFail(scope: RoleScopes, name: RoleNames): Promise<Role> {
return this.findOneOrFail({ where: { scope, name } });
}
}