refactor(update-step): move connection authorization to model
This commit is contained in:
@@ -5,18 +5,7 @@ export default async (request, response) => {
|
|||||||
.findById(request.params.stepId)
|
.findById(request.params.stepId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
const stepData = stepParams(request);
|
step = await step.updateFor(request.currentUser, stepParams(request));
|
||||||
|
|
||||||
if (stepData.connectionId && (stepData.appKey || step.appKey)) {
|
|
||||||
await request.currentUser.authorizedConnections
|
|
||||||
.findOne({
|
|
||||||
id: stepData.connectionId,
|
|
||||||
key: stepData.appKey || step.appKey,
|
|
||||||
})
|
|
||||||
.throwIfNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
step = await step.update(stepData);
|
|
||||||
|
|
||||||
renderObject(response, step);
|
renderObject(response, step);
|
||||||
};
|
};
|
||||||
|
@@ -335,9 +335,18 @@ class Step extends Base {
|
|||||||
await Promise.all(nextStepQueries);
|
await Promise.all(nextStepQueries);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(newStepData) {
|
async updateFor(user, newStepData) {
|
||||||
const { connectionId, appKey, key, parameters } = newStepData;
|
const { connectionId, appKey, key, parameters } = newStepData;
|
||||||
|
|
||||||
|
if (connectionId && (appKey || this.appKey)) {
|
||||||
|
await user.authorizedConnections
|
||||||
|
.findOne({
|
||||||
|
id: connectionId,
|
||||||
|
key: appKey || this.appKey,
|
||||||
|
})
|
||||||
|
.throwIfNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isTrigger && appKey && key) {
|
if (this.isTrigger && appKey && key) {
|
||||||
await App.checkAppAndTrigger(appKey, key);
|
await App.checkAppAndTrigger(appKey, key);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user