Skip to content

Commit

Permalink
Merge branch 'alexjustesen:main' into dashboard-remake
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvg93 authored Nov 14, 2024
2 parents 29f364d + 0bdd141 commit 7ae9014
Show file tree
Hide file tree
Showing 14 changed files with 755 additions and 560 deletions.
281 changes: 202 additions & 79 deletions _ide_helper.php

Large diffs are not rendered by default.

145 changes: 74 additions & 71 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use App\Enums\UserRole;
use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\Pages\CreateUser;
use App\Filament\Resources\UserResource\Pages\EditUser;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
Expand All @@ -14,8 +12,6 @@
use Filament\Tables\Table;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\HtmlString;
use Illuminate\Validation\Rules\Password;

class UserResource extends Resource
{
Expand All @@ -29,77 +25,72 @@ public static function form(Form $form): Form
->schema([
Forms\Components\Grid::make([
'default' => 1,
'md' => 3,
])
])->columnSpan([
'lg' => 2,
])->schema([
Forms\Components\Section::make('Details')
->columns([
'default' => 1,
'lg' => 2,
])
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
->columnSpanFull(),

Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255)
->columnSpanFull(),

Forms\Components\TextInput::make('password')
->confirmed()
->password()
->revealable()
->required(fn (string $context): bool => $context === 'create')
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state)),

Forms\Components\TextInput::make('password_confirmation')
->password()
->revealable(),

// ...
]),
]),

Forms\Components\Grid::make(1)
->columnSpan(1)
->schema([
Forms\Components\Section::make()
Forms\Components\Section::make('Platform')
->schema([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TextInput::make('email')
->required()
->email()
->unique(ignoreRecord: true),
Forms\Components\TextInput::make('password')
Forms\Components\Select::make('role')
->label('Role')
->default(UserRole::User)
->options(UserRole::class)
->required()
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->visible(fn ($livewire) => $livewire instanceof CreateUser)
->rule(Password::default()),
Forms\Components\TextInput::make('new_password')
->password()
->label('New Password')
->nullable()
->rule(Password::default())
->visible(fn ($livewire) => $livewire instanceof EditUser)
->dehydrated(false),
Forms\Components\TextInput::make('new_password_confirmation')
->password()
->label('Confirm New Password')
->rule('required', fn ($get) => (bool) $get('new_password'))
->same('new_password')
->visible(fn ($livewire) => $livewire instanceof EditUser)
->dehydrated(false),
])
->columns(1)
->columnSpan([
'md' => 2,
->disabled(fn (?User $record): bool => Auth::user()->role !== UserRole::Admin),

// ...
]),

Forms\Components\Grid::make([
'default' => 1,
])
Forms\Components\Section::make()
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('role')
->options(UserRole::class)
->default(UserRole::User)
->disabled(fn (): bool => ! Auth::user()->is_admin)
->required(),
])
->columns(1)
->columnSpan([
'md' => 1,
]),

Forms\Components\Section::make()
->schema([
Forms\Components\Placeholder::make('created_at')
->content(fn ($record) => $record?->created_at?->diffForHumans() ?? new HtmlString('—')),
Forms\Components\Placeholder::make('updated_at')
->content(fn ($record) => $record?->updated_at?->diffForHumans() ?? new HtmlString('—')),
])
->columns(1)
->columnSpan([
'md' => 1,
]),
])
->columns(1)
->columnSpan([
'md' => 1,
Forms\Components\Placeholder::make('created_at')
->content(fn (?User $record): string => $record ? $record->created_at->diffForHumans() : '-'),

Forms\Components\Placeholder::make('updated_at')
->content(fn (?User $record): string => $record ? $record->updated_at->diffForHumans() : '-'),

// ...
]),
]),
])
->columns([
'default' => 1,
'lg' => 3,
]);
}

Expand All @@ -108,33 +99,45 @@ public static function table(Table $table): Table
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID'),
->label('ID')
->sortable(),

Tables\Columns\TextColumn::make('name')
->searchable(),

Tables\Columns\TextColumn::make('email')
->searchable(),

Tables\Columns\TextColumn::make('role')
->badge(),

Tables\Columns\TextColumn::make('created_at')
->alignEnd()
->dateTime(config('app.datetime_format'))
->timezone(config('app.display_timezone')),
->timezone(config('app.display_timezone'))
->sortable()
->toggleable(isToggledHiddenByDefault: false),

