mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(core): Ensure getSharedWorkflowIds returns string[] instead of number[] (#4971)
* 🔨 - getSharedWorkflowIds returns string[] * 🔨 - update the sharedWorkflow function in public api * 🔨 - update existing code to handle new data type * simplify code Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
445463a605
commit
60b14116f0
|
@ -123,7 +123,7 @@ export async function getExecutionsCount(data: {
|
||||||
|
|
||||||
export async function getExecutionInWorkflows(
|
export async function getExecutionInWorkflows(
|
||||||
id: number,
|
id: number,
|
||||||
workflows: number[],
|
workflows: string[],
|
||||||
includeData?: boolean,
|
includeData?: boolean,
|
||||||
): Promise<IExecutionResponseApi | undefined> {
|
): Promise<IExecutionResponseApi | undefined> {
|
||||||
const execution = await Db.collections.Execution.findOne({
|
const execution = await Db.collections.Execution.findOne({
|
||||||
|
|
|
@ -15,12 +15,12 @@ function insertIf(condition: boolean, elements: string[]): string[] {
|
||||||
return condition ? elements : [];
|
return condition ? elements : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSharedWorkflowIds(user: User): Promise<number[]> {
|
export async function getSharedWorkflowIds(user: User): Promise<string[]> {
|
||||||
const sharedWorkflows = await Db.collections.SharedWorkflow.find({
|
const sharedWorkflows = await Db.collections.SharedWorkflow.find({
|
||||||
where: { user },
|
where: { user },
|
||||||
});
|
});
|
||||||
|
|
||||||
return sharedWorkflows.map((workflow) => workflow.workflowId);
|
return sharedWorkflows.map(({ workflowId }) => workflowId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSharedWorkflow(
|
export async function getSharedWorkflow(
|
||||||
|
|
|
@ -1345,9 +1345,7 @@ class App {
|
||||||
|
|
||||||
const filter = req.query.filter ? jsonParse<any>(req.query.filter) : {};
|
const filter = req.query.filter ? jsonParse<any>(req.query.filter) : {};
|
||||||
|
|
||||||
const sharedWorkflowIds = await getSharedWorkflowIds(req.user).then((ids) =>
|
const sharedWorkflowIds = await getSharedWorkflowIds(req.user);
|
||||||
ids.map((id) => id.toString()),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const data of executingWorkflows) {
|
for (const data of executingWorkflows) {
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -405,13 +405,13 @@ export async function replaceInvalidCredentials(workflow: WorkflowEntity): Promi
|
||||||
* Get the IDs of the workflows that have been shared with the user.
|
* Get the IDs of the workflows that have been shared with the user.
|
||||||
* Returns all IDs if user is global owner (see `whereClause`)
|
* Returns all IDs if user is global owner (see `whereClause`)
|
||||||
*/
|
*/
|
||||||
export async function getSharedWorkflowIds(user: User, roles?: string[]): Promise<number[]> {
|
export async function getSharedWorkflowIds(user: User, roles?: string[]): Promise<string[]> {
|
||||||
const sharedWorkflows = await Db.collections.SharedWorkflow.find({
|
const sharedWorkflows = await Db.collections.SharedWorkflow.find({
|
||||||
relations: ['workflow', 'role'],
|
relations: ['workflow', 'role'],
|
||||||
where: whereClause({ user, entityType: 'workflow', roles }),
|
where: whereClause({ user, entityType: 'workflow', roles }),
|
||||||
});
|
});
|
||||||
|
|
||||||
return sharedWorkflows.map(({ workflow }) => workflow.id);
|
return sharedWorkflows.map(({ workflowId }) => workflowId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,7 @@ export class EEExecutionsService extends ExecutionsService {
|
||||||
/**
|
/**
|
||||||
* Function to get the workflow Ids for a User regardless of role
|
* Function to get the workflow Ids for a User regardless of role
|
||||||
*/
|
*/
|
||||||
static async getWorkflowIdsForUser(user: User): Promise<number[]> {
|
static async getWorkflowIdsForUser(user: User): Promise<string[]> {
|
||||||
// Get all workflows
|
// Get all workflows
|
||||||
return getSharedWorkflowIds(user);
|
return getSharedWorkflowIds(user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ export class ExecutionsService {
|
||||||
* Function to get the workflow Ids for a User
|
* Function to get the workflow Ids for a User
|
||||||
* Overridden in EE version to ignore roles
|
* Overridden in EE version to ignore roles
|
||||||
*/
|
*/
|
||||||
static async getWorkflowIdsForUser(user: User): Promise<number[]> {
|
static async getWorkflowIdsForUser(user: User): Promise<string[]> {
|
||||||
// Get all workflows using owner role
|
// Get all workflows using owner role
|
||||||
return getSharedWorkflowIds(user, ['owner']);
|
return getSharedWorkflowIds(user, ['owner']);
|
||||||
}
|
}
|
||||||
|
@ -160,9 +160,8 @@ export class ExecutionsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// safeguard against querying workflowIds not shared with the user
|
// safeguard against querying workflowIds not shared with the user
|
||||||
if (filter?.workflowId !== undefined) {
|
const workflowId = filter?.workflowId?.toString();
|
||||||
const workflowId = parseInt(filter.workflowId.toString());
|
if (workflowId !== undefined && !sharedWorkflowIds.includes(workflowId)) {
|
||||||
if (workflowId && !sharedWorkflowIds.includes(workflowId)) {
|
|
||||||
LoggerProxy.verbose(
|
LoggerProxy.verbose(
|
||||||
`User ${req.user.id} attempted to query non-shared workflow ${workflowId}`,
|
`User ${req.user.id} attempted to query non-shared workflow ${workflowId}`,
|
||||||
);
|
);
|
||||||
|
@ -172,7 +171,6 @@ export class ExecutionsService {
|
||||||
results: [],
|
results: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const limit = req.query.limit
|
const limit = req.query.limit
|
||||||
? parseInt(req.query.limit, 10)
|
? parseInt(req.query.limit, 10)
|
||||||
|
|
|
@ -116,7 +116,7 @@ export class WorkflowsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warning: this function is overriden by EE to disregard role list.
|
// Warning: this function is overriden by EE to disregard role list.
|
||||||
static async getWorkflowIdsForUser(user: User, roles?: string[]) {
|
static async getWorkflowIdsForUser(user: User, roles?: string[]): Promise<string[]> {
|
||||||
return getSharedWorkflowIds(user, roles);
|
return getSharedWorkflowIds(user, roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,13 +152,11 @@ export class WorkflowsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// safeguard against querying ids not shared with the user
|
// safeguard against querying ids not shared with the user
|
||||||
if (filter?.id !== undefined) {
|
const workflowId = filter?.id?.toString();
|
||||||
const workflowId = parseInt(filter.id.toString());
|
if (workflowId !== undefined && !sharedWorkflowIds.includes(workflowId)) {
|
||||||
if (workflowId && !sharedWorkflowIds.includes(workflowId)) {
|
|
||||||
LoggerProxy.verbose(`User ${user.id} attempted to query non-shared workflow ${workflowId}`);
|
LoggerProxy.verbose(`User ${user.id} attempted to query non-shared workflow ${workflowId}`);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const fields: Array<keyof WorkflowEntity> = ['id', 'name', 'active', 'createdAt', 'updatedAt'];
|
const fields: Array<keyof WorkflowEntity> = ['id', 'name', 'active', 'createdAt', 'updatedAt'];
|
||||||
const relations: string[] = [];
|
const relations: string[] = [];
|
||||||
|
|
Loading…
Reference in a new issue