mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
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:
@@ -20,7 +20,6 @@ import type { Role } from '@db/entities/Role';
|
||||
import type { TagEntity } from '@db/entities/TagEntity';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import { RoleRepository } from '@db/repositories';
|
||||
import type { ICredentialsDb } from '@/Interfaces';
|
||||
|
||||
import { DB_INITIALIZATION_TIMEOUT } from './constants';
|
||||
@@ -34,6 +33,7 @@ import type {
|
||||
} from './types';
|
||||
import type { ExecutionData } from '@db/entities/ExecutionData';
|
||||
import { generateNanoId } from '@db/utils/generators';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
import { VariablesService } from '@/environments/variables/variables.service';
|
||||
|
||||
export type TestDBType = 'postgres' | 'mysql';
|
||||
@@ -151,7 +151,7 @@ export async function saveCredential(
|
||||
}
|
||||
|
||||
export async function shareCredentialWithUsers(credential: CredentialsEntity, users: User[]) {
|
||||
const role = await Container.get(RoleRepository).findCredentialUserRole();
|
||||
const role = await Container.get(RoleService).findCredentialUserRole();
|
||||
const newSharedCredentials = users.map((user) =>
|
||||
Db.collections.SharedCredentials.create({
|
||||
userId: user.id,
|
||||
@@ -276,23 +276,23 @@ export async function addApiKey(user: User): Promise<User> {
|
||||
// ----------------------------------
|
||||
|
||||
export async function getGlobalOwnerRole() {
|
||||
return Container.get(RoleRepository).findGlobalOwnerRoleOrFail();
|
||||
return Container.get(RoleService).findGlobalOwnerRole();
|
||||
}
|
||||
|
||||
export async function getGlobalMemberRole() {
|
||||
return Container.get(RoleRepository).findGlobalMemberRoleOrFail();
|
||||
return Container.get(RoleService).findGlobalMemberRole();
|
||||
}
|
||||
|
||||
export async function getWorkflowOwnerRole() {
|
||||
return Container.get(RoleRepository).findWorkflowOwnerRoleOrFail();
|
||||
return Container.get(RoleService).findWorkflowOwnerRole();
|
||||
}
|
||||
|
||||
export async function getWorkflowEditorRole() {
|
||||
return Container.get(RoleRepository).findWorkflowEditorRoleOrFail();
|
||||
return Container.get(RoleService).findWorkflowEditorRole();
|
||||
}
|
||||
|
||||
export async function getCredentialOwnerRole() {
|
||||
return Container.get(RoleRepository).findCredentialOwnerRoleOrFail();
|
||||
return Container.get(RoleService).findCredentialOwnerRole();
|
||||
}
|
||||
|
||||
export async function getAllRoles() {
|
||||
|
||||
Reference in New Issue
Block a user