-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4dd6dad
Showing
16 changed files
with
3,711 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- v*.*.* | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
run: composer install | ||
|
||
- name: Compile package | ||
run: vendor/bin/box compile | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: dist/attachment-retention.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/dist | ||
/vendor-bin/*/vendor | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) VATSIM Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Attachment Retention for osTicket | ||
|
||
## Installation | ||
|
||
Download `attachment-retention.phar` from the | ||
[latest release](https://github.com/vatsimnetwork/osticket-attachment-retention/releases/latest) | ||
and place it in the `include/plugins` folder in your osTicket installation. | ||
|
||
Sign into your osTicket staff control panel, enable the plugin, and create a | ||
plugin instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
require __DIR__.'/vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"main": false, | ||
"output": "dist/attachment-retention.phar", | ||
"chmod": "0644", | ||
"check-requirements": false, | ||
"force-autodiscovery": true, | ||
"files": [ | ||
"bootstrap.php", | ||
"plugin.php" | ||
], | ||
"directories": [ | ||
"templates" | ||
], | ||
"shebang": false, | ||
"banner": [ | ||
"Attachment Retention for osTicket", | ||
"", | ||
"Copyright (c) VATSIM Inc.", | ||
"", | ||
"Permission is hereby granted, free of charge, to any person obtaining a copy", | ||
"of this software and associated documentation files (the \"Software\"), to deal", | ||
"in the Software without restriction, including without limitation the rights", | ||
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell", | ||
"copies of the Software, and to permit persons to whom the Software is", | ||
"furnished to do so, subject to the following conditions:", | ||
"", | ||
"The above copyright notice and this permission notice shall be included in all", | ||
"copies or substantial portions of the Software.", | ||
"", | ||
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", | ||
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", | ||
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", | ||
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", | ||
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", | ||
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", | ||
"SOFTWARE." | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "vatsim/osticket-attachment-retention", | ||
"description": "osTicket plugin for customizing attachment retention policies.", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "William McKinnerney", | ||
"email": "[email protected]", | ||
"homepage": "https://williammck.net" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": "^8.0" | ||
}, | ||
"require-dev": { | ||
"bamarni/composer-bin-plugin": "^1.8" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Vatsim\\Osticket\\AttachmentRetention\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"bamarni-bin": { | ||
"bin-links": true, | ||
"forward-command": true | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"bamarni/composer-bin-plugin": true | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
use Vatsim\Osticket\AttachmentRetention\Plugin; | ||
|
||
return [ | ||
'id' => 'attachment:retention', | ||
'version' => '1.0', | ||
'ost_version' => '1.16', | ||
'name' => 'Attachment Retention', | ||
'author' => 'VATSIM Tech Team <[email protected]>', | ||
'description' => 'Customize retention policies for thread attachments', | ||
'plugin' => 'bootstrap.php:'.Plugin::class, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Vatsim\Osticket\AttachmentRetention; | ||
|
||
use PluginConfig; | ||
|
||
class Config extends PluginConfig | ||
{ | ||
public function getOptions(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Vatsim\Osticket\AttachmentRetention; | ||
|
||
use Http; | ||
use Staff; | ||
use Ticket; | ||
|
||
class DeleteAllController | ||
{ | ||
public function __invoke($ticketId): void | ||
{ | ||
$ticket = Ticket::lookup($ticketId); | ||
if (! $ticket) { | ||
Http::response(404, 'Not Found'); | ||
} | ||
|
||
/** @var Staff $thisstaff */ | ||
global $thisstaff; | ||
if (! $thisstaff || ! $ticket->checkStaffPerm($thisstaff, Ticket::PERM_DELETE)) { | ||
Http::response(403, 'Forbidden'); | ||
} | ||
|
||
match ($_SERVER['REQUEST_METHOD']) { | ||
'GET' => $this->show($ticket), | ||
'POST' => $this->destroy($ticket), | ||
default => Http::response(405, 'Method Not Allowed'), | ||
}; | ||
} | ||
|
||
public function show(Ticket $ticket): void | ||
{ | ||
include __DIR__ . '/../templates/delete-all.php'; | ||
} | ||
|
||
public function destroy(Ticket $ticket): void | ||
{ | ||
Utils::deleteAttachments($ticket); | ||
$_SESSION['::sysmsgs']['msg'] = __('Ticket attachments deleted successfully'); | ||
|
||
Http::response(201, $ticket->getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Vatsim\Osticket\AttachmentRetention; | ||
|
||
use Dispatcher; | ||
use Plugin as BasePlugin; | ||
use Signal; | ||
use Ticket; | ||
|
||
class Plugin extends BasePlugin | ||
{ | ||
public $config_class = Config::class; | ||
|
||
public function bootstrap(): void | ||
{ | ||
$this->addActionLink(); | ||
$this->registerRoutes(); | ||
} | ||
|
||
private function addActionLink(): void | ||
{ | ||
Signal::connect('ticket.view.more', function (Ticket $ticket, &$data) { | ||
$ticketId = $ticket->getId(); | ||
$text = __('Delete Attachments'); | ||
echo <<<HTML | ||
<li class="danger"> | ||
<a class="ticket-action" href="#attachment-retention/ticket/$ticketId/delete-all" data-redirect="tickets.php?id=$ticketId"> | ||
<i class="icon-folder-close"></i> | ||
$text | ||
</a> | ||
</li> | ||
HTML; | ||
}); | ||
} | ||
|
||
private function registerRoutes(): void | ||
{ | ||
Signal::connect('ajax.scp', function (Dispatcher $dispatcher, &$data) { | ||
$dispatcher->append( | ||
url('^/attachment-retention/ticket/(?P<id>\d+)/delete-all$', new DeleteAllController) | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Vatsim\Osticket\AttachmentRetention; | ||
|
||
use Staff; | ||
use Ticket; | ||
use TicketThread; | ||
|
||
final class Utils | ||
{ | ||
public static function deleteAttachments(Ticket $ticket): bool | ||
{ | ||
/** @var Staff|null $thisstaff */ | ||
global $thisstaff; | ||
|
||
/** @var TicketThread $thread */ | ||
$thread = $ticket->getThread(); | ||
$deleted = $thread->deleteAttachments(); | ||
|
||
if ($deleted === 0) { | ||
return false; | ||
} | ||
|
||
$name = $thisstaff->getName() ?? __('system task'); | ||
$ticket->logActivity( | ||
__('Ticket Attachments Deleted'), | ||
sprintf(__('Ticket attachments deleted by %s'), $name), | ||
); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.