From 0328766d54202c0090ec61821473a82ce0596358 Mon Sep 17 00:00:00 2001 From: Warrick Date: Tue, 7 Jun 2022 11:09:07 +0200 Subject: [PATCH] Added a `has` method to `UserCollection`. --- CHANGELOG.md | 4 ++++ src/UserCollection.php | 5 +++++ tests/PermissionTest.php | 1 + 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb35f9c..1b66708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.4] 2022-06-07 +### Added +- Added a `has` method to `UserCollection` which is really just an alias of `anyHave`. + ## [2.2.3] 2022-06-06 ### Added - Added a `describe` method to the `User` class to get user permissions with descriptions. diff --git a/src/UserCollection.php b/src/UserCollection.php index 64187ed..6b24e94 100644 --- a/src/UserCollection.php +++ b/src/UserCollection.php @@ -155,6 +155,11 @@ public function anyHave(...$permissions): bool return false; } + public function has($permission): bool + { + return $this->anyHave($permission); + } + /** * Check if none of the users have the specified permissions. * diff --git a/tests/PermissionTest.php b/tests/PermissionTest.php index 12bd402..e24e427 100644 --- a/tests/PermissionTest.php +++ b/tests/PermissionTest.php @@ -183,6 +183,7 @@ public function it_can_assign_permissioins_to_multiple_users(): void self::assertTrue(Deadbolt::user($users[0])->has('articles.create')); self::assertTrue(Deadbolt::user($users[1])->has('articles.create')); + self::assertTrue(Deadbolt::users($users)->has('articles.create')); self::assertTrue(Deadbolt::users($users)->allHave('articles.create')); self::assertFalse(Deadbolt::users($users)->allHave('articles.edit')); self::assertTrue(Deadbolt::users($users)->anyHave('articles.create'));