Skip to content

Commit

Permalink
Add Dashboard Logging
Browse files Browse the repository at this point in the history
Add Create, Edit, or Delete logging for the following:

- Departments
- Organizations
- Staff
- Task
- Ticket
- User
- Canned Response
- FAQ Categories
- Emails
- FAQs
- Ticket Filters
- Help Topics
- Lists
- Pages
- Roles
- SLA
- Teams
- Email Templates
  • Loading branch information
aydreeihn committed Oct 10, 2019
1 parent 72974c8 commit 27cfd65
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 13 deletions.
3 changes: 3 additions & 0 deletions include/class.dept.php
Expand Up @@ -879,6 +879,9 @@ function update($vars, &$errors) {
// The ID wasn't available until after the commit // The ID wasn't available until after the commit
$this->path = $this->getFullPath(); $this->path = $this->getFullPath();
$this->save(); $this->save();
} else {
$type = array('type' => 'edited');
Signal::send('object.edited', $this, $type);
} }
return true; return true;
} }
Expand Down
3 changes: 3 additions & 0 deletions include/class.organization.php
Expand Up @@ -443,6 +443,9 @@ function updateProfile($vars, &$errors) {
)); ));
} }


$type = array('type' => 'edited');
Signal::send('object.edited', $this, $type);

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


Expand Down
6 changes: 6 additions & 0 deletions include/class.staff.php
Expand Up @@ -779,6 +779,9 @@ function updateProfile($vars, &$errors) {
); );
$this->_config = $_config->getInfo(); $this->_config = $_config->getInfo();


$type = array('type' => 'edited');
Signal::send('object.edited', $this, $type);

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


Expand Down Expand Up @@ -1170,6 +1173,9 @@ function update($vars, &$errors) {
if ($this->save()) { if ($this->save()) {
if ($vars['welcome_email']) if ($vars['welcome_email'])
$this->sendResetEmail('registration-staff', false); $this->sendResetEmail('registration-staff', false);

$type = array('type' => 'edited');
Signal::send('object.edited', $this, $type);
return true; return true;
} }


Expand Down
6 changes: 3 additions & 3 deletions include/class.task.php
Expand Up @@ -678,6 +678,9 @@ function claim(ClaimForm $form, &$errors) {
if ($errors) if ($errors)
return false; return false;


$type = array('type' => 'assigned', 'data' => array('claim' => true));
Signal::send('object.edited', $this, $type);

return $this->assignToStaff($assignee, $form->getComments(), false); return $this->assignToStaff($assignee, $form->getComments(), false);
} }


Expand Down Expand Up @@ -705,9 +708,6 @@ function assignToStaff($staff, $note, $alert=true) {


$this->logEvent('assigned', $data); $this->logEvent('assigned', $data);


$type = array('type' => 'assigned', 'data' => array('name' => $this->getNumber(), 'staff' => $staff->getName()->name));
Signal::send('object.edited', $this, $type);

return true; return true;
} }


Expand Down
2 changes: 1 addition & 1 deletion include/class.ticket.php
Expand Up @@ -2742,7 +2742,7 @@ function assignToStaff($staff, $note, $alert=true, $user=null) {


$this->logEvent('assigned', $data, $user); $this->logEvent('assigned', $data, $user);


$type = array('type' => 'assigned', 'data' => array('name' => $this->getNumber(), 'staff' => $staff->getName()->name)); $type = array('type' => 'assigned', 'data' => array('claim' => true));
Signal::send('object.edited', $this, $type); Signal::send('object.edited', $this, $type);


return true; return true;
Expand Down
5 changes: 5 additions & 0 deletions include/class.user.php
Expand Up @@ -251,6 +251,8 @@ static function fromVars($vars, $create=true, $update=false) {
catch (OrmException $e) { catch (OrmException $e) {
return null; return null;
} }
$type = array('type' => 'created', 'data' => array('id' => $user->getId(), 'name' => $user->getName()->name));
Signal::send('object.created', $user, $type);
Signal::send('user.created', $user); Signal::send('user.created', $user);
} }
elseif ($update) { elseif ($update) {
Expand Down Expand Up @@ -641,6 +643,9 @@ function delete() {
$entry->delete(); $entry->delete();
} }


$type = array('type' => 'deleted', 'data' => array('id' => $this->getId(), 'name' => $this->getName()->name));
Signal::send('object.deleted', $this, $type);

// Delete user // Delete user
return parent::delete(); return parent::delete();
} }
Expand Down
10 changes: 9 additions & 1 deletion scp/canned.php
Expand Up @@ -53,6 +53,9 @@
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
__('this canned response')); __('this canned response'));


