mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-24 19:10:53 +02:00
31 lines
900 B
TypeScript
31 lines
900 B
TypeScript
import type { User } from '@n8n/db';
|
|
import { UserRepository } from '@n8n/db';
|
|
import { Service } from '@n8n/di';
|
|
import type { Workflow } from 'n8n-workflow';
|
|
|
|
import { WorkflowFinderService } from '@/workflows/workflow-finder.service';
|
|
|
|
/**
|
|
* Responsible for checking whether a user has access to a resource.
|
|
*/
|
|
@Service()
|
|
export class AccessService {
|
|
constructor(
|
|
private readonly userRepository: UserRepository,
|
|
private readonly workflowFinderService: WorkflowFinderService,
|
|
) {}
|
|
|
|
/** Whether a user has read access to a workflow based on their project and scope. */
|
|
async hasReadAccess(userId: User['id'], workflowId: Workflow['id']) {
|
|
const user = await this.userRepository.findOneBy({ id: userId });
|
|
|
|
if (!user) return false;
|
|
|
|
const workflow = await this.workflowFinderService.findWorkflowForUser(workflowId, user, [
|
|
'workflow:read',
|
|
]);
|
|
|
|
return workflow !== null;
|
|
}
|
|
}
|