Skip to content

Commit

Permalink
Fix Configuration Audits
Browse files Browse the repository at this point in the history
- Agents (checkboxes, Department Access)
- Teams (flags/checkboxes)
- SLA (flags)
- Email (checkboxes)
- Users (dynamic fields)
- User Account (whole object)
- Organizations (dynamic fields, flags)
- Departments (checkboxes)
  • Loading branch information
aydreeihn committed Oct 10, 2019
1 parent 349c982 commit 7cfc062
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 43 deletions.
14 changes: 11 additions & 3 deletions include/class.dept.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ public function setFlag($flag, $val) {
$this->flags &= ~$flag; $this->flags &= ~$flag;
} }


function hasFlag($flag) {
return ($this->get('flags', 0) & $flag) != 0;
}

function export($dept, $criteria=null, $filename='') { function export($dept, $criteria=null, $filename='') {
include_once(INCLUDE_DIR.'class.error.php'); include_once(INCLUDE_DIR.'class.error.php');
$members = $dept->getMembers(); $members = $dept->getMembers();
Expand Down Expand Up @@ -813,13 +817,19 @@ function update($vars, &$errors) {
if ($errors) if ($errors)
return false; return false;


$vars['disable_auto_claim'] = isset($vars['disable_auto_claim']) ? 1 : 0;
if (PluginManager::getPluginByName('View auditing for tickets', true)) { if (PluginManager::getPluginByName('View auditing for tickets', true)) {
//flags
if (($this->hasflag(self::FLAG_DISABLE_AUTO_CLAIM) && !$vars['disable_auto_claim']) ||
(!$this->hasflag(self::FLAG_DISABLE_AUTO_CLAIM) && $vars['disable_auto_claim']))
$disableAutoClaim = true;
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) { if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) {
$loggedUpdate = true; $loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'type' => ucfirst($value))); $type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'type' => ucfirst($value)));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);
} elseif (isset($this->$key) && ($this->$key != $value) && $key != 'members') { } elseif ((isset($this->$key) && ($this->$key != $value) && $key != 'members') ||
($disableAutoClaim && $key == 'disable_auto_claim')) {
$loggedUpdate = true; $loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key)); $type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);
Expand Down Expand Up @@ -868,8 +878,6 @@ function update($vars, &$errors) {
$this->setFlag(self::FLAG_ARCHIVED, true); $this->setFlag(self::FLAG_ARCHIVED, true);
} }


$this->setFlag(self::FLAG_DISABLE_AUTO_CLAIM, isset($vars['disable_auto_claim']));

