Skip to content

Commit 6cfe010

Browse files
antonkomarevAnton Komarev
andauthored
[10.x] Expand Gate::allows & Gate::denies signature (#49503)
* [10.x] Expand Gate::allows & Gate::denies signature * [10.x] Expand Gate::allows & Gate::denies signature * [10.x] Expand Gate::allows & Gate::denies signature --------- Co-authored-by: Anton Komarev <[email protected]>
1 parent bd9b41e commit 6cfe010

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

src/Illuminate/Auth/Access/Gate.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,27 @@ public function after(callable $callback)
318318
}
319319

320320
/**
321-
* Determine if the given ability should be granted for the current user.
321+
* Determine if all of the given abilities should be granted for the current user.
322322
*
323-
* @param string $ability
323+
* @param iterable|string $abilities
324324
* @param array|mixed $arguments
325325
* @return bool
326326
*/
327-
public function allows($ability, $arguments = [])
327+
public function allows($abilities, $arguments = [])
328328
{
329-
return $this->check($ability, $arguments);
329+
return $this->check($abilities, $arguments);
330330
}
331331

332332
/**
333-
* Determine if the given ability should be denied for the current user.
333+
* Determine if any of the given abilities should be denied for the current user.
334334
*
335-
* @param string $ability
335+
* @param iterable|string $abilities
336336
* @param array|mixed $arguments
337337
* @return bool
338338
*/
339-
public function denies($ability, $arguments = [])
339+
public function denies($abilities, $arguments = [])
340340
{
341-
return ! $this->allows($ability, $arguments);
341+
return ! $this->allows($abilities, $arguments);
342342
}
343343

344344
/**

src/Illuminate/Contracts/Auth/Access/Gate.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ public function before(callable $callback);
5757
public function after(callable $callback);
5858

5959
/**
60-
* Determine if the given ability should be granted for the current user.
60+
* Determine if all of the given abilities should be granted for the current user.
6161
*
62-
* @param string $ability
62+
* @param iterable|string $abilities
6363
* @param array|mixed $arguments
6464
* @return bool
6565
*/
66-
public function allows($ability, $arguments = []);
66+
public function allows($abilities, $arguments = []);
6767

6868
/**
69-
* Determine if the given ability should be denied for the current user.
69+
* Determine if any of the given abilities should be denied for the current user.
7070
*
71-
* @param string $ability
71+
* @param iterable|string $abilities
7272
* @param array|mixed $arguments
7373
* @return bool
7474
*/
75-
public function denies($ability, $arguments = []);
75+
public function denies($abilities, $arguments = []);
7676

7777
/**
7878
* Determine if all of the given abilities should be granted for the current user.

tests/Auth/AuthAccessGateTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,47 @@ public function testAfterCallbacksDoNotOverrideEachOther()
325325
$this->assertTrue($gate->denies('deny'));
326326
}
327327

328+
public function testArrayAbilitiesInAllows()
329+
{
330+
$gate = $this->getBasicGate();
331+
332+
$gate->define('allow_1', function ($user) {
333+
return true;
334+
});
335+
$gate->define('allow_2', function ($user) {
336+
return true;
337+
});
338+
$gate->define('deny', function ($user) {
339+
return false;
340+
});
341+
342+
$this->assertTrue($gate->allows(['allow_1']));
343+
$this->assertTrue($gate->allows(['allow_1', 'allow_2']));
344+
$this->assertFalse($gate->allows(['allow_1', 'allow_2', 'deny']));
345+
$this->assertFalse($gate->allows(['deny', 'allow_1', 'allow_2']));
346+
}
347+
348+
public function testArrayAbilitiesInDenies()
349+
{
350+
$gate = $this->getBasicGate();
351+
352+
$gate->define('deny_1', function ($user) {
353+
return false;
354+
});
355+
$gate->define('deny_2', function ($user) {
356+
return false;
357+
});
358+
$gate->define('allow', function ($user) {
359+
return true;
360+
});
361+
362+
$this->assertTrue($gate->denies(['deny_1']));
363+
$this->assertTrue($gate->denies(['deny_1', 'deny_2']));
364+
$this->assertTrue($gate->denies(['deny_1', 'allow']));
365+
$this->assertTrue($gate->denies(['allow', 'deny_1']));
366+
$this->assertFalse($gate->denies(['allow']));
367+
}
368+
328369
public function testCurrentUserThatIsOnGateAlwaysInjectedIntoClosureCallbacks()
329370
{
330371
$gate = $this->getBasicGate();

0 commit comments

Comments
 (0)