Tables\Columns\TextColumn::make('updated_at')
->alignEnd()
->dateTime(config('app.datetime_format'))
->timezone(config('app.display_timezone'))
->sortable()
->toggleable(isToggledHiddenByDefault: true),

// ...
])
->filters([
Tables\Filters\SelectFilter::make('role')
->options(UserRole::class),
])
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]),
])
->bulkActions([
// ...
]);
}

Expand Down
10 changes: 0 additions & 10 deletions app/Filament/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Hash;

class EditUser extends EditRecord
{
Expand All @@ -17,13 +16,4 @@ protected function getHeaderActions(): array
Actions\DeleteAction::make(),
];
}

public function beforeSave()
{
if (! array_key_exists('new_password', $this->data) || ! filled($this->data['new_password'])) {
return;
}

$this->record->password = Hash::make($this->data['new_password']);
}
}
23 changes: 19 additions & 4 deletions app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,19 @@ public function handle(): void

/**
* Check for internet connection.
*
* @throws \Exception
*/
protected function checkForInternetConnection(): bool
{
$url = config('speedtest.ping_url');

// TODO: skip checking for internet connection, current validation does not take into account different host formats and ip addresses.
return true;

// Skip checking for internet connection if ping url isn't set (disabled)
if (blank($url)) {
return true;
}

if (! URL::isValidUrl($url)) {
if (! $this->isValidPingUrl($url)) {
$this->result->update([
'data' => [
'type' => 'log',
Expand Down Expand Up @@ -165,4 +164,20 @@ protected function checkForInternetConnection(): bool

return true;
}

/**
* Check if the given URL is a valid ping URL.
*/
public function isValidPingUrl(string $url): bool
{
$hasTLD = static function (string $url): bool {
// this also ensures the string ends with a TLD
return preg_match('/\.[a-z]{2,}$/i', $url);
};

return (filter_var($url, FILTER_VALIDATE_URL) && $hasTLD($url))
// to check for things like `google.com`, we need to add the protocol
|| (filter_var('https://'.$url, FILTER_VALIDATE_URL) && $hasTLD($url))
|| filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 || FILTER_FLAG_IPV6) !== false;
}
}
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
"awcodes/filament-versions": "^2.0.1",
"chrisullyott/php-filesize": "^4.2.1",
"dragonmantank/cron-expression": "^3.4.0",
"filament/filament": "^3.2.117",
"filament/spatie-laravel-settings-plugin": "^3.2.117",
"filament/filament": "^3.2.124",
"filament/spatie-laravel-settings-plugin": "^3.2.124",
"geerlingguy/ping": "^1.2.1",
"guzzlehttp/guzzle": "^7.9.2",
"influxdata/influxdb-client-php": "^3.6",
"laravel-notification-channels/telegram": "^5.0",
"laravel/framework": "^11.27.2",
"laravel/framework": "^11.31",
"laravel/prompts": "^0.2.1",
"laravel/sanctum": "^4.0.3",
"laravel/tinker": "^2.10.0",
"livewire/livewire": "^3.5.4",
"livewire/livewire": "^3.5.12",
"lorisleiva/laravel-actions": "^2.8.4",
"maennchen/zipstream-php": "^2.4",
"spatie/laravel-settings": "^3.4",
"spatie/laravel-webhook-server": "^3.8.1",
"timokoerber/laravel-one-time-operations": "^1.4.2"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.1",
"fakerphp/faker": "^1.23.1",
"barryvdh/laravel-ide-helper": "^3.2.2",
"fakerphp/faker": "^1.24.0",
"laravel/pint": "^1.18.1",
"laravel/sail": "^1.35.0",
"laravel/telescope": "^5.2.2",
"laravel/sail": "^1.38.0",
"laravel/telescope": "^5.2.5",
"mockery/mockery": "^1.6.12",
"nunomaduro/collision": "^8.4.0",
"phpunit/phpunit": "^11.4.1",
"nunomaduro/collision": "^8.5.0",
"phpunit/phpunit": "^11.4.3",
"spatie/laravel-ignition": "^2.8.0",
"tightenco/duster": "^3.0.3"
},
Expand Down
Loading

0 comments on commit 7ae9014

Please sign in to comment.