diff --git a/include/class.dept.php b/include/class.dept.php index 7c9f92bfca05df65120fa59d52fd25a602aa03a7..384a749a23b86c9d9a237fb383060fec52fc22be 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -373,18 +373,25 @@ implements TemplateVariable, Searchable { return ($this->getSignature() && $this->isPublic()); } - //Check if an agent is eligible for assignment - function canAssign(Staff $assignee) { - //Primary members only - if ($this->assignPrimaryOnly() && !$this->isPrimaryMember($assignee)) - return false; + // Check if an agent or team is eligible for assignment + function canAssign($assignee) { + - //Extended members only - if ($this->assignMembersOnly() && !$this->isMember($assignee)) + if ($assignee instanceof Staff) { + // Primary members only + if ($this->assignPrimaryOnly() && !$this->isPrimaryMember($assignee)) + return false; + + // Extended members only + if ($this->assignMembersOnly() && !$this->isMember($assignee)) + return false; + } elseif (!$assignee instanceof Team) { + // Assignee can only be an Agent or a Team return false; + } - //Make sure agent is active & not on vacation - if (!$assignee->isActive() || $assignee->onVacation()) + // Make sure agent / team is availabe for assignment + if (!$assignee->isAvailable()) return false; return true; diff --git a/include/class.team.php b/include/class.team.php index a4fd4f8c7af6eb8cbac70a3d27f2f82488cc59ea..2420cebc0369e1ae5990d4fb57c80a019343c8c5 100644 --- a/include/class.team.php +++ b/include/class.team.php @@ -126,6 +126,10 @@ implements TemplateVariable { return $this->isEnabled(); } + function isAvailable() { + return ($this->isActive() && $this->members); + } + function alertsEnabled() { return ($this->flags & self::FLAG_NOALERTS) == 0; } diff --git a/include/class.ticket.php b/include/class.ticket.php index 0855f1196c5395ea6f0964c0427a0d1a74f062b0..de6b6d0f7dcbfdcbac3bae238d650a7f97ebf134 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2397,17 +2397,17 @@ implements RestrictedAccess, Threadable, Searchable { $evd = array(); $refer = null; + $dept = $this->getDept(); $assignee = $form->getAssignee(); if ($assignee instanceof Staff) { - $dept = $this->getDept(); if ($this->getStaffId() == $assignee->getId()) { $errors['assignee'] = sprintf(__('%s already assigned to %s'), __('Ticket'), __('the agent') ); - } elseif(!$assignee->isAvailable()) { + } elseif (!$assignee->isAvailable()) { $errors['assignee'] = __('Agent is unavailable for assignment'); - } elseif (!$dept->canAssign($assignee)) { + } elseif (!$dept->canAssign($assignee)) { $errors['err'] = __('Permission denied'); } else { $refer = $this->staff ?: null; @@ -2425,6 +2425,8 @@ implements RestrictedAccess, Threadable, Searchable { __('Ticket'), __('the team') ); + } elseif (!$dept->canAssign($assignee)) { + $errors['err'] = __('Permission denied'); } else { $refer = $this->team ?: null; $this->team_id = $assignee->getId();