Skip to content

Commit

Permalink
Remove hashids (pelican-dev#282) and close pelican-dev#269
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 authored May 29, 2024
1 parent e980877 commit b6e46f7
Show file tree
Hide file tree
Showing 20 changed files with 11 additions and 250 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ CACHE_STORE=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file

HASHIDS_SALT=
HASHIDS_LENGTH=8

MAIL_MAILER=log
MAIL_HOST=smtp.example.com
MAIL_PORT=25
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
MAIL_MAILER: array
SESSION_DRIVER: array
QUEUE_CONNECTION: sync
HASHIDS_SALT: alittlebitofsalt1234
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_DATABASE: testing
Expand Down Expand Up @@ -97,7 +96,6 @@ jobs:
MAIL_MAILER: array
SESSION_DRIVER: array
QUEUE_CONNECTION: sync
HASHIDS_SALT: alittlebitofsalt1234
DB_CONNECTION: sqlite
DB_DATABASE: testing.sqlite
steps:
Expand Down
5 changes: 0 additions & 5 deletions app/Console/Commands/Environment/AppSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class AppSettingsCommand extends Command
protected $description = 'Configure basic environment settings for the Panel.';

protected $signature = 'p:environment:setup
{--new-salt : Whether or not to generate a new salt for Hashids.}
{--url= : The URL that this Panel is running on.}
{--cache= : The cache driver backend to use.}
{--session= : The session driver backend to use.}
Expand Down Expand Up @@ -61,10 +60,6 @@ public function handle(): int
{
$this->variables['APP_TIMEZONE'] = 'UTC';

if (empty(config('hashids.salt')) || $this->option('new-salt')) {
$this->variables['HASHIDS_SALT'] = str_random(20);
}

$this->output->comment(__('commands.appsettings.comment.url'));
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(
'Application URL',
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function processSchedule(Schedule $schedule)

$this->line(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
'hash' => $schedule->hashid,
'id' => $schedule->id,
]));
} catch (\Throwable|\Exception $exception) {
logger()->error($exception, ['schedule_id' => $schedule->id]);
Expand Down
15 changes: 0 additions & 15 deletions app/Contracts/Extensions/HashidsInterface.php

This file was deleted.

22 changes: 0 additions & 22 deletions app/Extensions/Hashids.php

This file was deleted.

9 changes: 0 additions & 9 deletions app/Models/Allocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* @property bool $has_alias
* @property \App\Models\Server|null $server
* @property \App\Models\Node $node
* @property string $hashid
*
* @method static \Database\Factories\AllocationFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|Allocation newModelQuery()
Expand Down Expand Up @@ -88,14 +87,6 @@ public function getRouteKeyName(): string
return $this->getKeyName();
}

/**
* Return a hashid encoded string to represent the ID of the allocation.
*/
public function getHashidAttribute(): string
{
return app()->make('hashids')->encode($this->id);
}

/**
* Accessor to automatically provide the IP alias if defined.
*/
Expand Down
22 changes: 0 additions & 22 deletions app/Models/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Models;

use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Contracts\Extensions\HashidsInterface;
use Illuminate\Support\Facades\DB;

/**
Expand Down Expand Up @@ -72,26 +70,6 @@ public function getRouteKeyName(): string
return $this->getKeyName();
}

/**
* Resolves the database using the ID by checking if the value provided is a HashID
* string value, or just the ID to the database itself.
*
* @param mixed $value
* @param string|null $field
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function resolveRouteBinding($value, $field = null): ?\Illuminate\Database\Eloquent\Model
{
if (is_scalar($value) && ($field ?? $this->getRouteKeyName()) === 'id') {
$value = ctype_digit((string) $value)
? $value
: Container::getInstance()->make(HashidsInterface::class)->decodeFirst($value);
}

return $this->where($field ?? $this->getRouteKeyName(), $value)->firstOrFail();
}

/**
* Gets the host database server associated with a database.
*/
Expand Down
11 changes: 0 additions & 11 deletions app/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Cron\CronExpression;
use Carbon\CarbonImmutable;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Contracts\Extensions\HashidsInterface;

