Skip to content

Commit

Permalink
API Deletes trigger archive instead of delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Oct 21, 2016
1 parent eedc806 commit f859464
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions code/Controller/AssetAdmin.php
Expand Up @@ -234,7 +234,7 @@ public function apiReadFolder(HTTPRequest $request)
'parentID' => $folder->exists() ? $folder->ParentID : null, // grandparent
'folderID' => $folderID,
'canEdit' => $folder->canEdit(),
'canDelete' => $folder->canDelete(),
'canDelete' => $folder->canArchive(),
]));

return $response;
Expand Down Expand Up @@ -292,15 +292,15 @@ public function apiDelete(HTTPRequest $request)
}

if (!min(array_map(function (File $file) {
return $file->canDelete();
return $file->canArchive();
}, $files))) {
return (new HTTPResponse(json_encode(['status' => 'error']), 401))
->addHeader('Content-Type', 'application/json');
}

/** @var File $file */
foreach ($files as $file) {
$file->delete();
$file->doArchive();
}

return (new HTTPResponse(json_encode(['status' => 'file was deleted'])))
Expand Down Expand Up @@ -768,7 +768,7 @@ protected function getObjectFromData(File $file)
'modified' => $file->isModifiedOnDraft(),
'draft' => $file->isOnDraftOnly(),
'canEdit' => $file->canEdit(),
'canDelete' => $file->canDelete(),
'canDelete' => $file->canArchive(),
);

/** @var Member $owner */
Expand Down
8 changes: 8 additions & 0 deletions tests/php/AssetAdminTest.php
Expand Up @@ -502,6 +502,14 @@ public function canDelete($member = null)
}
}

public function canArchive($member = null)
{
if ($this->owner->Name === 'disallowCanDelete.txt') {
return false;
}
return $this->owner->canDelete($member);
}

public function canCreate($member = null, $context = [])
{
if (isset($context['Parent']) && $context['Parent']->Name === 'disallowCanAddChildren') {
Expand Down

0 comments on commit f859464

Please sign in to comment.