Skip to content
Permalink
Browse files

Fix Configuration Audits

- 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 Jun 18, 2019
1 parent 349c982 commit 7cfc062e3e032b967874fb5806f234cce22949d8
@@ -610,6 +610,10 @@ public function setFlag($flag, $val) {
$this->flags &= ~$flag;
}
function hasFlag($flag) {
return ($this->get('flags', 0) & $flag) != 0;
}
function export($dept, $criteria=null, $filename='') {
include_once(INCLUDE_DIR.'class.error.php');
$members = $dept->getMembers();
@@ -813,13 +817,19 @@ function update($vars, &$errors) {
if ($errors)
return false;
$vars['disable_auto_claim'] = isset($vars['disable_auto_claim']) ? 1 : 0;
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) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'type' => ucfirst($value)));
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;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
@@ -868,8 +878,6 @@ function update($vars, &$errors) {
$this->setFlag(self::FLAG_ARCHIVED, true);
}
$this->setFlag(self::FLAG_DISABLE_AUTO_CLAIM, isset($vars['disable_auto_claim']));
switch ($vars['assignment_flag']) {
case 'all':
$this->setFlag(self::FLAG_ASSIGN_MEMBERS_ONLY, false);
@@ -386,6 +386,9 @@ function update($vars, &$errors=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)) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
@@ -402,7 +405,7 @@ function update($vars, &$errors=false) {
$this->dept_id = $vars['dept_id'];
$this->priority_id = $vars['priority_id'];
$this->topic_id = $vars['topic_id'];
$this->noautoresp = isset($vars['noautoresp'])?1:0;
$this->noautoresp = $vars['noautoresp'];
$this->userid = $vars['userid'];
$this->mail_active = $vars['mail_active'];
$this->mail_host = $vars['mail_host'];
@@ -415,7 +418,7 @@ function update($vars, &$errors=false) {
$this->smtp_host = $vars['smtp_host'];
$this->smtp_port = $vars['smtp_port'] ?: 0;
$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']);
//Post fetch email handling...
@@ -417,10 +417,76 @@ function update($vars, &$errors) {
if (!$this->update($vars, $errors))
$errors['error'] = __('Unable to update organization form');
if ($errors)
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
foreach (array(
'collab-all-flag' => Organization::COLLAB_ALL_MEMBERS,
@@ -437,6 +503,13 @@ function update($vars, &$errors) {
'sharing-primary' => Organization::SHARE_PRIMARY_CONTACT,
'sharing-all' => Organization::SHARE_EVERYBODY,
) 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)
$this->setStatus($flag);
else
@@ -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();
}
@@ -106,6 +106,10 @@ function sendAlerts() {
return 0 === ($this->flags & self::FLAG_NOALERTS);
}
function hasFlag($flag) {
return ($this->get('flags', 0) & $flag) != 0;
}
function alertOnOverdue() {
return $this->sendAlerts();
}
@@ -158,10 +162,23 @@ function update($vars, &$errors) {
if ($errors)
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)) {
//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) {
if (isset($this->$key) && ($this->$key != $value)) {
$loggedUpdate = true;
if (isset($this->$key) && ($this->$key != $value) ||
($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));
Signal::send('object.edited', $this, $type);
}
@@ -174,17 +191,12 @@ function update($vars, &$errors) {
$this->notes = Format::sanitize($vars['notes']);
$this->flags =
($vars['isactive'] ? self::FLAG_ACTIVE : 0)
| (isset($vars['disable_overdue_alerts']) ? self::FLAG_NOALERTS : 0)
| (isset($vars['enable_priority_escalation']) ? self::FLAG_ESCALATE : 0)
| (isset($vars['transient']) ? self::FLAG_TRANSIENT : 0);
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);
}
| ($vars['disable_overdue_alerts'])
| ($vars['enable_priority_escalation'])
| ($vars['transient']);
if ($this->save())
return true;
}
if (isset($this->id)) {
$errors['err']=sprintf(__('Unable to update %s.'), __('this SLA plan'))
@@ -741,10 +741,13 @@ function updateProfile($vars, &$errors) {
}
}
$vars['onvacation'] = isset($vars['onvacation']) ? 1 : 0;
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $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);
}
}
@@ -764,7 +767,7 @@ function updateProfile($vars, &$errors) {
$this->default_signature_type = $vars['default_signature_type'];
$this->default_paper_size = $vars['default_paper_size'];
$this->lang = $vars['lang'];
$this->onvacation = isset($vars['onvacation']) ? 1 : 0;
$this->onvacation = $vars['onvacation'];
if (isset($vars['avatar_code']))
$this->setExtraAttr('avatar', $vars['avatar_code']);
@@ -1152,21 +1155,30 @@ function update($vars, &$errors) {
// Update the local permissions
$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)) {
foreach ($vars as $key => $value) {
if ($key == 'islocked') $key = 'isactive';
if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms') && ($key != 'teams')) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
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));
Signal::send('object.edited', $this, $type);
}
if ($key == 'isactive') $key = 'islocked';
}
}
$this->isadmin = $vars['isadmin'];
$this->isactive = isset($vars['islocked']) ? 0 : 1;
$this->isvisible = isset($vars['isvisible'])?1:0;
$this->onvacation = isset($vars['onvacation'])?1:0;
$this->assigned_only = isset($vars['assigned_only'])?1:0;
$this->isactive = $vars['islocked'];
$this->isvisible = $vars['isvisible'];
$this->onvacation = $vars['onvacation'];
$this->assigned_only = $vars['assigned_only'];
$this->role_id = $vars['role_id'];
$this->username = $vars['username'];
$this->firstname = $vars['firstname'];
@@ -1212,6 +1224,7 @@ function update($vars, &$errors) {
* be indexed by the dept_id number.
*/
function updateAccess($access, &$errors) {
global $thisstaff;
reset($access);
$dropped = array();
foreach ($this->dept_access as $DA)
@@ -1220,7 +1233,7 @@ function updateAccess($access, &$errors) {
unset($dropped[$dept_id]);
if (!$role_id || !Role::lookup($role_id))
$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');
if ($dept_id == $this->getDeptId())
$errors['dept_access'][$dept_id] = sprintf(__('Agent already has access to %s'), __('this department'));
@@ -1230,6 +1243,12 @@ function updateAccess($access, &$errors) {
'dept_id' => $dept_id, 'role_id' => $role_id
));
$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 {
$da->role_id = $role_id;
@@ -1243,6 +1262,15 @@ function updateAccess($access, &$errors) {
->filter(array('dept_id__in' => array_keys($dropped)))
->delete();
$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;
}
@@ -130,6 +130,10 @@ function isAvailable() {
return ($this->isActive() && $this->members);
}
function hasFlag($flag) {
return ($this->get('flags', 0) & $flag) != 0;
}
function alertsEnabled() {
return ($this->flags & self::FLAG_NOALERTS) == 0;
}
@@ -157,10 +161,21 @@ function update($vars, &$errors=array()) {
$errors['name']=__('Team name already exists');
}
$vars['noalerts'] = isset($vars['noalerts']) ? self::FLAG_NOALERTS : 0;
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) {
if (isset($this->$key) && ($this->$key != $value) && $key != 'members') {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
if (isset($this->$key) && ($this->$key != $value) && $key != 'members' ||
($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);
}
}
@@ -175,7 +190,7 @@ function update($vars, &$errors=array()) {
$this->flags =
($vars['isenabled'] ? self::FLAG_ENABLED : 0)
| (isset($vars['noalerts']) ? self::FLAG_NOALERTS : 0);
| ($vars['noalerts']);
$this->lead_id = $vars['lead_id'] ?: 0;
$this->name = Format::striptags($vars['name']);
$this->notes = Format::sanitize($vars['notes']);

0 comments on commit 7cfc062

Please sign in to comment.
You can’t perform that action at this time.