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(
|
||||
id: number,
|
||||
workflows: number[],
|
||||
workflows: string[],
|
||||
includeData?: boolean,
|
||||
): Promise<IExecutionResponseApi | undefined> {
|
||||
const execution = await Db.collections.Execution.findOne({
|
||||
|
|
|
@ -15,12 +15,12 @@ function insertIf(condition: boolean, elements: string[]): string[] {
|
|||
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({
|
||||
where: { user },
|
||||
});
|
||||
|
||||
return sharedWorkflows.map((workflow) => workflow.workflowId);
|
||||
return sharedWorkflows.map(({ workflowId }) => workflowId.toString());
|
||||
}
|
||||
|
||||
export async function getSharedWorkflow(
|
||||
|
|
|
@ -1345,9 +1345,7 @@ class App {
|
|||
|
||||
const filter = req.query.filter ? jsonParse<any>(req.query.filter) : {};
|
||||
|
||||
const sharedWorkflowIds = await getSharedWorkflowIds(req.user).then((ids) =>
|
||||
ids.map((id) => id.toString()),
|
||||
);
|
||||
const sharedWorkflowIds = await getSharedWorkflowIds(req.user);
|
||||
|
||||
for (const data of executingWorkflows) {
|
||||
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.
|
||||
* 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({
|
||||
relations: ['workflow', 'role'],
|
||||
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
|
||||
*/
|
||||
static async getWorkflowIdsForUser(user: User): Promise<number[]> {
|
||||
static async getWorkflowIdsForUser(user: User): Promise<string[]> {
|
||||
// Get all workflows
|
||||
return getSharedWorkflowIds(user);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ export class ExecutionsService {
|
|||
* Function to get the workflow Ids for a User
|
||||
* 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
|
||||
return getSharedWorkflowIds(user, ['owner']);
|
||||
}
|
||||
|
@ -160,18 +160,16 @@ export class ExecutionsService {
|
|||
}
|
||||
|
||||
// safeguard against querying workflowIds not shared with the user
|
||||
if (filter?.workflowId !== undefined) {
|
||||
const workflowId = parseInt(filter.workflowId.toString());
|
||||
if (workflowId && !sharedWorkflowIds.includes(workflowId)) {
|
||||
LoggerProxy.verbose(
|
||||
`User ${req.user.id} attempted to query non-shared workflow ${workflowId}`,
|
||||
);
|
||||
return {
|
||||
count: 0,
|
||||
estimated: false,
|
||||
results: [],
|
||||
};
|
||||
}
|
||||
const workflowId = filter?.workflowId?.toString();
|
||||
if (workflowId !== undefined && !sharedWorkflowIds.includes(workflowId)) {
|
||||
LoggerProxy.verbose(
|
||||
`User ${req.user.id} attempted to query non-shared workflow ${workflowId}`,
|
||||
);
|
||||
return {
|
||||
count: 0,
|
||||
estimated: false,
|
||||
results: [],
|
||||
};
|
||||
}
|
||||
|
||||
const limit = req.query.limit
|
||||
|
|
|
@ -116,7 +116,7 @@ export class WorkflowsService {
|
|||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -152,12 +152,10 @@ export class WorkflowsService {
|
|||
}
|
||||
|
||||
// safeguard against querying ids not shared with the user
|
||||
if (filter?.id !== undefined) {
|
||||
const workflowId = parseInt(filter.id.toString());
|
||||
if (workflowId && !sharedWorkflowIds.includes(workflowId)) {
|
||||
LoggerProxy.verbose(`User ${user.id} attempted to query non-shared workflow ${workflowId}`);
|
||||
return [];
|
||||
}
|
||||
const workflowId = filter?.id?.toString();
|
||||
if (workflowId !== undefined && !sharedWorkflowIds.includes(workflowId)) {
|
||||
LoggerProxy.verbose(`User ${user.id} attempted to query non-shared workflow ${workflowId}`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const fields: Array<keyof WorkflowEntity> = ['id', 'name', 'active', 'createdAt', 'updatedAt'];
|
||||
|
|
Loading…
Reference in a new issue