fix: let permitted users delete others' flows (#1417)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
|
import Flow from '../../models/flow';
|
||||||
import Execution from '../../models/execution';
|
import Execution from '../../models/execution';
|
||||||
import ExecutionStep from '../../models/execution-step';
|
import ExecutionStep from '../../models/execution-step';
|
||||||
import globalVariable from '../../helpers/global-variable';
|
import globalVariable from '../../helpers/global-variable';
|
||||||
@@ -15,10 +16,13 @@ const deleteFlow = async (
|
|||||||
params: Params,
|
params: Params,
|
||||||
context: Context
|
context: Context
|
||||||
) => {
|
) => {
|
||||||
context.currentUser.can('delete', 'Flow');
|
const conditions = context.currentUser.can('delete', 'Flow');
|
||||||
|
const isCreator = conditions.isCreator;
|
||||||
|
const allFlows = Flow.query();
|
||||||
|
const userFlows = context.currentUser.$relatedQuery('flows');
|
||||||
|
const baseQuery = isCreator ? userFlows : allFlows;
|
||||||
|
|
||||||
const flow = await context.currentUser
|
const flow = await baseQuery
|
||||||
.$relatedQuery('flows')
|
|
||||||
.findOne({
|
.findOne({
|
||||||
id: params.input.id,
|
id: params.input.id,
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user