wip
This commit is contained in:
parent
61f7bbeca7
commit
a45045d9bd
@ -5,10 +5,14 @@ declare(strict_types=1);
|
||||
namespace Toby\Architecture\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Toby\Domain\Policies\HolidayPolicy;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected $policies = [];
|
||||
protected $policies = [
|
||||
Holiday::class => HolidayPolicy::class
|
||||
];
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
|
16
app/Domain/Policies/HolidayPolicy.php
Normal file
16
app/Domain/Policies/HolidayPolicy.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Policies;
|
||||
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class HolidayPolicy
|
||||
{
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->role == Role::AdministrativeApprover || $user->role == Role::Administrator;
|
||||
}
|
||||
}
|
@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Policies\HolidayPolicy;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Infrastructure\Http\Requests\HolidayRequest;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayFormDataResource;
|
||||
@ -13,14 +15,18 @@ use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
|
||||
class HolidayController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$holidays = Holiday::query()
|
||||
->orderBy("date")
|
||||
->get();
|
||||
|
||||
$user = $request->user();
|
||||
return inertia("Holidays/Index", [
|
||||
"holidays" => HolidayResource::collection($holidays),
|
||||
"can" => [
|
||||
"create" => $user->can("create", Holiday::class)
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
Lista dni wolnych od pracy w danym roku
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<div v-if="can.create">
|
||||
<InertiaLink
|
||||
href="holidays/create"
|
||||
class="inline-flex items-center px-4 py-3 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
|
||||
@ -159,6 +159,10 @@ export default {
|
||||
type: Object,
|
||||
default: () => null,
|
||||
},
|
||||
can: {
|
||||
type: Object,
|
||||
default: () => null,
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
return {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user