diff --git a/app/Filament/Resources/AirportGroupResource/RelationManagers/AirportsRelationManager.php b/app/Filament/Resources/AirportGroupResource/RelationManagers/AirportsRelationManager.php index f5d824c8..8aacc951 100644 --- a/app/Filament/Resources/AirportGroupResource/RelationManagers/AirportsRelationManager.php +++ b/app/Filament/Resources/AirportGroupResource/RelationManagers/AirportsRelationManager.php @@ -22,11 +22,6 @@ protected function canDelete(Model $record): bool return false; } - protected function canDeleteAny(): bool - { - return false; - } - public static function form(Form $form): Form { return $form diff --git a/app/Filament/Resources/AirportResource/RelationManagers/GroupsRelationManager.php b/app/Filament/Resources/AirportResource/RelationManagers/GroupsRelationManager.php index f1dac36d..6a158303 100644 --- a/app/Filament/Resources/AirportResource/RelationManagers/GroupsRelationManager.php +++ b/app/Filament/Resources/AirportResource/RelationManagers/GroupsRelationManager.php @@ -20,11 +20,6 @@ protected function canDelete(Model $record): bool return false; } - protected function canDeleteAny(): bool - { - return false; - } - public static function form(Form $form): Form { return $form diff --git a/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/EventsRelationManager.php b/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/EventsRelationManager.php index 85bf7be7..d53b8119 100644 --- a/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/EventsRelationManager.php +++ b/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/EventsRelationManager.php @@ -19,11 +19,6 @@ class EventsRelationManager extends HasManyRelationManager protected static ?string $recordTitleAttribute = 'name'; - private static function setFirOptions(Collection $firs) - { - return $firs->mapWithKeys(fn (FlightInformationRegion $fir) => [$fir->id => $fir->identifierName]); - } - public static function form(Form $form): Form { return $form diff --git a/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/UsersRelationManager.php b/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/UsersRelationManager.php index 0b509753..8118abca 100644 --- a/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/UsersRelationManager.php +++ b/app/Filament/Resources/FlightInformationRegionResource/RelationManagers/UsersRelationManager.php @@ -27,11 +27,6 @@ protected function canDelete(Model $record): bool return false; } - protected function canDeleteAny(): bool - { - return false; - } - protected function canEdit(Model $record): bool { // TODO: Might add role stuff here diff --git a/app/Filament/Resources/FlowMeasureResource/Widgets/ActiveFlowMeasures.php b/app/Filament/Resources/FlowMeasureResource/Widgets/ActiveFlowMeasures.php index a1a09424..3e9ff039 100644 --- a/app/Filament/Resources/FlowMeasureResource/Widgets/ActiveFlowMeasures.php +++ b/app/Filament/Resources/FlowMeasureResource/Widgets/ActiveFlowMeasures.php @@ -24,7 +24,7 @@ protected function getTableColumns(): array { return [ Tables\Columns\TextColumn::make('identifier'), - Tables\Columns\TextColumn::make('user.name') + Tables\Columns\TextColumn::make('flightInformationRegion.identifierName') ->label(__('Owner')), Tables\Columns\BadgeColumn::make('type') ->alignCenter() diff --git a/app/Filament/Resources/FlowMeasureResource/Widgets/UpcomingFlowMeasures.php b/app/Filament/Resources/FlowMeasureResource/Widgets/UpcomingFlowMeasures.php index db2e5506..0aca85ac 100644 --- a/app/Filament/Resources/FlowMeasureResource/Widgets/UpcomingFlowMeasures.php +++ b/app/Filament/Resources/FlowMeasureResource/Widgets/UpcomingFlowMeasures.php @@ -24,7 +24,7 @@ protected function getTableColumns(): array { return [ Tables\Columns\TextColumn::make('identifier'), - Tables\Columns\TextColumn::make('user.name') + Tables\Columns\TextColumn::make('flightInformationRegion.identifierName') ->label(__('Owner')), Tables\Columns\BadgeColumn::make('type') ->alignCenter() diff --git a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php index a8a8b9de..235a3ca7 100644 --- a/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php +++ b/app/Filament/Resources/UserResource/RelationManagers/FlightInformationRegionsRelationManager.php @@ -20,11 +20,6 @@ protected function canDelete(Model $record): bool return false; } - protected function canDeleteAny(): bool - { - return false; - } - public static function form(Form $form): Form { return $form diff --git a/app/Policies/AirportGroupPolicy.php b/app/Policies/AirportGroupPolicy.php index 43774b86..85d6a39a 100644 --- a/app/Policies/AirportGroupPolicy.php +++ b/app/Policies/AirportGroupPolicy.php @@ -113,4 +113,14 @@ public function forceDelete(User $user, AirportGroup $airportGroup) RoleKey::NMT, ]); } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } } diff --git a/app/Policies/AirportPolicy.php b/app/Policies/AirportPolicy.php index 603d138f..a128fee9 100644 --- a/app/Policies/AirportPolicy.php +++ b/app/Policies/AirportPolicy.php @@ -113,4 +113,14 @@ public function forceDelete(User $user, Airport $airport) RoleKey::NMT, ]); } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } } diff --git a/app/Policies/DiscordTagPolicy.php b/app/Policies/DiscordTagPolicy.php new file mode 100644 index 00000000..fb8e88b2 --- /dev/null +++ b/app/Policies/DiscordTagPolicy.php @@ -0,0 +1,126 @@ +role->key, [ + RoleKey::SYSTEM, + RoleKey::NMT, + ]); + } + + /** + * Determine whether the user can view the model. + * + * @param \App\Models\User $user + * @param \App\Models\DiscordTag $discordTag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function view(User $user, DiscordTag $discordTag) + { + 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\DiscordTag $discordTag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, DiscordTag $discordTag) + { + 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\DiscordTag $discordTag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, DiscordTag $discordTag) + { + 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\DiscordTag $discordTag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, DiscordTag $discordTag) + { + 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\DiscordTag $discordTag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, DiscordTag $discordTag) + { + return in_array($user->role->key, [ + RoleKey::SYSTEM, + RoleKey::NMT, + ]); + } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } +} diff --git a/app/Policies/EventPolicy.php b/app/Policies/EventPolicy.php index cb775eb2..15c28e11 100644 --- a/app/Policies/EventPolicy.php +++ b/app/Policies/EventPolicy.php @@ -118,4 +118,14 @@ public function forceDelete(User $user, Event $event) RoleKey::FLOW_MANAGER, ]); } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } } diff --git a/app/Policies/FlightInformationRegionPolicy.php b/app/Policies/FlightInformationRegionPolicy.php index 26192f8e..67e4a086 100644 --- a/app/Policies/FlightInformationRegionPolicy.php +++ b/app/Policies/FlightInformationRegionPolicy.php @@ -113,4 +113,14 @@ public function forceDelete(User $user, FlightInformationRegion $flightInformati RoleKey::NMT, ]); } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } } diff --git a/app/Policies/FlowMeasurePolicy.php b/app/Policies/FlowMeasurePolicy.php index 11a3abfc..1c77f017 100644 --- a/app/Policies/FlowMeasurePolicy.php +++ b/app/Policies/FlowMeasurePolicy.php @@ -122,4 +122,14 @@ public function forceDelete(User $user, FlowMeasure $flowMeasure) RoleKey::NMT, ]); } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } } diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index 7f46fdd1..7e52ce1c 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -104,4 +104,14 @@ public function forceDelete(User $user, User $model) { return false; } + + public function deleteAny() + { + return false; + } + + public function detachAny() + { + return false; + } } diff --git a/tests/Feature/Filament/UserResourceTest.php b/tests/Feature/Filament/UserResourceTest.php new file mode 100644 index 00000000..0fcdd872 --- /dev/null +++ b/tests/Feature/Filament/UserResourceTest.php @@ -0,0 +1,85 @@ +get(UserResource::getUrl())->assertForbidden(); + + $this->actingAs(User::factory()->flowManager()->create()); + $this->get(UserResource::getUrl())->assertForbidden(); + + $this->actingAs(User::factory()->networkManager()->create()); + $this->get(UserResource::getUrl())->assertSuccessful(); + + $this->actingAs(User::factory()->system()->create()); + $this->get(UserResource::getUrl())->assertSuccessful(); +}); + +it('can render edit page', function () { + /** @var FrontendTestCase $this */ + $this->get(UserResource::getUrl('edit', [ + 'record' => User::factory()->create(), + ]))->assertForbidden(); + + $this->actingAs(User::factory()->flowManager()->create()); + $this->get(UserResource::getUrl('edit', [ + 'record' => User::factory()->create(), + ]))->assertForbidden(); + + $this->actingAs(User::factory()->networkManager()->create()); + $this->get(UserResource::getUrl('edit', [ + 'record' => User::factory()->create(), + ]))->assertSuccessful(); + + $this->actingAs(User::factory()->system()->create()); + $this->get(UserResource::getUrl('edit', [ + 'record' => User::factory()->create(), + ]))->assertSuccessful(); +}); + +it('can retrieve data for edit page', function () { + $this->actingAs(User::factory()->system()->create()); + $user = User::factory()->create(); + + livewire(UserResource\Pages\EditUser::class, [ + 'record' => $user->getKey(), + ]) + ->assertSet('data.id', $user->id) + ->assertSet('data.name', $user->name) + ->assertSet('data.role', $user->role->value); +}); + +it('can edit', function () { + /** @var FrontendTestCase $this */ + $this->actingAs(User::factory()->system()->create()); + + $user = User::factory()->create(); + $newData = User::factory()->make(); + + livewire(UserResource\Pages\EditUser::class, [ + 'record' => $user->getKey(), + ]) + ->set('data.role_id', $newData->role_id) + ->call('save'); + + expect($user->refresh()) + ->role_id->toBe($newData->role_id); +}); + +it('can validate edit input', function () { + $this->actingAs(User::factory()->system()->create()); + + $user = User::factory()->create(); + + livewire(UserResource\Pages\EditUser::class, [ + 'record' => $user->getKey(), + ]) + ->set('data.role_id', null) + ->call('save') + ->assertHasErrors(['data.role_id' => 'required']); +});