-
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 #47 from ECFMP/dashboard-owner
fix(Dashboard): replace user with fir as owner
- Loading branch information
Showing
15 changed files
with
273 additions
and
27 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
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
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
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
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
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
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
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
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
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,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; | ||
} | ||
} |
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
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
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
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
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,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']); | ||
}); |