-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from ECFMP/division-discord-webhooks
Division discord webhooks admin
- Loading branch information
Showing
10 changed files
with
763 additions
and
11 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,77 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\DivisionDiscordWebhookResource\Pages; | ||
use App\Filament\Resources\DivisionDiscordWebhookResource\RelationManagers\FlightinformationregionsRelationManager; | ||
use App\Models\DivisionDiscordWebhook; | ||
use App\Models\FlightInformationRegion; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TagsColumn; | ||
use Filament\Tables\Columns\TextColumn; | ||
|
||
class DivisionDiscordWebhookResource extends Resource | ||
{ | ||
protected static ?string $model = DivisionDiscordWebhook::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-collection'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
TextInput::make('description') | ||
->label(__('Description')) | ||
->required() | ||
->maxLength(255), | ||
TextInput::make('url') | ||
->url() | ||
->required() | ||
->maxLength( | ||
500 | ||
) | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('id') | ||
->label(__('id')), | ||
TextColumn::make('description') | ||
->label(__('description')) | ||
->searchable(), | ||
TextColumn::make('url') | ||
->label(__('URL')), | ||
TagsColumn::make('firs') | ||
->getStateUsing(fn (DivisionDiscordWebhook $record) => $record->flightInformationRegions->map(fn (FlightInformationRegion $fir) => $fir->identifierName)->toArray()) | ||
->label(__('FIRs')), | ||
TextColumn::make('created_at') | ||
->label(__('Created At')), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
FlightinformationregionsRelationManager::class, | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListDivisionDiscordWebhooks::route('/'), | ||
'create' => Pages\CreateDivisionDiscordWebhook::route('/create'), | ||
'edit' => Pages\EditDivisionDiscordWebhook::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/Filament/Resources/DivisionDiscordWebhookResource/Pages/CreateDivisionDiscordWebhook.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,11 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\DivisionDiscordWebhookResource\Pages; | ||
|
||
use App\Filament\Resources\DivisionDiscordWebhookResource; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateDivisionDiscordWebhook extends CreateRecord | ||
{ | ||
protected static string $resource = DivisionDiscordWebhookResource::class; | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/DivisionDiscordWebhookResource/Pages/EditDivisionDiscordWebhook.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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\DivisionDiscordWebhookResource\Pages; | ||
|
||
use App\Filament\Resources\DivisionDiscordWebhookResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditDivisionDiscordWebhook extends EditRecord | ||
{ | ||
protected static string $resource = DivisionDiscordWebhookResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/DivisionDiscordWebhookResource/Pages/ListDivisionDiscordWebhooks.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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\DivisionDiscordWebhookResource\Pages; | ||
|
||
use App\Filament\Resources\DivisionDiscordWebhookResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListDivisionDiscordWebhooks extends ListRecords | ||
{ | ||
protected static string $resource = DivisionDiscordWebhookResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...visionDiscordWebhookResource/RelationManagers/FlightinformationregionsRelationManager.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,47 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\DivisionDiscordWebhookResource\RelationManagers; | ||
|
||
use App\Models\FlightInformationRegion; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
use Filament\Tables\Actions\AttachAction; | ||
use Filament\Tables\Actions\DetachAction; | ||
|
||
class FlightinformationregionsRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'flightInformationRegions'; | ||
|
||
protected static ?string $title = 'Flight Information Regions'; | ||
|
||
protected static ?string $recordTitleAttribute = 'identifier'; | ||
|
||
protected static ?string $inverseRelationship = 'divisionDiscordWebhooks'; | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('fir') | ||
->label(__('FIR')) | ||
->formatStateUsing(fn (FlightInformationRegion $record) => $record->identifierName), | ||
Tables\Columns\TextColumn::make('tag') | ||
->label(__('Mention Tag')), | ||
]) | ||
->headerActions([ | ||
AttachAction::make('attach-fir') | ||
->form(fn (AttachAction $action) => [ | ||
$action->getRecordSelect(), | ||
TextInput::make('tag') | ||
->label(__('Discord Tag')) | ||
->helperText(__('A Discord tag for a person / group / role that should be mentioned in the post.')) | ||
->maxLength(255) | ||
]), | ||
]) | ||
->actions([ | ||
DetachAction::make(), | ||
]); | ||
} | ||
} |
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,156 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\User; | ||
use App\Enums\RoleKey; | ||
use App\Models\DivisionDiscordWebhook; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class DivisionDiscordWebhookPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Determine whether the user can view any models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function viewAny(User $user) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function view(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function create(User $user) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function update(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function delete(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function restore(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can permanently delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function forceDelete(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
public function deleteAny() | ||
{ | ||
return false; | ||
} | ||
|
||
public function detachAny() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function attach(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\DivisionDiscordWebhook $divisionDiscordWebhook | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function detach(User $user, DivisionDiscordWebhook $divisionDiscordWebhook) | ||
{ | ||
return in_array($user->role->key, [ | ||
RoleKey::SYSTEM, | ||
RoleKey::NMT, | ||
]); | ||
} | ||
} |
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
Oops, something went wrong.