mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Remove roleId indirection (no-changelog) (#8413)
This commit is contained in:
committed by
GitHub
parent
1affebd85e
commit
d6deceacde
@@ -1,31 +1,25 @@
|
||||
import { Service } from 'typedi';
|
||||
import { In, type FindOptionsWhere } from 'typeorm';
|
||||
|
||||
import type { RoleNames } from '@db/entities/Role';
|
||||
import type { SharedWorkflow } from '@db/entities/SharedWorkflow';
|
||||
import type { SharedWorkflow, WorkflowSharingRole } from '@db/entities/SharedWorkflow';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { RoleRepository } from '@db/repositories/role.repository';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
|
||||
@Service()
|
||||
export class WorkflowSharingService {
|
||||
constructor(
|
||||
private readonly roleRepository: RoleRepository,
|
||||
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
|
||||
) {}
|
||||
constructor(private readonly sharedWorkflowRepository: SharedWorkflowRepository) {}
|
||||
|
||||
/**
|
||||
* Get the IDs of the workflows that have been shared with the user.
|
||||
* Returns all IDs if user has the 'workflow:read' scope.
|
||||
*/
|
||||
async getSharedWorkflowIds(user: User, roleNames?: RoleNames[]): Promise<string[]> {
|
||||
async getSharedWorkflowIds(user: User, roles?: WorkflowSharingRole[]): Promise<string[]> {
|
||||
const where: FindOptionsWhere<SharedWorkflow> = {};
|
||||
if (!user.hasGlobalScope('workflow:read')) {
|
||||
where.userId = user.id;
|
||||
}
|
||||
if (roleNames?.length) {
|
||||
const roleIds = await this.roleRepository.getIdsInScopeWorkflowByNames(roleNames);
|
||||
where.roleId = In(roleIds);
|
||||
if (roles?.length) {
|
||||
where.role = In(roles);
|
||||
}
|
||||
const sharedWorkflows = await this.sharedWorkflowRepository.find({
|
||||
where,
|
||||
|
||||
Reference in New Issue
Block a user