Skip to content

Commit dade8df

Browse files
authored
Revert "[8.x] Add gate policy callback (#39185)" (#39290)
This reverts commit 02c5dc5.
1 parent 41ac7e8 commit dade8df

File tree

4 files changed

+0
-94
lines changed

4 files changed

+0
-94
lines changed

src/Illuminate/Auth/Access/Gate.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ public function denies($ability, $arguments = [])
279279
*/
280280
public function check($abilities, $arguments = [])
281281
{
282-
if (is_array($abilities) && class_exists($abilities[0])) {
283-
$abilities = [$abilities];
284-
}
285-
286282
return collect($abilities)->every(function ($ability) use ($arguments) {
287283
return $this->inspect($ability, $arguments)->allowed();
288284
});
@@ -297,13 +293,6 @@ public function check($abilities, $arguments = [])
297293
*/
298294
public function any($abilities, $arguments = [])
299295
{
300-
// Gate::any([Policy::class, ['view', 'create']], $post)...
301-
if (isset($abilities[1]) && is_array($abilities[1])) {
302-
$abilities = collect($abilities[1])->map(function ($ability) use ($abilities) {
303-
return [$abilities[0], $ability];
304-
})->all();
305-
}
306-
307296
return collect($abilities)->contains(function ($ability) use ($arguments) {
308297
return $this->check($ability, $arguments);
309298
});
@@ -567,19 +556,6 @@ protected function resolveAuthCallback($user, $ability, array $arguments)
567556
return $callback;
568557
}
569558

570-
if (is_array($ability)) {
571-
[$class, $method] = $ability;
572-
573-
if ($this->canBeCalledWithUser($user, $class, $method)) {
574-
return $this->getCallableFromClassAndMethod($class, $method);
575-
}
576-
}
577-
578-
if (class_exists($ability) &&
579-
$this->canBeCalledWithUser($user, $ability, '__invoke')) {
580-
return $this->getCallableFromClassAndMethod($ability);
581-
}
582-
583559
if (isset($this->stringCallbacks[$ability])) {
584560
[$class, $method] = Str::parseCallback($this->stringCallbacks[$ability]);
585561

@@ -805,20 +781,6 @@ protected function resolveUser()
805781
return call_user_func($this->userResolver);
806782
}
807783

808-
/**
809-
* Get a callable from a class and method.
810-
*
811-
* @param string $class
812-
* @param string $method
813-
* @return \Closure
814-
*/
815-
protected function getCallableFromClassAndMethod($class, $method = '__invoke')
816-
{
817-
return function (...$params) use ($class, $method) {
818-
return $this->container->make($class)->{$method}(...$params);
819-
};
820-
}
821-
822784
/**
823785
* Get all of the defined abilities.
824786
*

src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ protected function parseAbilityAndArguments($ability, $arguments)
5353
return [$ability, $arguments];
5454
}
5555

56-
if (is_array($ability)) {
57-
return [$ability, $arguments];
58-
}
59-
6056
$method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['function'];
6157

6258
return [$this->normalizeGuessedAbilityName($method), $ability];

tests/Auth/AuthAccessGateTest.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -759,46 +759,6 @@ public function testEveryAbilityCheckFailsIfNonePass()
759759
$this->assertFalse($gate->check(['edit', 'update'], new AccessGateTestDummy));
760760
}
761761

762-
public function testInspectPolicyCallback()
763-
{
764-
$gate = $this->getBasicGate();
765-
766-
$response = $gate->inspect([AccessGateTestPolicyWithAllPermissions::class, 'edit'], new AccessGateTestDummy);
767-
768-
$this->assertFalse($response->denied());
769-
$this->assertTrue($response->allowed());
770-
}
771-
772-
public function testInspectPolicyCallbackInvoke()
773-
{
774-
$gate = $this->getBasicGate();
775-
776-
$response = $gate->inspect(AccessGateTestGuestInvokableClass::class, new AccessGateTestDummy);
777-
778-
$this->assertFalse($response->denied());
779-
$this->assertTrue($response->allowed());
780-
}
781-
782-
public function testCheckUsingPolicyCallback()
783-
{
784-
$gate = $this->getBasicGate();
785-
786-
$this->assertTrue($gate->check(
787-
[AccessGateTestPolicyWithAllPermissions::class, 'edit'],
788-
new AccessGateTestDummy)
789-
);
790-
}
791-
792-
public function testAnyUsingPolicyCallback()
793-
{
794-
$gate = $this->getBasicGate();
795-
796-
$this->assertTrue($gate->any(
797-
[AccessGateTestPolicyWithAllPermissions::class, ['edit', 'update']],
798-
new AccessGateTestDummy)
799-
);
800-
}
801-
802762
/**
803763
* @dataProvider hasAbilitiesTestDataProvider
804764
*

tests/Foundation/FoundationAuthorizesRequestsTraitTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ protected function tearDown(): void
1717
Container::setInstance(null);
1818
}
1919

20-
public function testCallableGateCheck()
21-
{
22-
unset($_SERVER['_test.authorizes.trait']);
23-
24-
$gate = $this->getBasicGate();
25-
26-
$response = (new FoundationTestAuthorizeTraitClass)->authorize([FoundationAuthorizesRequestTestPolicy::class, 'create']);
27-
28-
$this->assertInstanceOf(Response::class, $response);
29-
$this->assertTrue($_SERVER['_test.authorizes.trait.policy']);
30-
}
31-
3220
public function testBasicGateCheck()
3321
{
3422
unset($_SERVER['_test.authorizes.trait']);

0 commit comments

Comments
 (0)