Skip to content
Permalink
Browse files

Code Cleanup

- Reduce lines of code for Organization audits
- Refer to audit files in phar format, not normal file format
- Update Plugin name
- Remove unneeded comments
- Do not write audit record if the object hasn't been initially saved yet (Dept/Team create)
- Add the audits.php file
  • Loading branch information...
aydreeihn committed Jul 11, 2019
1 parent e0ca7e2 commit d942b160b36e7b2c4c59ab62f14251e71284681f
@@ -824,7 +824,7 @@ function update($vars, &$errors) {
return false;
$vars['disable_auto_claim'] = isset($vars['disable_auto_claim']) ? 1 : 0;
if (PluginManager::auditPlugin()) {
if (PluginManager::auditPlugin() && $this->getId()) {
//flags
$disableAutoClaim = $this->flagChanged(self::FLAG_DISABLE_AUTO_CLAIM, $vars['disable_auto_claim']);
$ticketAssignment = ($this->getAssignmentFlag() != $vars['assignment_flag']);
@@ -115,6 +115,11 @@ function autoAssignAccountManager() {
return $this->check(self::ASSIGN_AGENT_MANAGER);
}
function autoFlagChanged($flag, $var) {
if (($flag && !$var) || (!$flag && $var))
return true;
}
function shareWithPrimaryContacts() {
return $this->check(self::SHARE_PRIMARY_CONTACT);
}
@@ -123,6 +128,11 @@ function shareWithEverybody() {
return $this->check(self::SHARE_EVERYBODY);
}
function sharingFlagChanged($flag, $var, $title) {
if (($flag && !$var) || (!$flag && $var == $title))
return true;
}
function getUpdateDate() {
return $this->updated;
}
@@ -447,21 +457,15 @@ function update($vars, &$errors) {
}
if (PluginManager::auditPlugin()) {
if (($this->autoAddMembersAsCollabs() && !$vars['collab-all-flag']) ||
(!$this->autoAddMembersAsCollabs() && $vars['collab-all-flag'])) {
$auditCollabAll = true;
if ($auditCollabAll = $this->autoFlagChanged($this->autoAddMembersAsCollabs(),
$vars['collab-all-flag']))
$key = 'collab-all-flag';
}
if (($this->autoAddPrimaryContactsAsCollabs() && !$vars['collab-pc-flag']) ||
(!$this->autoAddPrimaryContactsAsCollabs() && $vars['collab-pc-flag'])) {
$auditCollabPc = true;
if ($auditCollabPc = $this->autoFlagChanged($this->autoAddPrimaryContactsAsCollabs(),
$vars['collab-pc-flag']))
$key = 'collab-pc-flag';
}
if (($this->autoAssignAccountManager() && !$vars['assign-am-flag']) ||
(!$this->autoAssignAccountManager() && $vars['assign-am-flag'])) {
$auditAssignAm = true;
if ($auditAssignAm = $this->autoFlagChanged($this->autoAssignAccountManager(),
$vars['assign-am-flag']))
$key = 'assign-am-flag';
}
if ($auditCollabAll || $auditCollabPc || $auditAssignAm) {
$type = array('type' => 'edited', 'key' => $key);
@@ -476,16 +480,10 @@ function update($vars, &$errors) {
}
}
if ((!$this->shareWithPrimaryContacts() && $vars['sharing'] == 'sharing-primary') ||
($this->shareWithPrimaryContacts() && !$vars['sharing'])) {
$sharingPrimary = true;
$key = 'sharing-primary';
}
if ((!$this->shareWithEverybody() && $vars['sharing'] == 'sharing-all') ||
($this->shareWithEverybody() && !$vars['sharing'])) {
$sharingEverybody = true;
$key = 'sharing-all';
}
$sharingPrimary = $this->sharingFlagChanged($this->shareWithPrimaryContacts(),
$vars['sharing'], 'sharing-primary');
$sharingEverybody = $this->sharingFlagChanged($this->shareWithEverybody(),
$vars['sharing'], 'sharing-all');
// Set flags
foreach (array(
@@ -505,7 +503,7 @@ function update($vars, &$errors) {
) as $ck=>$flag) {
if (PluginManager::auditPlugin()) {
if (($sharingPrimary || $sharingEverybody) && $key == $ck) {
$type = array('type' => 'edited', 'key' => 'sharing'); //adriane
$type = array('type' => 'edited', 'key' => 'sharing');
Signal::send('object.edited', $this, $type);
}
}
@@ -222,7 +222,7 @@ static function getPluginByName($name, $active=false) {
}
static function auditPlugin() {
return self::getPluginByName('View auditing for tickets', true);
return self::getPluginByName('Help Desk Audit', true);
}
static function allActive() {
@@ -697,7 +697,7 @@ function onLogin($bk) {
//Staff profile update...unfortunately we have to separate it from admin update to avoid potential issues
function updateProfile($vars, &$errors) {
global $cfg, $thisstaff;
global $cfg;
$vars['firstname']=Format::striptags($vars['firstname']);
$vars['lastname']=Format::striptags($vars['lastname']);
@@ -166,7 +166,7 @@ function update($vars, &$errors=array()) {
}
$vars['noalerts'] = isset($vars['noalerts']) ? self::FLAG_NOALERTS : 0;
if (PluginManager::auditPlugin()) {
if (PluginManager::auditPlugin() && $this->getId()) {
//flags
$auditEnabled = $this->flagChanged(self::FLAG_ENABLED, $vars['isenabled']);
$auditAlerts = $this->flagChanged(self::FLAG_NOALERTS, $vars['noalerts']);
@@ -437,7 +437,7 @@ function lookup($id){
}
function save($id, $vars, &$errors) {
global $ost, $thisstaff;
global $ost;
$tpl=null;
$vars['name']=Format::striptags(trim($vars['name']));
@@ -3012,7 +3012,7 @@ function changeOwner($user) {
// Insert message from client
function postMessage($vars, $origin='', $alerts=true) {
global $cfg, $thisstaff;
global $cfg;
if ($origin)
$vars['origin'] = $origin;
@@ -414,7 +414,7 @@ static function getIdByName($name, $pid=0) {
}
function update($vars, &$errors) {
global $cfg, $thisstaff;
global $cfg;
$vars['topic'] = Format::striptags(trim($vars['topic']));
@@ -447,7 +447,7 @@ function update($vars, &$errors) {
if (PluginManager::auditPlugin()) {
foreach ($vars as $key => $value) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value && $this->topic) {
$type = array('type' => 'edited', 'status' => ucfirst($value));
Signal::send('object.edited', $this, $type);
} elseif (isset($this->$key) && ($this->$key != $value) && ($key != 'forms')) {
@@ -35,8 +35,6 @@
}
if (PluginManager::auditPlugin()) {
// Allow extensions to add extra items to this form.
// $extras should be a array of [url=>, tab=>]
$extras = new ArrayObject();
Signal::send('agent.audit', $staff, $extras);
@@ -266,8 +266,6 @@ class="icon-group"></i> <?php echo __('Team'); ?></a>
}
}
if (PluginManager::auditPlugin()) {
// Allow extensions to add extra items to this ticket.
// $extras should be a array of [url=>, name=>, icon=>]
$extras = new ArrayObject();
Signal::send('ticket.view.more', $ticket, $extras);
foreach ($extras as $li) {
@@ -72,8 +72,6 @@ class="icon-lock"></i>
<?php echo __('Manage Forms'); ?></a></li>
<?php }
if (PluginManager::auditPlugin()) {
// Allow extensions to add extra items to this user.
// $extras should be a array of [url=>, name=>, icon=>]
$extras = new ArrayObject();
Signal::send('user.view.more', $user, $extras);
@@ -0,0 +1,45 @@
<?php
/*********************************************************************
audits.php
Audit Logs
Adriane Alexander
Copyright (c) 2006-2019 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require('admin.inc.php');
if (PluginManager::auditPlugin())
require_once(sprintf('phar:///%s/plugins/audit.phar/class.audit.php', INCLUDE_DIR));
switch (strtolower($_REQUEST['t'])) {
case 'audits':
if (PluginManager::auditPlugin() && $_REQUEST['a'] == 'export') {
foreach (AuditEntry::getTypes() as $abbrev => $info) {
if ($_REQUEST['type'] == $abbrev)
$name = AuditEntry::getObjectName($info[0]);
}
$filename = sprintf('%s-audits-%s.csv',
$name, strftime('%Y%m%d'));
if (!Export::audits('audit', $filename))
$errors['err'] = __('Unable to dump query results.')
.' '.__('Internal error occurred');
}
break;
}
$page= sprintf('phar:///%s/plugins/audit.phar/templates/auditlogs.tmpl.php', INCLUDE_DIR);
$nav->setTabActive('dashboard');
$ost->addExtraHeader('<meta name="tip-namespace" content="dashboard.audit_logs" />',
"$('#content').data('tipNamespace', 'dashboard.audit_logs');");
require(STAFFINC_DIR.'header.inc.php');
require($page);
include(STAFFINC_DIR.'footer.inc.php');
?>
@@ -183,8 +183,8 @@
$tip_namespace = 'staff.agent';
if($staff || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
if (strtolower($_REQUEST['t']) == 'audits') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
if (PluginManager::auditPlugin() && strtolower($_REQUEST['t']) == 'audits') {
require_once(sprintf('phar:///%s/plugins/audit.phar/class.audit.php', INCLUDE_DIR));
$show = AuditEntry::$show_view_audits;
$filename = sprintf('%s-audits-%s.csv',
$staff->getName(), strftime('%Y%m%d'));
@@ -504,8 +504,8 @@
elseif (!$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes'], $_REQUEST['events']))
$errors['err'] = __('Unable to export the ticket to PDF for print.')
.' '.__('Internal error occurred');
} elseif ($_REQUEST['a'] == 'export' && strtolower($_REQUEST['t']) == 'audits') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
} elseif (PluginManager::auditPlugin() && $_REQUEST['a'] == 'export' && strtolower($_REQUEST['t']) == 'audits') {
require_once(sprintf('phar:///%s/plugins/audit.phar/class.audit.php', INCLUDE_DIR));
$show = AuditEntry::$show_view_audits;
$filename = sprintf('%s-audits-%s.csv',
$ticket->getNumber(), strftime('%Y%m%d'));
@@ -215,8 +215,8 @@
}
break;
case 'audits':
if ($_REQUEST['a'] == 'export') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
if (PluginManager::auditPlugin() && $_REQUEST['a'] == 'export') {
require_once(sprintf('phar:///%s/plugins/audit.phar/class.audit.php', INCLUDE_DIR));
$show = AuditEntry::$show_view_audits;
$filename = sprintf('%s-audits-%s.csv',
$user->getName(), strftime('%Y%m%d'));

0 comments on commit d942b16

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