Skip to content

Commit

Permalink
[Mutation] Fix asset delete by id or fullpath
Browse files Browse the repository at this point in the history
  • Loading branch information
dvesh3 committed Sep 13, 2023
1 parent 7979d02 commit c70757c
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/GraphQL/Mutation/MutationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1382,31 +1382,38 @@ public function buildDeleteElementMutation(&$config, $context, $type)
'args' => [
'id' => ['type' => Type::int()],
'fullpath' => ['type' => Type::string()],
], 'resolve' => static function ($value, $args, $context, ResolveInfo $info) use ($type, $omitPermissionCheck, $me) {
try {
$id = $args['id'];
/** @var Configuration $configuration */
$configuration = $context['configuration'];
$element = $me->getElementByTypeAndIdOrPath($args, $type);
],
'resolve' => static function ($value, $args)
use ($type, $omitPermissionCheck, $me) {
try {
$idOrPath = $args['id'] ?? ($args['fullpath'] ?? null);
if (!$idOrPath) {
return [
'success' => false,
'message' => 'Missing required field id or fullpath to delete the asset.'
];
}

if (!$omitPermissionCheck && !WorkspaceHelper::checkPermission($element, 'delete')) {
return [
'success' => false,
'message' => 'delete ' . $type . ' permission denied.'
$element = $me->getElementByTypeAndIdOrPath($args, $type);

if (!$omitPermissionCheck && !WorkspaceHelper::checkPermission($element, 'delete')) {
return [
'success' => false,
'message' => 'delete ' . $type . ' permission denied.'
];
}
$result = ['success' => false];
$element->delete();

$result = [
'success' => true,
'message' => $type . ' ' . $idOrPath . ' deleted'
];
} catch (\Exception $e) {
$result['message'] = $e->getMessage();
}
$element->delete();

return [
'success' => true,
'message' => $type . ' ' . $id . ' deleted'
];
} catch (\Exception $e) {
return [
'success' => false,
'message' => $e->getMessage()
];
}
return $result;
}
];

Expand Down

0 comments on commit c70757c

Please sign in to comment.