switch ($vars['assignment_flag']) { switch ($vars['assignment_flag']) {
case 'all': case 'all':
$this->setFlag(self::FLAG_ASSIGN_MEMBERS_ONLY, false); $this->setFlag(self::FLAG_ASSIGN_MEMBERS_ONLY, false);
Expand Down
7 changes: 5 additions & 2 deletions include/class.email.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ function update($vars, &$errors=false) {


if($errors) return false; if($errors) return false;


//checkboxes
$vars['noautoresp'] = isset($vars['noautoresp']) ? 1 : 0;
$vars['smtp_spoofing'] = isset($vars['smtp_spoofing']) ? 1 : 0;
if (PluginManager::getPluginByName('View auditing for tickets', true)) { if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) { if (isset($this->$key) && ($this->$key != $value)) {
Expand All @@ -402,7 +405,7 @@ function update($vars, &$errors=false) {
$this->dept_id = $vars['dept_id']; $this->dept_id = $vars['dept_id'];
$this->priority_id = $vars['priority_id']; $this->priority_id = $vars['priority_id'];
$this->topic_id = $vars['topic_id']; $this->topic_id = $vars['topic_id'];
$this->noautoresp = isset($vars['noautoresp'])?1:0; $this->noautoresp = $vars['noautoresp'];
$this->userid = $vars['userid']; $this->userid = $vars['userid'];
$this->mail_active = $vars['mail_active']; $this->mail_active = $vars['mail_active'];
$this->mail_host = $vars['mail_host']; $this->mail_host = $vars['mail_host'];
Expand All @@ -415,7 +418,7 @@ function update($vars, &$errors=false) {
$this->smtp_host = $vars['smtp_host']; $this->smtp_host = $vars['smtp_host'];
$this->smtp_port = $vars['smtp_port'] ?: 0; $this->smtp_port = $vars['smtp_port'] ?: 0;
$this->smtp_auth = $vars['smtp_auth']; $this->smtp_auth = $vars['smtp_auth'];
$this->smtp_spoofing = isset($vars['smtp_spoofing']) ? 1 : 0; $this->smtp_spoofing = $vars['smtp_spoofing'];
$this->notes = Format::sanitize($vars['notes']); $this->notes = Format::sanitize($vars['notes']);


//Post fetch email handling... //Post fetch email handling...
Expand Down
80 changes: 74 additions & 6 deletions include/class.organization.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -417,10 +417,76 @@ function update($vars, &$errors) {
if (!$this->update($vars, $errors)) if (!$this->update($vars, $errors))
$errors['error'] = __('Unable to update organization form'); $errors['error'] = __('Unable to update organization form');



if ($errors) if ($errors)
return false; return false;


foreach ($this->getDynamicData() as $entry) {
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$fields = $entry->getFields();
foreach ($fields as $field) {
$changes = $field->getChanges();
if ((is_array($changes) && $changes[0]) || $changes && !is_array($changes)) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName(),'person' => $thisstaff->getName()->name, 'key' => $field->getLabel()));
Signal::send('object.edited', $this, $type);
}
}
}
if ($entry->getDynamicForm()->get('type') == 'O'
&& ($name = $entry->getField('name'))
) {
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
if ($this->name != $name->getClean()) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName(),'person' => $thisstaff->getName()->name, 'key' => 'Name'));
Signal::send('object.edited', $this, $type);
}
}
$this->name = $name->getClean();
$this->save();
}
$entry->setSource($vars);
if ($entry->save())
$this->updated = SqlFunction::NOW();
}

if (PluginManager::getPluginByName('View auditing for tickets', true)) {
if (($this->autoAddMembersAsCollabs() && !$vars['collab-all-flag']) ||
(!$this->autoAddMembersAsCollabs() && $vars['collab-all-flag'])) {
$auditCollabAll = true;
$key = 'collab-all-flag';
}
if (($this->autoAddPrimaryContactsAsCollabs() && !$vars['collab-pc-flag']) ||
(!$this->autoAddPrimaryContactsAsCollabs() && $vars['collab-pc-flag'])) {
$auditCollabPc = true;
$key = 'collab-pc-flag';
}
if (($this->autoAssignAccountManager() && !$vars['assign-am-flag']) ||
(!$this->autoAssignAccountManager() && $vars['assign-am-flag'])) {
$auditAssignAm = true;
$key = 'assign-am-flag';
}
if ((!$this->shareWithPrimaryContacts() && $vars['sharing'] == 'sharing-primary' ||
(!$this->shareWithEverybody() && $vars['sharing'] == 'sharing-all' ||
($this->shareWithPrimaryContacts() && !$vars['sharing']) ||
($this->shareWithEverybody() && !$vars['sharing']))))
$sharing = true;

if ($auditCollabAll || $auditCollabPc || $auditAssignAm) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}

foreach ($vars as $key => $value) {
if ($key != 'id' && $this->get($key) && $value != $this->get($key)) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}

// Set flags // Set flags
foreach (array( foreach (array(
'collab-all-flag' => Organization::COLLAB_ALL_MEMBERS, 'collab-all-flag' => Organization::COLLAB_ALL_MEMBERS,
Expand All @@ -437,6 +503,13 @@ function update($vars, &$errors) {
'sharing-primary' => Organization::SHARE_PRIMARY_CONTACT, 'sharing-primary' => Organization::SHARE_PRIMARY_CONTACT,
'sharing-all' => Organization::SHARE_EVERYBODY, 'sharing-all' => Organization::SHARE_EVERYBODY,
) as $ck=>$flag) { ) as $ck=>$flag) {
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
if ($sharing) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => 'sharing'));
Signal::send('object.edited', $this, $type);
}
}
if ($vars['sharing'] == $ck) if ($vars['sharing'] == $ck)
$this->setStatus($flag); $this->setStatus($flag);
else else
Expand All @@ -459,11 +532,6 @@ function update($vars, &$errors) {
)); ));
} }


