From d695ecbf7c44172b570469008028e33d83603e55 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 18 May 2015 15:13:13 -0500
Subject: [PATCH] thread: Hide edits to internal fields from clients

---
 include/class.thread.php                       | 8 ++++++--
 include/client/templates/thread-event.tmpl.php | 9 ++++++---
 include/staff/templates/thread-event.tmpl.php  | 2 +-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index 5b078a397..3b4676b9a 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1507,7 +1507,7 @@ class ThreadEvent extends VerySimpleModel {
         return @$icons[$this->state] ?: 'chevron-sign-right';
     }
 
-    function getDescription() {
+    function getDescription($mode=self::MODE_STAFF) {
         static $descs;
         if (!isset($descs))
             $descs = array(
@@ -1543,7 +1543,7 @@ class ThreadEvent extends VerySimpleModel {
             'edited:status' => __('<b>{username}</b> changed the status to <strong>{<TicketStatus>data.status}</strong> {timestamp}'),
             'overdue' => __('Flagged as overdue by the system {timestamp}'),
             'transferred' => __('<b>{username}</b> transferred this to <strong>{dept}</strong> {timestamp}'),
-            'edited:fields' => function($evt) {
+            'edited:fields' => function($evt) use ($mode) {
                 $base = __('Updated by <b>{username}</b> {timestamp} — %s');
                 $data = $evt->getData();
                 $fields = $changes = array();
@@ -1554,6 +1554,8 @@ class ThreadEvent extends VerySimpleModel {
                 }
                 foreach ($data['fields'] as $id=>$f) {
                     $field = $fields[$id];
+                    if ($mode == self::MODE_CLIENT && !$field->isVisibleToUsers())
+                        continue;
                     list($old, $new) = $f;
                     $impl = $field->getImpl($field);
                     $before = $impl->to_php($old);
@@ -1561,6 +1563,8 @@ class ThreadEvent extends VerySimpleModel {
                     $changes[] = sprintf('<strong>%s</strong> %s',
                         $field->getLocal('label'), $impl->whatChanged($before, $after));
                 }
+                if (!$changes)
+                    return '';
                 return sprintf($base, implode(', ', $changes));
             },
         );
diff --git a/include/client/templates/thread-event.tmpl.php b/include/client/templates/thread-event.tmpl.php
index f630268cb..42fd8027e 100644
--- a/include/client/templates/thread-event.tmpl.php
+++ b/include/client/templates/thread-event.tmpl.php
@@ -1,8 +1,11 @@
+<?php
+$desc = $event->getDescription(ThreadEvent::MODE_CLIENT);
+if (!$desc)
+    return;
+?>
 <div class="thread-event <?php if ($event->uid) echo 'action'; ?>">
         <span class="type-icon">
           <i class="faded icon-<?php echo $event->getIcon(); ?>"></i>
         </span>
-        <span class="faded description">
-            <?php echo $event->getDescription(); ?>
-        </span>
+        <span class="faded description"><?php echo $desc; ?></span>
 </div>
diff --git a/include/staff/templates/thread-event.tmpl.php b/include/staff/templates/thread-event.tmpl.php
index f630268cb..f98a1e320 100644
--- a/include/staff/templates/thread-event.tmpl.php
+++ b/include/staff/templates/thread-event.tmpl.php
@@ -3,6 +3,6 @@
           <i class="faded icon-<?php echo $event->getIcon(); ?>"></i>
         </span>
         <span class="faded description">
-            <?php echo $event->getDescription(); ?>
+            <?php echo $event->getDescription(ThreadEvent::MODE_STAFF); ?>
         </span>
 </div>
-- 
GitLab