Skip to content

Commit

Permalink
[Organizations] Fixes: Missing acl checks for editing organizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
TiSiE committed Jul 5, 2016
1 parent 90e9e7b commit 808a346
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 141 deletions.
2 changes: 2 additions & 0 deletions module/Organizations/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@
'allow' => array(
'route/lang/organizations',
'Organizations/InviteEmployee',
'Entity/Organization' => [ 'edit' => 'Organizations/Write' ],
),
),
),
'assertions' => array(
'invokables' => array(
'Organizations/Write' => 'Organizations\Acl\Assertion\WriteAssertion',
),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Organizations\Acl\Assertion;

use Auth\Entity\UserInterface;
use Core\Entity\PermissionsInterface;
use Organizations\Entity\OrganizationInterface;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Assertion\AssertionInterface;
use Zend\Permissions\Acl\Resource\ResourceInterface;
use Zend\Permissions\Acl\Role\RoleInterface;

/**
* ${CARET}
*
* @author Mathias Gelhausen <[email protected]>
* @todo write test
*/
class WriteAssertion implements AssertionInterface
{
public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
{
return 'edit' == $privilege
&& $role instanceOf UserInterface
&& $resource instanceOf OrganizationInterface
&& $resource->getPermissions()->isGranted($role, PermissionsInterface::PERMISSION_CHANGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Core\Entity\Collection\ArrayCollection;
use Core\Form\SummaryForm;
use Organizations\Exception\MissingParentOrganizationException;
use Zend\Mvc\Controller\AbstractActionController;
use Organizations\Repository;
use Organizations\Form;
Expand Down Expand Up @@ -124,7 +125,7 @@ public function editAction()
/* @var $handler \Organizations\Controller\Plugin\GetOrganizationHandler */
$handler = $this->plugin('Organizations/GetOrganizationHandler');
$org = $handler->process($this->params(), true);
} catch (\RuntimeException $e) {
} catch (MissingParentOrganizationException $e) {
return $this->getErrorViewModel('no-parent');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/** */
namespace Organizations\Controller\Plugin;

use Organizations\Exception\MissingParentOrganizationException;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Core\Repository\RepositoryService;
use Auth\AuthenticationService;
Expand Down Expand Up @@ -94,7 +95,7 @@ public function process(Params $params,$allowDraft = true)
/* @var $parent \Organizations\Entity\OrganizationReference */
$parent = $user->getOrganization();
if (!$parent->hasAssociation()) {
throw new \RuntimeException('You cannot create organizations, because you do not belong to a parent organization. Use "User menu -> create my organization" first.');
throw new MissingParentOrganizationException('You cannot create organizations, because you do not belong to a parent organization. Use "User menu -> create my organization" first.');
}
$organization->setParent($parent->getOrganization());
}
Expand All @@ -109,6 +110,9 @@ public function process(Params $params,$allowDraft = true)
if (!$organization) {
throw new \RuntimeException('No Organization found with id "' . $organizationId . '"');
}

$this->acl->check($organization, 'edit');

return $organization;
}
}
Loading

0 comments on commit 808a346

Please sign in to comment.