/**
* @property int $id
Expand All @@ -25,7 +23,6 @@
* @property \Carbon\Carbon|null $next_run_at
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $hashid
* @property \App\Models\Server $server
* @property \App\Models\Task[]|\Illuminate\Support\Collection $tasks
*/
Expand Down Expand Up @@ -124,14 +121,6 @@ public function getNextRunDate(): CarbonImmutable
);
}

/**
* Return a hashid encoded string to represent the ID of the schedule.
*/
public function getHashidAttribute(): string
{
return Container::getInstance()->make(HashidsInterface::class)->encode($this->id);
}

/**
* Return tasks belonging to a schedule.
*/
Expand Down
8 changes: 0 additions & 8 deletions app/Models/Subuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ protected function casts(): array
];
}

/**
* Return a hashid encoded string to represent the ID of the subuser.
*/
public function getHashidAttribute(): string
{
return app()->make('hashids')->encode($this->id);
}

/**
* Gets the server associated with a subuser.
*/
Expand Down
11 changes: 0 additions & 11 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace App\Models;

use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Contracts\Extensions\HashidsInterface;

/**
* @property int $id
Expand All @@ -18,7 +16,6 @@
* @property bool $continue_on_failure
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $hashid
* @property \App\Models\Schedule $schedule
* @property \App\Models\Server $server
*/
Expand Down Expand Up @@ -96,14 +93,6 @@ public function getRouteKeyName(): string
return $this->getKeyName();
}

/**
* Return a hashid encoded string to represent the ID of the task.
*/
public function getHashidAttribute(): string
{
return Container::getInstance()->make(HashidsInterface::class)->encode($this->id);
}

/**
* Return the schedule that a task belongs to.
*/
Expand Down
26 changes: 0 additions & 26 deletions app/Providers/HashidsServiceProvider.php

This file was deleted.

6 changes: 0 additions & 6 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Providers;

use Illuminate\Http\Request;
use App\Models\Database;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
use Illuminate\Support\Facades\Route;
use Illuminate\Cache\RateLimiting\Limit;
Expand All @@ -29,11 +28,6 @@ public function boot(): void
return preg_match(self::FILE_PATH_REGEX, $request->getPathInfo()) === 1;
});

// This is needed to make use of the "resolveRouteBinding" functionality in the
// model. Without it you'll never trigger that logic flow thus resulting in a 404
// error because we request databases with a HashID, and not with a normal ID.
Route::model('database', Database::class);

$this->routes(function () {
Route::middleware('web')->group(function () {
Route::middleware(['auth.session', RequireTwoFactorAuthentication::class])
Expand Down
13 changes: 1 addition & 12 deletions app/Transformers/Api/Client/DatabaseTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@
use League\Fractal\Resource\Item;
use App\Models\Permission;
use League\Fractal\Resource\NullResource;
use App\Contracts\Extensions\HashidsInterface;

class DatabaseTransformer extends BaseClientTransformer
{
protected array $availableIncludes = ['password'];

private HashidsInterface $hashids;

/**
* Handle dependency injection.
*/
public function handle(HashidsInterface $hashids)
{
$this->hashids = $hashids;
}

public function getResourceName(): string
{
return Database::RESOURCE_NAME;
Expand All @@ -32,7 +21,7 @@ public function transform(Database $model): array
$model->loadMissing('host');

return [
'id' => $this->hashids->encode($model->id),
'id' => $model->id,
'host' => [
'address' => $model->getRelation('host')->host,
'port' => $model->getRelation('host')->port,
Expand Down
1 change: 0 additions & 1 deletion bootstrap/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
App\Providers\BackupsServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\HashidsServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ViewComposerServiceProvider::class,
];
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"doctrine/dbal": "~3.6.0",
"filament/filament": "^3.2",
"guzzlehttp/guzzle": "^7.8.1",
"hashids/hashids": "~5.0.0",
"laracasts/utilities": "~3.2.2",
"laravel/framework": "^11.7",
"laravel/helpers": "^1.7",
Expand Down
Loading

0 comments on commit b6e46f7

Please sign in to comment.