if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.edited', $this, $type);
}

return $this->save(); return $this->save();
} }


Expand Down
36 changes: 24 additions & 12 deletions include/class.sla.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ function sendAlerts() {
return 0 === ($this->flags & self::FLAG_NOALERTS); return 0 === ($this->flags & self::FLAG_NOALERTS);
} }


function hasFlag($flag) {
return ($this->get('flags', 0) & $flag) != 0;
}

function alertOnOverdue() { function alertOnOverdue() {
return $this->sendAlerts(); return $this->sendAlerts();
} }
Expand Down Expand Up @@ -158,10 +162,23 @@ function update($vars, &$errors) {
if ($errors) if ($errors)
return false; return false;


//flags
$vars['disable_overdue_alerts'] = isset($vars['disable_overdue_alerts']) ? self::FLAG_NOALERTS : 0;
$vars['transient'] = isset($vars['transient']) ? self::FLAG_TRANSIENT : 0;
if (PluginManager::getPluginByName('View auditing for tickets', true)) { if (PluginManager::getPluginByName('View auditing for tickets', true)) {
//flags
if (($this->hasflag(self::FLAG_NOALERTS) && $vars['disable_overdue_alerts'] != self::FLAG_NOALERTS) ||
(!$this->hasflag(self::FLAG_NOALERTS) && $vars['disable_overdue_alerts'] == self::FLAG_NOALERTS))
$auditDisableOverdue = true;
if (($this->hasflag(self::FLAG_TRANSIENT) && $vars['transient'] != self::FLAG_TRANSIENT) ||
(!$this->hasflag(self::FLAG_TRANSIENT) && $vars['transient'] == self::FLAG_TRANSIENT))
$auditTransient = true;
if (($this->hasflag(self::FLAG_ACTIVE) && $vars['isactive'] != self::FLAG_ACTIVE) ||
(!$this->hasflag(self::FLAG_ACTIVE) && $vars['isactive'] == self::FLAG_ACTIVE))
$auditStatus = true;
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) { if (isset($this->$key) && ($this->$key != $value) ||
$loggedUpdate = true; ($auditDisableOverdue && $key == 'disable_overdue_alerts' || $auditTransient && $key == 'transient' || $auditStatus && $key == 'isactive')) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key)); $type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);
} }
Expand All @@ -174,17 +191,12 @@ function update($vars, &$errors) {
$this->notes = Format::sanitize($vars['notes']); $this->notes = Format::sanitize($vars['notes']);
$this->flags = $this->flags =
($vars['isactive'] ? self::FLAG_ACTIVE : 0) ($vars['isactive'] ? self::FLAG_ACTIVE : 0)
| (isset($vars['disable_overdue_alerts']) ? self::FLAG_NOALERTS : 0) | ($vars['disable_overdue_alerts'])
| (isset($vars['enable_priority_escalation']) ? self::FLAG_ESCALATE : 0) | ($vars['enable_priority_escalation'])
| (isset($vars['transient']) ? self::FLAG_TRANSIENT : 0); | ($vars['transient']);


if ($this->save()) { if ($this->save())
if (!$loggedUpdate && PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.edited', $this, $type);
}
return true; return true;
}


if (isset($this->id)) { if (isset($this->id)) {
$errors['err']=sprintf(__('Unable to update %s.'), __('this SLA plan')) $errors['err']=sprintf(__('Unable to update %s.'), __('this SLA plan'))
Expand Down
46 changes: 37 additions & 9 deletions include/class.staff.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -741,10 +741,13 @@ function updateProfile($vars, &$errors) {
} }
} }


