From 5e9a4555c241bd08d249a87811b83277d938acdf Mon Sep 17 00:00:00 2001 From: Nicholas J Date: Wed, 7 Oct 2015 22:55:06 -0400 Subject: [PATCH] Expose permissions collection through all method This feature exposes a colleciton of Permission objects. Useful in situations where you need to display tables of permissions a user is allowed or denied. The underlying getPermissions method is exposed as a public function "all". --- changelog.md | 3 +++ spec/Callers/CallerLockSpec.php | 9 +++++++++ src/Lock.php | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/changelog.md b/changelog.md index 9914144..e38f7c2 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ All notable changes to Lock will be documented in this file. This file follows the *[Keep a CHANGELOG](http://keepachangelog.com/)* standards. +## [Unreleased] +- Added all method, this feature returns the permissions collection for a caller. + ## 0.2.0 - 2015-09-16 ### Added diff --git a/spec/Callers/CallerLockSpec.php b/spec/Callers/CallerLockSpec.php index f50dd64..e6bc429 100644 --- a/spec/Callers/CallerLockSpec.php +++ b/spec/Callers/CallerLockSpec.php @@ -133,4 +133,13 @@ function it_can_work_with_permission_conditions() $this->can('create', 'posts')->shouldReturn(true); $this->can('create', 'pages')->shouldReturn(false); } + + function it_can_fetch_all_permissions() + { + $this->allow('login'); + $this->allow('create', 'posts'); + $this->deny('delete', 'users'); + + $this->all()->shouldBeArray(); + } } diff --git a/src/Lock.php b/src/Lock.php index a0309d4..19e866c 100644 --- a/src/Lock.php +++ b/src/Lock.php @@ -222,6 +222,16 @@ private function clearPermission($action, Resource $resource, array $permissions } } + /** + * Fetch collection of all caller permissions + * + * @return Permissions\Permission[] + */ + public function all() + { + return $this->getPermissions(); + } + /** * Determine if an action is allowed *