From c809e7b00c8d53b1c5e34570ee2be62a537ecd30 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 21 Oct 2021 09:32:47 +0200 Subject: [PATCH] Revert "[8.x] Add gate policy callback (#39185)" This reverts commit 02c5dc5324c9bbb0e816cbe2d6c4d95488af88c0. --- src/Illuminate/Auth/Access/Gate.php | 38 ------------------ .../Auth/Access/AuthorizesRequests.php | 4 -- tests/Auth/AuthAccessGateTest.php | 40 ------------------- .../FoundationAuthorizesRequestsTraitTest.php | 12 ------ 4 files changed, 94 deletions(-) diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index 1746a2ec6f98..75eba1dcea8f 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -279,10 +279,6 @@ public function denies($ability, $arguments = []) */ public function check($abilities, $arguments = []) { - if (is_array($abilities) && class_exists($abilities[0])) { - $abilities = [$abilities]; - } - return collect($abilities)->every(function ($ability) use ($arguments) { return $this->inspect($ability, $arguments)->allowed(); }); @@ -297,13 +293,6 @@ public function check($abilities, $arguments = []) */ public function any($abilities, $arguments = []) { - // Gate::any([Policy::class, ['view', 'create']], $post)... - if (isset($abilities[1]) && is_array($abilities[1])) { - $abilities = collect($abilities[1])->map(function ($ability) use ($abilities) { - return [$abilities[0], $ability]; - })->all(); - } - return collect($abilities)->contains(function ($ability) use ($arguments) { return $this->check($ability, $arguments); }); @@ -567,19 +556,6 @@ protected function resolveAuthCallback($user, $ability, array $arguments) return $callback; } - if (is_array($ability)) { - [$class, $method] = $ability; - - if ($this->canBeCalledWithUser($user, $class, $method)) { - return $this->getCallableFromClassAndMethod($class, $method); - } - } - - if (class_exists($ability) && - $this->canBeCalledWithUser($user, $ability, '__invoke')) { - return $this->getCallableFromClassAndMethod($ability); - } - if (isset($this->stringCallbacks[$ability])) { [$class, $method] = Str::parseCallback($this->stringCallbacks[$ability]); @@ -805,20 +781,6 @@ protected function resolveUser() return call_user_func($this->userResolver); } - /** - * Get a callable from a class and method. - * - * @param string $class - * @param string $method - * @return \Closure - */ - protected function getCallableFromClassAndMethod($class, $method = '__invoke') - { - return function (...$params) use ($class, $method) { - return $this->container->make($class)->{$method}(...$params); - }; - } - /** * Get all of the defined abilities. * diff --git a/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php b/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php index 76b58b30ebaf..85a9596f9c57 100644 --- a/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php +++ b/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php @@ -53,10 +53,6 @@ protected function parseAbilityAndArguments($ability, $arguments) return [$ability, $arguments]; } - if (is_array($ability)) { - return [$ability, $arguments]; - } - $method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['function']; return [$this->normalizeGuessedAbilityName($method), $ability]; diff --git a/tests/Auth/AuthAccessGateTest.php b/tests/Auth/AuthAccessGateTest.php index 8660b465127a..c9c0d7d08ef2 100644 --- a/tests/Auth/AuthAccessGateTest.php +++ b/tests/Auth/AuthAccessGateTest.php @@ -759,46 +759,6 @@ public function testEveryAbilityCheckFailsIfNonePass() $this->assertFalse($gate->check(['edit', 'update'], new AccessGateTestDummy)); } - public function testInspectPolicyCallback() - { - $gate = $this->getBasicGate(); - - $response = $gate->inspect([AccessGateTestPolicyWithAllPermissions::class, 'edit'], new AccessGateTestDummy); - - $this->assertFalse($response->denied()); - $this->assertTrue($response->allowed()); - } - - public function testInspectPolicyCallbackInvoke() - { - $gate = $this->getBasicGate(); - - $response = $gate->inspect(AccessGateTestGuestInvokableClass::class, new AccessGateTestDummy); - - $this->assertFalse($response->denied()); - $this->assertTrue($response->allowed()); - } - - public function testCheckUsingPolicyCallback() - { - $gate = $this->getBasicGate(); - - $this->assertTrue($gate->check( - [AccessGateTestPolicyWithAllPermissions::class, 'edit'], - new AccessGateTestDummy) - ); - } - - public function testAnyUsingPolicyCallback() - { - $gate = $this->getBasicGate(); - - $this->assertTrue($gate->any( - [AccessGateTestPolicyWithAllPermissions::class, ['edit', 'update']], - new AccessGateTestDummy) - ); - } - /** * @dataProvider hasAbilitiesTestDataProvider * diff --git a/tests/Foundation/FoundationAuthorizesRequestsTraitTest.php b/tests/Foundation/FoundationAuthorizesRequestsTraitTest.php index 57c829df111f..1005103aaf66 100644 --- a/tests/Foundation/FoundationAuthorizesRequestsTraitTest.php +++ b/tests/Foundation/FoundationAuthorizesRequestsTraitTest.php @@ -17,18 +17,6 @@ protected function tearDown(): void Container::setInstance(null); } - public function testCallableGateCheck() - { - unset($_SERVER['_test.authorizes.trait']); - - $gate = $this->getBasicGate(); - - $response = (new FoundationTestAuthorizeTraitClass)->authorize([FoundationAuthorizesRequestTestPolicy::class, 'create']); - - $this->assertInstanceOf(Response::class, $response); - $this->assertTrue($_SERVER['_test.authorizes.trait.policy']); - } - public function testBasicGateCheck() { unset($_SERVER['_test.authorizes.trait']);