diff --git a/src/Controllers/LinkFieldController.php b/src/Controllers/LinkFieldController.php index 2e5bb2bc..6e1c1f73 100644 --- a/src/Controllers/LinkFieldController.php +++ b/src/Controllers/LinkFieldController.php @@ -132,15 +132,12 @@ public function linkDelete(): HTTPResponse $this->jsonError(400); } $link = $this->linkFromRequest(); + if (!$link->canDelete()) { + $this->jsonError(403); + } if ($link->hasExtension(Versioned::class)) { - if (!$link->canArchive()) { - $this->jsonError(403); - } $link->doArchive(); } else { - if (!$link->canDelete()) { - $this->jsonError(403); - } $link->delete(); } // Send response diff --git a/tests/php/Controllers/LinkFieldControllerTest.php b/tests/php/Controllers/LinkFieldControllerTest.php index c806bfb8..188b4746 100644 --- a/tests/php/Controllers/LinkFieldControllerTest.php +++ b/tests/php/Controllers/LinkFieldControllerTest.php @@ -538,12 +538,6 @@ public function testLinkArchive( int $expectedCode ): void { TestPhoneLink::$fail = $fail; - if ($fail == 'can-delete') { - // Remove the Versioned extension because there's logic in LinkFieldController - // to use either canArchive() or canDelete() based on the presence of the Versioned extension - // Note that you must remove the extension on the base class rather than a TestOnly subclass - Link::remove_extension(Versioned::class); - } $owner = $this->getFixtureLinkOwner(); $ownerID = $owner->ID; $ownerClass = urlencode($owner->ClassName); @@ -581,11 +575,6 @@ public function provideLinkArchive(): array 'fail' => '', 'expectedCode' => 204, ], - 'Reject fail canArchive()' => [ - 'idType' => 'existing', - 'fail' => 'can-archive', - 'expectedCode' => 403, - ], 'Reject fail canDelete()' => [ 'idType' => 'existing', 'fail' => 'can-delete', diff --git a/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php b/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php index b1f39bfa..c740e1e1 100644 --- a/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php +++ b/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php @@ -43,11 +43,6 @@ 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();