feat(auth): UserPolicy + LicensePolicy + TenantPolicy + ParentChildPolicy + EnsureActiveLicense placeholder
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>main
parent
a099f2a4dc
commit
58400d3dc3
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EnsureActiveLicense
|
||||
{
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
// Full implementation in Phase 4 (requires License model)
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\User;
|
||||
|
||||
class LicensePolicy
|
||||
{
|
||||
public function viewAny(User $actor): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin') || $actor->hasRole('school-admin');
|
||||
}
|
||||
|
||||
public function view(User $actor, License $license): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->tenant_id === $license->tenant_id;
|
||||
}
|
||||
|
||||
public function create(User $actor): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin');
|
||||
}
|
||||
|
||||
public function update(User $actor, License $license): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class ParentChildPolicy
|
||||
{
|
||||
public function attach(User $actor, User $parent, User $child): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->hasRole('parent') && $actor->id === $parent->id;
|
||||
}
|
||||
|
||||
public function detach(User $actor, User $parent, User $child): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->hasRole('parent') && $actor->id === $parent->id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
|
||||
class TenantPolicy
|
||||
{
|
||||
public function viewAny(User $actor): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin');
|
||||
}
|
||||
|
||||
public function view(User $actor, Tenant $tenant): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->tenant_id === $tenant->id;
|
||||
}
|
||||
|
||||
public function create(User $actor): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin');
|
||||
}
|
||||
|
||||
public function update(User $actor, Tenant $tenant): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserPolicy
|
||||
{
|
||||
public function viewAny(User $actor): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin')
|
||||
|| $actor->hasRole('school-admin')
|
||||
|| $actor->hasRole('teacher');
|
||||
}
|
||||
|
||||
public function view(User $actor, User $target): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->tenant_id === $target->tenant_id;
|
||||
}
|
||||
|
||||
public function create(User $actor): bool
|
||||
{
|
||||
return $actor->hasRole('platform-admin') || $actor->hasRole('school-admin');
|
||||
}
|
||||
|
||||
public function update(User $actor, User $target): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->hasRole('school-admin') && $actor->tenant_id === $target->tenant_id;
|
||||
}
|
||||
|
||||
public function delete(User $actor, User $target): bool
|
||||
{
|
||||
if ($actor->hasRole('platform-admin')) return true;
|
||||
return $actor->hasRole('school-admin') && $actor->tenant_id === $target->tenant_id;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Policies\LicensePolicy;
|
||||
use App\Policies\TenantPolicy;
|
||||
use App\Policies\UserPolicy;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
|
|
@ -19,6 +27,12 @@ class AppServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
if (app()->environment() !== 'testing') {
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
|
||||
Gate::policy(User::class, UserPolicy::class);
|
||||
Gate::policy(License::class, LicensePolicy::class);
|
||||
Gate::policy(Tenant::class, TenantPolicy::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue