Skip to content

Commit

Permalink
fix(target): deduplicate actors
Browse files Browse the repository at this point in the history
if an actor is added several times (from ticket template and form settings) then unicity in SQL fails and breaks target creation

@see pluginsGLPI#1089

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Sep 9, 2018
1 parent 2de40f4 commit 72cfb44
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
* @param string $role role of the user
* @param string $user user ID or email address for anonymous users
* @param boolean $notify true to enable notification for the actor
* @return void
* @return boolean true on success, false on error
*/
protected function addActor($role, $user, $notify) {
if (filter_var($user, FILTER_VALIDATE_EMAIL) !== false) {
Expand Down Expand Up @@ -336,9 +336,19 @@ protected function addActor($role, $user, $notify) {
default:
return false;
}
$actorType[] = $userId;
$actorType['use_notification'][] = ($notify == true);
$actorType['alternative_email'][] = $alternativeEmail;

$actorKey = array_search($userId, $actorType);
if ($actorKey === false) {
// Add the actor
$actorType[] = $userId;
$actorType['use_notification'][] = ($notify == true);
$actorType['alternative_email'][] = $alternativeEmail;
} else {
// New actor settings takes precedence
$actorType[$actorKey] = $userId;
$actorType['use_notification'][$actorKey] = ($notify == true);
$actorType['alternative_email'][$actorKey] = $alternativeEmail;
}

return true;
}
Expand All @@ -348,19 +358,32 @@ protected function addActor($role, $user, $notify) {
*
* @param string $role Role of the group
* @param string $group Group ID
* @return boolean true on sucess, false on error
*/
protected function addGroupActor($role, $group) {
switch ($role) {
case 'requester':
$this->requesterGroups['_groups_id_requester'][] = $group;
$actorType = &$this->requesterGroups['_groups_id_requester'];
break;
case 'observer' :
$this->observerGroups['_groups_id_observer'][] = $group;
$actorType = &$this->observerGroups['_groups_id_observer'];
break;
case 'assigned' :
$this->assignedGroups['_groups_id_assign'][] = $group;
$actorType = &$this->assignedGroups['_groups_id_assign'];
break;
default:
return false;
}

$actorKey = array_search($userId, $actorType);
if ($actorKey !== false) {
return false;
}

// Add the group actor
$actorType[] = $group;

return true;
}

/**
Expand Down

0 comments on commit 72cfb44

Please sign in to comment.