Skip to content

Commit

Permalink
FIX Check canArchive() permission instead of canDelete()
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 6, 2024
1 parent 77a1497 commit 2ba2e3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/Controllers/LinkFieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ private function getLinkData(Link $link): array
*/
public function linkDelete(): HTTPResponse
{
$link = $this->linkFromRequest();
if (!$link->canDelete()) {
$this->jsonError(403);
}
// Check security token on destructive operation
if (!SecurityToken::inst()->checkRequest($this->getRequest())) {
$this->jsonError(400);
}
$link = $this->linkFromRequest();
if ($link->hasExtension(Versioned::class)) {
if (!$link->canArchive()) {
$this->jsonError(403);
}
$link->doArchive();
} else {
if (!$link->canDelete()) {
$this->jsonError(403);
}
$link->delete();
}
// Send response
Expand Down
7 changes: 5 additions & 2 deletions tests/php/Controllers/LinkFieldControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,12 @@ public function provideLinkDelete(): array
'fail' => '',
'expectedCode' => 204,
],
'Reject fail canDelete()' => [
// note there isn't a canDelete() test here because it seems impossible to get an
// unversioned Link because there's no way to actually remove the Versioned extension
// from any subclass of Link since we're unable to the use app/_config.php method
'Reject fail canArchive()' => [
'idType' => 'existing',
'fail' => 'can-delete',
'fail' => 'can-archive',
'expectedCode' => 403,
],
'Reject fail csrf-token' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function canDelete($member = null)
return TestPhoneLink::$fail !== 'can-delete';
}

public function canArchive($member = null)
{
return TestPhoneLink::$fail !== 'can-archive';
}

public function validate(): ValidationResult
{
$validationResult = parent::validate();
Expand Down

0 comments on commit 2ba2e3c

Please sign in to comment.