Skip to content

Commit

Permalink
Delete evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Nov 8, 2024
1 parent 4fb378c commit e264bc6
Show file tree
Hide file tree
Showing 194 changed files with 1,874 additions and 1,809 deletions.
16 changes: 16 additions & 0 deletions app/Http/Controllers/BanWardenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function show(PlayerPunishment $playerPunishment, Request $request)
'canViewEvidence' => $canViewEvidence,
'canCreateEvidence' => Gate::allows('createEvidence', PlayerPunishment::class)
&& $playerPunishment->evidences->count() < config('minetrax.banwarden.evidence_max_count'),
'canDeleteEvidence' => Gate::allows('deleteEvidence', PlayerPunishment::class),
],
];

Expand Down Expand Up @@ -301,4 +302,19 @@ public function createEvidence(PlayerPunishment $playerPunishment, Request $requ
return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Upload Successful'), 'body' => __('Evidence uploaded successfully')]]);
}

public function deleteEvidence(PlayerPunishment $playerPunishment, $evidence)
{
$this->authorize('deleteEvidence', PlayerPunishment::class);

$media = $playerPunishment->getMedia('punishment-evidence')->find($evidence);
if (!$media) {
abort(404);
}

$media->delete();

return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Delete Successful'), 'body' => __('Evidence deleted successfully')]]);
}
}
9 changes: 9 additions & 0 deletions app/Policies/PlayerPunishmentPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,13 @@ public function createEvidence(User $user): bool

return false;
}

public function deleteEvidence(User $user): bool
{
if ($user->can('delete banwarden_punishments_evidence')) {
return true;
}

return false;
}
}
19 changes: 16 additions & 3 deletions app/Utils/MinecraftQuery/MinecraftWebQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Utils\MinecraftQuery;

use App\Enums\PlayerPunishmentType;
use App\Settings\PluginSettings;
use App\Utils\Helpers\CryptoUtils;
use Illuminate\Encryption\Encrypter;
Expand All @@ -13,6 +14,18 @@ public function __construct(public $HOST, public $PORT)
{
}

public function banwardenPardon(PlayerPunishmentType $type, string $victim, string $reason = null)
{
$payload = [
'type' => $type->value,
'victim' => $victim,
'reason' => $reason,
];
$status = $this->sendQuery('banwarden-pardon', $payload);

return $status;
}

/**
* Changes the player's skin.
*
Expand Down Expand Up @@ -70,7 +83,7 @@ public function sendBroadcast($message)
public function runCommand($command, $params = null)
{
$payload = [
'command' => $params ? $command.' '.$params : $command,
'command' => $params ? $command . ' ' . $params : $command,
];
$status = $this->sendQuery('command', $payload);

Expand All @@ -93,7 +106,7 @@ public function getPing()

public function checkPlayerOnline($playerUuid): bool
{
if (! Str::isUuid($playerUuid)) {
if (!Str::isUuid($playerUuid)) {
throw new \Exception(__('Provided UUID is not valid.'));
}

Expand All @@ -111,7 +124,7 @@ public function sendQuery($type, array $data = [])

$factory = new \Socket\Raw\Factory();
$socket = $factory->createClient("tcp://{$this->HOST}:{$this->PORT}", 10);
$text = $encrypted."\n";
$text = $encrypted . "\n";
$socket->write($text);
// Timeout after 10 seconds for webquery in case of no response
socket_set_option($socket->getResource(), SOL_SOCKET, SO_RCVTIMEO, ['sec' => 10, 'usec' => 0]);
Expand Down
6 changes: 3 additions & 3 deletions database/seeders/PermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public function run()

Permission::findOrCreate('read banwarden_punishments'); // Only come into effect if BANWARDEN_SHOW_PUBLIC is set to false.
Permission::findOrCreate('read banwarden_punishments_critical');
Permission::findOrCreate('create banwarden_punishments');
Permission::findOrCreate('update banwarden_punishments');
Permission::findOrCreate('delete banwarden_punishments');
Permission::findOrCreate('create banwarden_punishments'); // punish
Permission::findOrCreate('delete banwarden_punishments'); // pardon
Permission::findOrCreate('read banwarden_punishments_evidence');
Permission::findOrCreate('create banwarden_punishments_evidence');
Permission::findOrCreate('delete banwarden_punishments_evidence');
}
}

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

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

Large diffs are not rendered by default.

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

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

Loading

0 comments on commit e264bc6

Please sign in to comment.