-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor workflows endpoints for user management #2676
Changes from all commits
cce42ce
db295ee
0e4ff05
cd5b25d
6a6100d
39a79c8
8d17b4a
ad7f9a1
e0694b0
5d0f424
b36af77
6a258d1
8070965
8e84de2
def8a60
67a5f2c
9e5df24
57037cf
ce4529d
2adb049
6a753a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable import/no-cycle */ | ||
/* eslint-disable prefer-spread */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
/* eslint-disable no-param-reassign */ | ||
|
@@ -47,6 +48,9 @@ import { | |
WorkflowRunner, | ||
} from '.'; | ||
import config = require('../config'); | ||
import { User } from './databases/entities/User'; | ||
import { whereClause } from './WorkflowHelpers'; | ||
import { WorkflowEntity } from './databases/entities/WorkflowEntity'; | ||
|
||
const WEBHOOK_PROD_UNREGISTERED_HINT = `The workflow must be active for a production URL to run successfully. You can activate the workflow using the toggle in the top-right of the editor. Note that unlike test URL calls, production URL calls aren't shown on the canvas (only in the executions list)`; | ||
|
||
|
@@ -333,20 +337,30 @@ export class ActiveWorkflowRunner { | |
* @returns {string[]} | ||
* @memberof ActiveWorkflowRunner | ||
*/ | ||
async getActiveWorkflows(userId?: string): Promise<IWorkflowDb[]> { | ||
// TODO UM: make userId mandatory? | ||
const queryBuilder = Db.collections.Workflow!.createQueryBuilder('w'); | ||
queryBuilder.andWhere('active = :active', { active: true }); | ||
queryBuilder.select('w.id'); | ||
if (userId) { | ||
queryBuilder.innerJoin('w.shared', 'shared'); | ||
queryBuilder.andWhere('shared.user = :userId', { userId }); | ||
async getActiveWorkflows(user?: User): Promise<IWorkflowDb[]> { | ||
let activeWorkflows: WorkflowEntity[] = []; | ||
|
||
if (!user || user.globalRole.name === 'owner') { | ||
activeWorkflows = await Db.collections.Workflow!.find({ | ||
select: ['id'], | ||
where: { active: true }, | ||
}); | ||
} else { | ||
const shared = await Db.collections.SharedWorkflow!.find({ | ||
relations: ['workflow'], | ||
where: whereClause({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to have possibly additional filters to this whereClause allowing us to use I know the Let me know if you think we should change this now or merge first and then make all changes at once when refactoring code to centralize these helpers into a model-like class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, let's do away with |
||
user, | ||
entityType: 'workflow', | ||
}), | ||
}); | ||
|
||
activeWorkflows = shared.reduce<WorkflowEntity[]>((acc, cur) => { | ||
if (cur.workflow.active) acc.push(cur.workflow); | ||
return acc; | ||
}, []); | ||
} | ||
|
||
const activeWorkflows = (await queryBuilder.getMany()) as IWorkflowDb[]; | ||
return activeWorkflows.filter( | ||
(workflow) => this.activationErrors[workflow.id.toString()] === undefined, | ||
); | ||
return activeWorkflows.filter((workflow) => this.activationErrors[workflow.id] === undefined); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, optional
user
sincegetActiveWorkflows()
is used without arg byremoveAll()
, which is used instart.ts
,ActiveWorkflowRunner.ts
, andTestWebhooks.ts
. Delving there would increase the scope of the PR.