Skip to content

Commit

Permalink
ELMCF-74 fixing role assign to work when updating a role, catching th…
Browse files Browse the repository at this point in the history
…e exception if the role is already assigned with the limitation
  • Loading branch information
Daniel Clements committed Jul 13, 2016
1 parent 022d18f commit d4c04da
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Core/API/Managers/RoleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use eZ\Publish\API\Repository\UserService;
use Kaliop\eZMigrationBundle\Core\API\ReferenceHandler;
use Kaliop\eZMigrationBundle\Core\API\Handler\RoleTranslationHandler;

use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException;
/**
* Class RoleManager
*
Expand All @@ -29,7 +29,7 @@ public function create()
$this->loginUser();

$roleService = $this->repository->getRoleService();
//$userService = $this->repository->getUserService();
$userService = $this->repository->getUserService();

$roleCreateStruct = $roleService->newRoleCreateStruct($this->dsl['name']);

Expand All @@ -56,7 +56,7 @@ public function update()
$this->loginUser();

$roleService = $this->repository->getRoleService();
//$userService = $this->repository->getUserService();
$userService = $this->repository->getUserService();

if (array_key_exists('name', $this->dsl)) {
/** @var \eZ\Publish\API\Repository\Values\User\Role $role */
Expand Down Expand Up @@ -84,6 +84,10 @@ public function update()
}
}

if (array_key_exists('assign', $this->dsl)) {
$this->assignRole($role, $roleService, $userService, $this->dsl['assign']);
}

$this->setReferences($role);
}

Expand Down Expand Up @@ -220,11 +224,15 @@ private function assignRole(Role $role, RoleService $roleService, UserService $u
$group = $userService->loadUserGroup($groupId);

if (!array_key_exists('limitation', $assign)) {
$roleService->assignRoleToUserGroup($role, $group);
try {
$roleService->assignRoleToUserGroup($role, $group);
} catch (InvalidArgumentException $e) {}
} else {
foreach ($assign['limitation'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
$roleService->assignRoleToUserGroup($role, $group, $limitationObject);
try {
$roleService->assignRoleToUserGroup($role, $group, $limitationObject);
} catch (InvalidArgumentException $e) {}
}
}
}
Expand Down

0 comments on commit d4c04da

Please sign in to comment.