From 99e9f3053d334e881a1ef2f538e5c10146211028 Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Tue, 3 Jan 2017 11:07:40 -0600 Subject: [PATCH] thread: Add action to remove responses and notes This will allow an administrator with access to a thread to remove notes and optionally responses. This might be useful if the items were accidently double posted or the information was posted to an incorrect thread. --- thread-action-delete/plugin.php | 13 ++ thread-action-delete/tea_remove.php | 116 ++++++++++++++++++ .../templates/thread-entry-delete.tmpl.php | 37 ++++++ 3 files changed, 166 insertions(+) create mode 100644 thread-action-delete/plugin.php create mode 100644 thread-action-delete/tea_remove.php create mode 100644 thread-action-delete/templates/thread-entry-delete.tmpl.php diff --git a/thread-action-delete/plugin.php b/thread-action-delete/plugin.php new file mode 100644 index 0000000..82488ee --- /dev/null +++ b/thread-action-delete/plugin.php @@ -0,0 +1,13 @@ + 'thread-entry:delete', # notrans + 'version' => '0.1', + 'name' => /* trans */ 'Delete plugin for thread entries', + 'author' => 'Jared Hancock', + 'description' => /* trans */ 'Allows administrators to remove thread entry items', + 'url' => 'http://www.osticket.com/plugins/thread-entry/remove', + 'plugin' => 'tea_remove.php:TEA_RemovePlugin' +); + +?> diff --git a/thread-action-delete/tea_remove.php b/thread-action-delete/tea_remove.php new file mode 100644 index 0000000..b4e1bbe --- /dev/null +++ b/thread-action-delete/tea_remove.php @@ -0,0 +1,116 @@ +getInfo(); + } + + function getConfig() { + return static::$plugin_config; + } + + function isVisible() { + $config = $this->getConfig(); + + // Removal of messages is not allowed + if ($this->entry->type == 'M') + return false; + + // Configuration indicates if removal of responses is allowed + if ($this->entry->type == 'R' && !@$config['responses']) + return false; + + // Can't remove system posts + return ($this->entry->staff_id || $this->entry->user_id) + && $this->isEnabled(); + } + + function isEnabled() { + global $thisstaff; + + // You have to be an admin *and* have access to the ticket/task + $T = $this->entry->getThread()->getObject(); + return $thisstaff->isAdmin() + && $T->checkStaffPerm($thisstaff); + } + + function getJsStub() { + return sprintf(<<getAjaxUrl()); + } + + function trigger() { + switch ($_SERVER['REQUEST_METHOD']) { + case 'GET': + return $this->trigger__get(); + case 'POST': + return $this->trigger__post(); + } + } + + protected function trigger__get() { + global $cfg, $thisstaff; + + $poster = $this->entry->getStaff(); + $action = str_replace('ajax.php/','#', $this->getAjaxUrl()); + + include 'templates/thread-entry-delete.tmpl.php'; + } + + protected function trigger__post() { + $config = $this->getConfig(); + + if ($this->entry->type == 'M') { + Messages::error(__('Deletion of messages is not supported')); + } + if ($this->entry->type == 'R' && !@$config['responses']) { + Messages::error(__('Deletion of responses is disabled')); + } + elseif ($this->entry->delete()) { + Http::response('201', JsonDataEncoder::encode(array( + 'thread_id' => $this->entry->id, + ))); + } + return $this->trigger__get(); + } +} + +class TEA_RemovePlugin +extends Plugin { + var $config_class = 'TEA_RemovePluginConfig'; + + function bootstrap() { + TEA_RemoveThreadEntry::setConfig($this->getConfig()); + ThreadEntry::registerAction(/* trans */ 'Manage', 'TEA_RemoveThreadEntry'); + } +} + +class TEA_RemovePluginConfig +extends PluginConfig { + function getOptions() { + return array( + 'responses' => new BooleanField(array( + 'label' => 'Allow removal of Responses', + 'default' => false, + 'hint' => 'Not recommended. Removing responses which were emailed to your users could cause significant confusion', + 'configuration' => array( + 'desc' => 'Allow removal of Responses', + ), + )), + ); + } +} diff --git a/thread-action-delete/templates/thread-entry-delete.tmpl.php b/thread-action-delete/templates/thread-entry-delete.tmpl.php new file mode 100644 index 0000000..bb1d61a --- /dev/null +++ b/thread-action-delete/templates/thread-entry-delete.tmpl.php @@ -0,0 +1,37 @@ +

+ +
+
+ + +
+ + +
+

+ +

+ +

+
+ +
+
+

+ + + + + + +

+
+ +