Skip to content

Commit

Permalink
Merge pull request #47 from ECFMP/dashboard-owner
Browse files Browse the repository at this point in the history
fix(Dashboard): replace user with fir as owner
  • Loading branch information
AndyTWF authored May 20, 2022
2 parents fa50834 + 9fff753 commit 9bd15ee
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/Policies/AirportGroupPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ public function forceDelete(User $user, AirportGroup $airportGroup)
RoleKey::NMT,
]);
}

public function deleteAny()
{
return false;
}

public function detachAny()
{
return false;
}
}
10 changes: 10 additions & 0 deletions app/Policies/AirportPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ public function forceDelete(User $user, Airport $airport)
RoleKey::NMT,
]);
}

public function deleteAny()
{
return false;
}

public function detachAny()
{
return false;
}
}
126 changes: 126 additions & 0 deletions app/Policies/DiscordTagPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace App\Policies;

use App\Models\User;
use App\Enums\RoleKey;
use App\Models\DiscordTag;
use Illuminate\Auth\Access\HandlesAuthorization;

class DiscordTagPolicy
{
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\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;
}
}
10 changes: 10 additions & 0 deletions app/Policies/EventPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ public function forceDelete(User $user, Event $event)
RoleKey::FLOW_MANAGER,
]);
}

public function deleteAny()
{
return false;
}

public function detachAny()
{
return false;
}
}
10 changes: 10 additions & 0 deletions app/Policies/FlightInformationRegionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ public function forceDelete(User $user, FlightInformationRegion $flightInformati
RoleKey::NMT,
]);
}

public function deleteAny()
{
return false;
}

public function detachAny()
{
return false;
}
}
10 changes: 10 additions & 0 deletions app/Policies/FlowMeasurePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ public function forceDelete(User $user, FlowMeasure $flowMeasure)
RoleKey::NMT,
]);
}

public function deleteAny()
{
return false;
}

public function detachAny()
{
return false;
}
}
10 changes: 10 additions & 0 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ public function forceDelete(User $user, User $model)
{
return false;
}

public function deleteAny()
{
return false;
}

public function detachAny()
{
return false;
}
}
85 changes: 85 additions & 0 deletions tests/Feature/Filament/UserResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

use App\Filament\Resources\UserResource;
use App\Models\User;
use Tests\FrontendTestCase;

use function Pest\Livewire\livewire;

it('can render index page', function () {
/** @var FrontendTestCase $this */
$this->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']);
});

0 comments on commit 9bd15ee

Please sign in to comment.