$vars['onvacation'] = isset($vars['onvacation']) ? 1 : 0;

if (PluginManager::getPluginByName('View auditing for tickets', true)) { if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) { if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key)); $type = array('type' => 'edited', 'data' =>
array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);
} }
} }
Expand All @@ -764,7 +767,7 @@ function updateProfile($vars, &$errors) {
$this->default_signature_type = $vars['default_signature_type']; $this->default_signature_type = $vars['default_signature_type'];
$this->default_paper_size = $vars['default_paper_size']; $this->default_paper_size = $vars['default_paper_size'];
$this->lang = $vars['lang']; $this->lang = $vars['lang'];
$this->onvacation = isset($vars['onvacation']) ? 1 : 0; $this->onvacation = $vars['onvacation'];


if (isset($vars['avatar_code'])) if (isset($vars['avatar_code']))
$this->setExtraAttr('avatar', $vars['avatar_code']); $this->setExtraAttr('avatar', $vars['avatar_code']);
Expand Down Expand Up @@ -1152,21 +1155,30 @@ function update($vars, &$errors) {
// Update the local permissions // Update the local permissions
$this->updatePerms($vars['perms'], $errors); $this->updatePerms($vars['perms'], $errors);


//checkboxes
$vars['isadmin'] = isset($vars['isadmin']) ? 1 : 0;
$vars['islocked'] = isset($vars['islocked']) ? 0 : 1;
$vars['isvisible'] = isset($vars['isvisible']) ? 1 : 0;
$vars['onvacation'] = isset($vars['onvacation']) ? 1 : 0;
$vars['assigned_only'] = isset($vars['assigned_only']) ? 1 : 0;

if (PluginManager::getPluginByName('View auditing for tickets', true)) { if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if ($key == 'islocked') $key = 'isactive'; if ($key == 'islocked') $key = 'isactive';
if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms') && ($key != 'teams')) { if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms') && ($key != 'teams') && ($key != 'dept_access')) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key)); $type = array('type' => 'edited', 'data' =>
array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);
} }
if ($key == 'isactive') $key = 'islocked';
} }
} }


$this->isadmin = $vars['isadmin']; $this->isadmin = $vars['isadmin'];
$this->isactive = isset($vars['islocked']) ? 0 : 1; $this->isactive = $vars['islocked'];
$this->isvisible = isset($vars['isvisible'])?1:0; $this->isvisible = $vars['isvisible'];
$this->onvacation = isset($vars['onvacation'])?1:0; $this->onvacation = $vars['onvacation'];
$this->assigned_only = isset($vars['assigned_only'])?1:0; $this->assigned_only = $vars['assigned_only'];
$this->role_id = $vars['role_id']; $this->role_id = $vars['role_id'];
$this->username = $vars['username']; $this->username = $vars['username'];
$this->firstname = $vars['firstname']; $this->firstname = $vars['firstname'];
Expand Down Expand Up @@ -1212,6 +1224,7 @@ function update($vars, &$errors) {
* be indexed by the dept_id number. * be indexed by the dept_id number.
*/ */
function updateAccess($access, &$errors) { function updateAccess($access, &$errors) {
global $thisstaff;
reset($access); reset($access);
$dropped = array(); $dropped = array();
foreach ($this->dept_access as $DA) foreach ($this->dept_access as $DA)
Expand All @@ -1220,7 +1233,7 @@ function updateAccess($access, &$errors) {
unset($dropped[$dept_id]); unset($dropped[$dept_id]);
if (!$role_id || !Role::lookup($role_id)) if (!$role_id || !Role::lookup($role_id))
$errors['dept_access'][$dept_id] = __('Select a valid role'); $errors['dept_access'][$dept_id] = __('Select a valid role');
if (!$dept_id || !Dept::lookup($dept_id)) if (!$dept_id || !($dept=Dept::lookup($dept_id)))
$errors['dept_access'][$dept_id] = __('Select a valid department'); $errors['dept_access'][$dept_id] = __('Select a valid department');
if ($dept_id == $this->getDeptId()) if ($dept_id == $this->getDeptId())
$errors['dept_access'][$dept_id] = sprintf(__('Agent already has access to %s'), __('this department')); $errors['dept_access'][$dept_id] = sprintf(__('Agent already has access to %s'), __('this department'));
Expand All @@ -1230,6 +1243,12 @@ function updateAccess($access, &$errors) {
'dept_id' => $dept_id, 'role_id' => $role_id 'dept_id' => $dept_id, 'role_id' => $role_id
)); ));
$this->dept_access->add($da); $this->dept_access->add($da);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name,
'key' => sprintf('%s Department Access Added', $dept->getName())));
Signal::send('object.edited', $this, $type);
}
} }
else { else {
$da->role_id = $role_id; $da->role_id = $role_id;
Expand All @@ -1243,6 +1262,15 @@ function updateAccess($access, &$errors) {
->filter(array('dept_id__in' => array_keys($dropped))) ->filter(array('dept_id__in' => array_keys($dropped)))
->delete(); ->delete();
$this->dept_access->reset(); $this->dept_access->reset();
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach (array_keys($dropped) as $dept_id) {
$deptName = Dept::getNameById($dept_id);
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name,
'key' => sprintf('%s Department Access Removed', $deptName)));
Signal::send('object.edited', $this, $type);
}
}
} }
return !$errors; return !$errors;
} }
Expand Down
21 changes: 18 additions & 3 deletions include/class.team.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ function isAvailable() {
return ($this->isActive() && $this->members); return ($this->isActive() && $this->members);
} }


