Skip to content
Snippets Groups Projects
Commit 72bc8f88 authored by Peter Rotich's avatar Peter Rotich
Browse files

Dept::canAssign Support Team Check

parent 2f82c476
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment