Skip to content

Commit

Permalink
issue: Org Added Collabs
Browse files Browse the repository at this point in the history
This addresses an issue where creating a ticket with a Reply and
Collaborators failed to add the Response. This was caused by the Owner ID
check in class Ticket as it returned an error that wouldn’t let the response
be added. This also addresses an issue where Collabs added via Organization
were being Enabled regardless of the Disable Agent Collab setting.
  • Loading branch information
JediKev committed Apr 29, 2020
1 parent cba6035 commit 0ee25b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
23 changes: 5 additions & 18 deletions include/class.ticket.php
Expand Up @@ -1239,6 +1239,9 @@ function addCollaborators($users, $vars, &$errors, $event=true) {
continue;
if ($collabs->findFirst(array('user_id' => $user->getId())))
continue;
if ($user->getId() == $this->getOwnerId())
continue;

if ($c=$this->addCollaborator($user, $vars, $errors, $event))
$new[] = $c;
}
Expand Down Expand Up @@ -3299,23 +3302,6 @@ function postReply($vars, &$errors, $alert=true, $claim=true) {
if (!$vars['ip_address'] && $_SERVER['REMOTE_ADDR'])
$vars['ip_address'] = $_SERVER['REMOTE_ADDR'];

// Add new collaborators (if any).
if (isset($vars['ccs']) && count($vars['ccs']))
$this->addCollaborators($vars['ccs'], array(), $errors);

if ($collabs = $this->getCollaborators()) {
foreach ($collabs as $collaborator) {
$cid = $collaborator->getUserId();
// Enable collaborators if they were reselected
if (!$collaborator->isActive() && ($vars['ccs'] && in_array($cid, $vars['ccs'])))
$collaborator->setFlag(Collaborator::FLAG_ACTIVE, true);
// Disable collaborators if they were unchecked
elseif ($collaborator->isActive() && (!$vars['ccs'] || !in_array($cid, $vars['ccs'])))
$collaborator->setFlag(Collaborator::FLAG_ACTIVE, false);

$collaborator->save();
}
}
// clear db cache
$this->getThread()->_collaborators = null;

Expand Down Expand Up @@ -4345,8 +4331,9 @@ static function create($vars, &$errors, $origin, $autorespond=true,
$settings = array('isactive' => true);
$collabs = array();
foreach ($org->allMembers() as $u) {
$_errors = array();
if ($members || ($pris && $u->isPrimaryContact())) {
if ($c = $ticket->addCollaborator($u, $settings, $errors)) {
if ($c = $ticket->addCollaborator($u, $settings, $_errors)) {
$collabs[] = (string) $c;
}
}
Expand Down
19 changes: 19 additions & 0 deletions scp/tickets.php
Expand Up @@ -191,6 +191,25 @@
}

$alert = strcasecmp('none', $_POST['reply-to']);
if (!$errors) {
// Add new collaborators (if any)
$_errors = array();
if (isset($vars['ccs']) && count($vars['ccs']))
$ticket->addCollaborators($vars['ccs'], array(), $_errors);
// set status of collaborators
if ($collabs = $ticket->getCollaborators()) {
foreach ($collabs as $collaborator) {
$cid = $collaborator->getUserId();
// Enable collaborators if they were reselected
if (!$collaborator->isActive() && ($vars['ccs'] && in_array($cid, $vars['ccs'])))
$collaborator->setFlag(Collaborator::FLAG_ACTIVE, true);
// Disable collaborators if they were unchecked
elseif ($collaborator->isActive() && (!$vars['ccs'] || !in_array($cid, $vars['ccs'])))
$collaborator->setFlag(Collaborator::FLAG_ACTIVE, false);
$collaborator->save();
}
}
}
if (!$errors && ($response=$ticket->postReply($vars, $errors,
$alert))) {
$msg = sprintf(__('%s: Reply posted successfully'),
Expand Down

0 comments on commit 0ee25b8

Please sign in to comment.