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)
|
||||
.throwIfNotFound();
|
||||
|
||||
const stepData = 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);
|
||||
step = await step.updateFor(request.currentUser, stepParams(request));
|
||||
|
||||
renderObject(response, step);
|
||||
};
|
||||
|
@@ -335,9 +335,18 @@ class Step extends Base {
|
||||
await Promise.all(nextStepQueries);
|
||||
}
|
||||
|
||||
async update(newStepData) {
|
||||
async updateFor(user, 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) {
|
||||
await App.checkAppAndTrigger(appKey, key);
|
||||
}
|
||||
|
Reference in New Issue
Block a user