$type = array('type' => 'edited');
Signal::send('object.edited', $canned, $type);

//Delete removed attachments. //Delete removed attachments.
//XXX: files[] shouldn't be changed under any circumstances. //XXX: files[] shouldn't be changed under any circumstances.
// Upload NEW attachments IF ANY - TODO: validate attachment types?? // Upload NEW attachments IF ANY - TODO: validate attachment types??
Expand Down Expand Up @@ -84,6 +87,8 @@
$premade = Canned::create(); $premade = Canned::create();
if ($premade->update($_POST,$errors)) { if ($premade->update($_POST,$errors)) {
$msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['title'])); $msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['title']));
$type = array('type' => 'created');
Signal::send('object.created', $premade, $type);
$_REQUEST['a']=null; $_REQUEST['a']=null;
//Upload attachments //Upload attachments
$keepers = $canned_form->getField('attachments')->getClean(); $keepers = $canned_form->getField('attachments')->getClean();
Expand Down Expand Up @@ -144,8 +149,11 @@


$i=0; $i=0;
foreach($_POST['ids'] as $k=>$v) { foreach($_POST['ids'] as $k=>$v) {
if(($c=Canned::lookup($v)) && $c->delete()) if(($c=Canned::lookup($v)) && $c->delete()) {
// $type = array('type' => 'deleted');
// Signal::send('object.deleted', $c, $type);
$i++; $i++;
}
} }


if($i==$count) if($i==$count)
Expand Down
4 changes: 3 additions & 1 deletion scp/categories.php
Expand Up @@ -41,14 +41,16 @@
sprintf(__('Unable to update %s.'), __('this category')), sprintf(__('Unable to update %s.'), __('this category')),
__('Correct any errors below and try again.')); __('Correct any errors below and try again.'));
} }
$type = array('type' => 'edited');
Signal::send('object.edited', $category, $type);
break; break;
case 'create': case 'create':
$category = Category::create(); $category = Category::create();
if ($category->update($_POST, $errors)) { if ($category->update($_POST, $errors)) {
$msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name'])); $msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name']));
$_REQUEST['a']=null;
$type = array('type' => 'created'); $type = array('type' => 'created');
Signal::send('object.created', $category, $type); Signal::send('object.created', $category, $type);
$_REQUEST['a']=null;
} elseif(!$errors['err']) { } elseif(!$errors['err']) {
$errors['err'] = sprintf('%s %s', $errors['err'] = sprintf('%s %s',
sprintf(__('Unable to add %s.'), __('this category')), sprintf(__('Unable to add %s.'), __('this category')),
Expand Down
4 changes: 4 additions & 0 deletions scp/departments.php
Expand Up @@ -105,6 +105,8 @@
FilterAction::setFilterFlag($filter_actions, 'dept', false); FilterAction::setFilterFlag($filter_actions, 'dept', false);
if($d->save()) if($d->save())
$num++; $num++;
$type = array('type' => 'edited', 'data' => array('type' => 'Enabled'));
Signal::send('object.edited', $d, $type);
} }


if ($num > 0) { if ($num > 0) {
Expand All @@ -131,6 +133,8 @@
$filter_actions = FilterAction::objects()->filter(array('type' => 'dept', 'configuration' => '{"dept_id":'. $d->getId().'}')); $filter_actions = FilterAction::objects()->filter(array('type' => 'dept', 'configuration' => '{"dept_id":'. $d->getId().'}'));
FilterAction::setFilterFlag($filter_actions, 'dept', true); FilterAction::setFilterFlag($filter_actions, 'dept', true);
if($d->save()) { if($d->save()) {
$type = array('type' => 'edited', 'data' => array('type' => 'Disabled'));
Signal::send('object.edited', $d, $type);
$num++; $num++;
} }
} }
Expand Down
10 changes: 9 additions & 1 deletion scp/emails.php
Expand Up @@ -28,6 +28,8 @@
}elseif($email->update($_POST,$errors)){ }elseif($email->update($_POST,$errors)){
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
__('this email')); __('this email'));
$type = array('type' => 'edited');
Signal::send('object.edited', $email, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err'] = sprintf('%s %s', $errors['err'] = sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this email')), sprintf(__('Unable to update %s.'), __('this email')),
Expand All @@ -40,6 +42,8 @@
$id = $box->getId(); $id = $box->getId();
$msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name'])); $msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name']));
$_REQUEST['a']=null; $_REQUEST['a']=null;
$type = array('type' => 'created');
Signal::send('object.created', $box, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
sprintf(__('Unable to add %s.'), __('this email')), sprintf(__('Unable to add %s.'), __('this email')),
Expand All @@ -57,8 +61,12 @@
case 'delete': case 'delete':
$i=0; $i=0;
foreach($_POST['ids'] as $k=>$v) { foreach($_POST['ids'] as $k=>$v) {
if($v!=$cfg->getDefaultEmailId() && ($e=Email::lookup($v)) && $e->delete()) if($v!=$cfg->getDefaultEmailId() && ($e=Email::lookup($v)) && $e->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $e, $type);
$i++; $i++;
}

} }