function hasFlag($flag) {
return ($this->get('flags', 0) & $flag) != 0;
}

function alertsEnabled() { function alertsEnabled() {
return ($this->flags & self::FLAG_NOALERTS) == 0; return ($this->flags & self::FLAG_NOALERTS) == 0;
} }
Expand Down Expand Up @@ -157,10 +161,21 @@ function update($vars, &$errors=array()) {
$errors['name']=__('Team name already exists'); $errors['name']=__('Team name already exists');
} }


$vars['noalerts'] = isset($vars['noalerts']) ? self::FLAG_NOALERTS : 0;
if (PluginManager::getPluginByName('View auditing for tickets', true)) { if (PluginManager::getPluginByName('View auditing for tickets', true)) {
//flags
if (($this->hasflag(self::FLAG_ENABLED) && $vars['isenabled'] != self::FLAG_ENABLED) ||
(!$this->hasflag(self::FLAG_ENABLED) && $vars['isenabled'] == self::FLAG_ENABLED))
$auditEnabled = true;
if (($this->hasflag(self::FLAG_NOALERTS) && $vars['noalerts'] != self::FLAG_NOALERTS) ||
(!$this->hasflag(self::FLAG_NOALERTS) && $vars['noalerts'] == self::FLAG_NOALERTS))
$auditAlerts = true;

foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && $key != 'members') { if (isset($this->$key) && ($this->$key != $value) && $key != 'members' ||
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key)); ($auditEnabled && $key == 'isenabled' || $auditAlerts && $key == 'noalerts')) {
$type = array('type' => 'edited', 'data' =>
array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);
} }
} }
Expand All @@ -175,7 +190,7 @@ function update($vars, &$errors=array()) {


$this->flags = $this->flags =
($vars['isenabled'] ? self::FLAG_ENABLED : 0) ($vars['isenabled'] ? self::FLAG_ENABLED : 0)
| (isset($vars['noalerts']) ? self::FLAG_NOALERTS : 0); | ($vars['noalerts']);
$this->lead_id = $vars['lead_id'] ?: 0; $this->lead_id = $vars['lead_id'] ?: 0;
$this->name = Format::striptags($vars['name']); $this->name = Format::striptags($vars['name']);
$this->notes = Format::sanitize($vars['notes']); $this->notes = Format::sanitize($vars['notes']);
Expand Down
Loading

0 comments on commit 7cfc062

Please sign in to comment.