Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
williammck committed Aug 15, 2024
0 parents commit 4dd6dad
Show file tree
Hide file tree
Showing 16 changed files with 3,711 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/release.yaml
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist
/vendor-bin/*/vendor
/vendor
21 changes: 21 additions & 0 deletions LICENSE
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.
10 changes: 10 additions & 0 deletions README.md
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.
3 changes: 3 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require __DIR__.'/vendor/autoload.php';
38 changes: 38 additions & 0 deletions box.json.dist
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."
]
}
35 changes: 35 additions & 0 deletions composer.json
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
}
}
}
78 changes: 78 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions plugin.php
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,
];
13 changes: 13 additions & 0 deletions src/Config.php
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 [];
}
}
43 changes: 43 additions & 0 deletions src/DeleteAllController.php
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());
}
}
44 changes: 44 additions & 0 deletions src/Plugin.php
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)
);
});
}
}
32 changes: 32 additions & 0 deletions src/Utils.php
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;
}
}
Loading

0 comments on commit 4dd6dad

Please sign in to comment.