if($i && $i==$count) if($i && $i==$count)
Expand Down
2 changes: 2 additions & 0 deletions scp/faq.php
Expand Up @@ -102,6 +102,8 @@
$errors['err'] = sprintf('%s %s', $errors['err'] = sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this FAQ article')), sprintf(__('Unable to update %s.'), __('this FAQ article')),
__('Correct any errors below and try again.')); __('Correct any errors below and try again.'));
$type = array('type' => 'edited');
Signal::send('object.edited', $faq, $type);
break; break;
case 'manage-faq': case 'manage-faq':
if(!$faq) { if(!$faq) {
Expand Down
10 changes: 9 additions & 1 deletion scp/filters.php
Expand Up @@ -32,6 +32,8 @@
$errors['err']=sprintf(__('%s: Unknown or invalid'), __('ticket filter')); $errors['err']=sprintf(__('%s: Unknown or invalid'), __('ticket filter'));
}elseif($filter->update($_POST,$errors)){ }elseif($filter->update($_POST,$errors)){
$msg=sprintf(__('Successfully updated %s.'), __('this ticket filter')); $msg=sprintf(__('Successfully updated %s.'), __('this ticket filter'));
$type = array('type' => 'edited');
Signal::send('object.edited', $filter, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this ticket filter')), sprintf(__('Unable to update %s.'), __('this ticket filter')),
Expand All @@ -42,6 +44,8 @@
$filter = new Filter(); $filter = new Filter();
if ($filter->update($_POST, $errors)) { if ($filter->update($_POST, $errors)) {
$msg=sprintf(__('Successfully updated %s.'), __('this ticket filter')); $msg=sprintf(__('Successfully updated %s.'), __('this ticket filter'));
$type = array('type' => 'created');
Signal::send('object.created', $filter, $type);
$_REQUEST['a']=null; $_REQUEST['a']=null;
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err'] = sprintf('%s %s', $errors['err'] = sprintf('%s %s',
Expand Down Expand Up @@ -103,8 +107,12 @@
case 'delete': case 'delete':
$i=0; $i=0;
foreach($_POST['ids'] as $k=>$v) { foreach($_POST['ids'] as $k=>$v) {
if(($f=Filter::lookup($v)) && !$f->isSystemBanlist() && $f->delete()) if(($f=Filter::lookup($v)) && !$f->isSystemBanlist() && $f->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $f, $type);
$i++; $i++;
}

} }


if($i && $i==$count) if($i && $i==$count)
Expand Down
4 changes: 4 additions & 0 deletions scp/helptopics.php
Expand Up @@ -30,6 +30,8 @@
}elseif($topic->update($_POST,$errors)){ }elseif($topic->update($_POST,$errors)){
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
__('this help topic')); __('this help topic'));
$type = array('type' => 'edited');
Signal::send('object.edited', $topic, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err'] = sprintf('%s %s', $errors['err'] = sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this help topic')), sprintf(__('Unable to update %s.'), __('this help topic')),
Expand All @@ -41,6 +43,8 @@
if ($_topic->update($_POST, $errors)) { if ($_topic->update($_POST, $errors)) {
$topic = $_topic; $topic = $_topic;
$msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['topic'])); $msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['topic']));
$type = array('type' => 'created');
Signal::send('object.created', $topic, $type);
$_REQUEST['a']=null; $_REQUEST['a']=null;
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
Expand Down
9 changes: 8 additions & 1 deletion scp/lists.php
Expand Up @@ -87,6 +87,8 @@
$list->_items = null; $list->_items = null;
$msg = sprintf(__('Successfully updated %s.'), $msg = sprintf(__('Successfully updated %s.'),
__('this custom list')); __('this custom list'));
$type = array('type' => 'edited');
Signal::send('object.edited', $list, $type);
} }


} elseif ($errors) } elseif ($errors)
Expand All @@ -102,6 +104,8 @@
if ($list=DynamicList::add($_POST, $errors)) { if ($list=DynamicList::add($_POST, $errors)) {
$form = $list->getForm(true); $form = $list->getForm(true);
Messages::success(sprintf(__('Successfully added %s.'), __('this custom list'))); Messages::success(sprintf(__('Successfully added %s.'), __('this custom list')));
$type = array('type' => 'created');
Signal::send('object.created', $list, $type);
// Redirect to list page // Redirect to list page
$redirect = "lists.php?id={$list->id}#items"; $redirect = "lists.php?id={$list->id}#items";
} elseif ($errors) { } elseif ($errors) {
Expand All @@ -124,8 +128,11 @@
case 'delete': case 'delete':
$i=0; $i=0;
foreach($_POST['ids'] as $k=>$v) { foreach($_POST['ids'] as $k=>$v) {
if(($t=DynamicList::lookup($v)) && $t->delete()) if(($t=DynamicList::lookup($v)) && $t->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $t, $type);
$i++; $i++;
}
} }
if ($i && $i==$count) if ($i && $i==$count)
$msg = sprintf(__('Successfully deleted %s.'), $msg = sprintf(__('Successfully deleted %s.'),
Expand Down
4 changes: 4 additions & 0 deletions scp/pages.php
Expand Up @@ -28,6 +28,8 @@
$pageId = $page->getId(); $pageId = $page->getId();
$_REQUEST['a'] = null; $_REQUEST['a'] = null;
$msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name'])); $msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name']));
$type = array('type' => 'created');
Signal::send('object.created', $page, $type);
Draft::deleteForNamespace('page'); Draft::deleteForNamespace('page');
} elseif(!$errors['err']) } elseif(!$errors['err'])
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
Expand All @@ -41,6 +43,8 @@
elseif($page->update($_POST, $errors)) { elseif($page->update($_POST, $errors)) {
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
__('this site page')); __('this site page'));
$type = array('type' => 'edited');
Signal::send('object.edited', $page, $type);
$_REQUEST['a']=null; //Go back to view $_REQUEST['a']=null; //Go back to view
Draft::deleteForNamespace('page.'.$page->getId().'%'); Draft::deleteForNamespace('page.'.$page->getId().'%');
} elseif(!$errors['err']) } elseif(!$errors['err'])
Expand Down
9 changes: 8 additions & 1 deletion scp/roles.php
Expand Up @@ -37,6 +37,8 @@
__('Role')); __('Role'));
} elseif ($role->update($_POST, $errors)) { } elseif ($role->update($_POST, $errors)) {
$msg = __('Role updated successfully'); $msg = __('Role updated successfully');
$type = array('type' => 'edited');
Signal::send('object.edited', $role, $type);
} elseif ($errors) { } elseif ($errors) {
$errors['err'] = $errors['err'] ?: sprintf('%s %s', $errors['err'] = $errors['err'] ?: sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this role')), sprintf(__('Unable to update %s.'), __('this role')),
Expand All @@ -53,6 +55,8 @@
unset($_REQUEST['a']); unset($_REQUEST['a']);
$msg = sprintf(__('Successfully added %s.'), $msg = sprintf(__('Successfully added %s.'),
__('role')); __('role'));
$type = array('type' => 'created');
Signal::send('object.created', $_role, $type);
} elseif ($errors) { } elseif ($errors) {
$errors['err'] = sprintf('%s %s', $errors['err'] = sprintf('%s %s',
sprintf(__('Unable to add %s.'), __('this role')), sprintf(__('Unable to add %s.'), __('this role')),
Expand Down Expand Up @@ -113,8 +117,11 @@
case 'delete': case 'delete':
$i=0; $i=0;
foreach ($_POST['ids'] as $k=>$v) { foreach ($_POST['ids'] as $k=>$v) {
if (($r=Role::lookup($v)) && $r->isDeleteable() && $r->delete()) if (($r=Role::lookup($v)) && $r->isDeleteable() && $r->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $r, $type);
$i++; $i++;
}
} }
if ($i && $i==$count) if ($i && $i==$count)
$msg = sprintf(__('Successfully deleted %s.'), $msg = sprintf(__('Successfully deleted %s.'),
Expand Down
11 changes: 9 additions & 2 deletions scp/slas.php
Expand Up @@ -30,6 +30,8 @@
}elseif($sla->update($_POST,$errors)){ }elseif($sla->update($_POST,$errors)){
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
__('this SLA plan')); __('this SLA plan'));
$type = array('type' => 'edited');
Signal::send('object.edited', $sla, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this SLA plan')), sprintf(__('Unable to update %s.'), __('this SLA plan')),
Expand All @@ -41,6 +43,8 @@
if (($_sla->update($_POST, $errors))) { if (($_sla->update($_POST, $errors))) {
$msg=sprintf(__('Successfully added %s.'), $msg=sprintf(__('Successfully added %s.'),
__('a SLA plan')); __('a SLA plan'));
$type = array('type' => 'created');
Signal::send('object.created', $_sla, $type);
$_REQUEST['a']=null; $_REQUEST['a']=null;
} elseif (!$errors['err']) { } elseif (!$errors['err']) {
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
Expand Down Expand Up @@ -99,8 +103,11 @@
foreach ($_POST['ids'] as $k => $v) { foreach ($_POST['ids'] as $k => $v) {
if (($p=SLA::lookup($v)) if (($p=SLA::lookup($v))
&& $p->getId() != $cfg->getDefaultSLAId() && $p->getId() != $cfg->getDefaultSLAId()
&& $p->delete()) && $p->delete()) {
$i++; $type = array('type' => 'deleted');
Signal::send('object.deleted', $p, $type);
$i++;
}
} }


if($i && $i==$count) if($i && $i==$count)
Expand Down
2 changes: 2 additions & 0 deletions scp/teams.php
Expand Up @@ -27,6 +27,8 @@
}elseif($team->update($_POST,$errors)){ }elseif($team->update($_POST,$errors)){
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
__('this team')); __('this team'));
$type = array('type' => 'edited');
Signal::send('object.edited', $team, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this team')), sprintf(__('Unable to update %s.'), __('this team')),
Expand Down
10 changes: 9 additions & 1 deletion scp/templates.php
Expand Up @@ -70,6 +70,8 @@
}elseif($template->update($_POST,$errors)){ }elseif($template->update($_POST,$errors)){
$msg=sprintf(__('Successfully updated %s.'), $msg=sprintf(__('Successfully updated %s.'),
mb_convert_case(__('this message template'), MB_CASE_TITLE)); mb_convert_case(__('this message template'), MB_CASE_TITLE));
$type = array('type' => 'edited');
Signal::send('object.edited', $template, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
sprintf(__('Unable to update %s.'), __('this message template')), sprintf(__('Unable to update %s.'), __('this message template')),
Expand All @@ -82,6 +84,8 @@
$msg=sprintf(__('Successfully added %s.'), $msg=sprintf(__('Successfully added %s.'),
mb_convert_case(__('a template set'), MB_CASE_TITLE)); mb_convert_case(__('a template set'), MB_CASE_TITLE));
$_REQUEST['a']=null; $_REQUEST['a']=null;
$type = array('type' => 'created');
Signal::send('object.created', $new, $type);
}elseif(!$errors['err']){ }elseif(!$errors['err']){
$errors['err']=sprintf('%s %s', $errors['err']=sprintf('%s %s',
sprintf(__('Unable to add %s.'), __('this message template')), sprintf(__('Unable to add %s.'), __('this message template')),
Expand Down Expand Up @@ -131,8 +135,12 @@
case 'delete': case 'delete':
$i=0; $i=0;
foreach($_POST['ids'] as $k=>$v) { foreach($_POST['ids'] as $k=>$v) {
if(($t=EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $t->delete()) if(($t=EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $t->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $t, $type);
$i++; $i++;
}

} }


if($i && $i==$count) if($i && $i==$count)
Expand Down

0 comments on commit 27cfd65

Please sign in to comment.