Permalink
Browse files

Remove allowedPrivileges from Resource.

  • Loading branch information...
Bukarinov committed Dec 3, 2012
1 parent 709a94b commit a48ad8258c4ead4fc021f6b692ecee9e2827292b
@@ -10,12 +10,6 @@
* @var string
*/
protected $name;
- /**
- * Array of privileges which always allowed for all
- *
- * @var array
- */
- protected $allowedPrivileges = array();
/**
* @param string $name
@@ -34,14 +28,4 @@ public function getName()
{
return $this->name;
}
-
- /**
- * Get array of privileges which always allowed for all
- *
- * @return array
- */
- public function getAllowedPrivileges()
- {
- return $this->allowedPrivileges;
- }
}
@@ -53,13 +53,9 @@ public function addResource(ResourceInterface $resource)
*/
public function hasResource($resource)
{
- if ($resource instanceof ResourceInterface) {
- $resourceId = $resource->getName();
- } else {
- $resourceId = (string) $resource;
- }
+ $resourceName = self::getResourceName($resource);
- return isset($this->resources[$resourceId]);
+ return isset($this->resources[$resourceName]);
}
/**
@@ -73,11 +69,7 @@ public function hasResource($resource)
*/
public function getResource($resource)
{
- if ($resource instanceof ResourceInterface) {
- $resourceName = $resource->getName();
- } else {
- $resourceName = $resource;
- }
+ $resourceName = self::getResourceName($resource);
if (!$this->hasResource($resource)) {
throw new Exception\InvalidArgumentException("Resource '$resourceName' not found");
@@ -97,7 +89,11 @@ public function getResource($resource)
*/
public function removeResource($resource)
{
- $resourceName = $this->getResource($resource)->getName();
+ $resourceName = self::getResourceName($resource);
+
+ if (!$this->hasResource($resource)) {
+ throw new Exception\InvalidArgumentException("Resource '$resourceName' not found");
+ }
unset($this->resources[$resourceName]);
@@ -119,10 +115,6 @@ public function assert($resource, $privilege, $arg1 = null, $arg2 = null, $argN
{
$resource = $this->getResource($resource);
- if (in_array($privilege, $resource->getAllowedPrivileges())) {
- return true;
- }
-
$methodName = self::DYNAMIC_ASSERT_PREFIX . ucfirst($privilege);
if (!method_exists($resource, $methodName)) {
throw new Exception\RuntimeException("No rules for privilege '{$privilege}'");
@@ -136,4 +128,20 @@ public function assert($resource, $privilege, $arg1 = null, $arg2 = null, $argN
return call_user_func_array(array($resource, $methodName), $funcArgs);
}
+
+ /**
+ * Get Resource name
+ * The $resource parameter can either be a Resource or a Resource identifier.
+ *
+ * @param ResourceInterface|string $resource
+ * @return string
+ */
+ protected static function getResourceName($resource)
+ {
+ if ($resource instanceof ResourceInterface) {
+ return $resource->getName();
+ }
+
+ return (string) $resource;
+ }
}
@@ -10,11 +10,4 @@
* @return string
*/
public function getName();
-
- /**
- * Get array of privileges which always allowed for all
- *
- * @return array
- */
- public function getAllowedPrivileges();
}
@@ -2,8 +2,6 @@
namespace GeometriaLab\Permissions\Assertion;
-use GeometriaLab\Api\Mvc\Router\Http\Api;
-
use Zend\Stdlib\Glob as ZendGlob,
Zend\ServiceManager\FactoryInterface as ZendFactoryInterface,
Zend\ServiceManager\ServiceLocatorInterface as ZendServiceLocatorInterface;
@@ -131,15 +131,6 @@ public function testAssertWithoutPrivilege()
$assertion->assert('Bar', 'privilege');
}
- public function testAssertWithAllowedPrivilege()
- {
- $assertion = new Assertion();
- $fooResource = new Sample\Foo('Foo');
- $assertion->addResource($fooResource);
-
- $this->assertTrue($assertion->assert('Foo', 'allowedForAll'));
- }
-
public function testWithDynamicAssert()
{
$assertion = new Assertion();
@@ -11,6 +11,5 @@ public function testCreate()
$resource = new Sample\Foo('Foo');
$this->assertEquals('Foo', $resource->getName());
- $this->assertEquals(array('allowedForAll'), $resource->getAllowedPrivileges());
}
}
@@ -7,10 +7,6 @@
class Foo extends AbstractResource
{
- protected $allowedPrivileges = array(
- 'allowedForAll',
- );
-
public function canDynamicAssert(Assertion $assertion, \stdClass $obj, array $array)
{
return !empty($obj) && !empty($array);

0 comments on commit a48ad82

Please sign in to comment.