diff --git a/app/Models/User.php b/app/Models/User.php index e5e0286..edce3cc 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Collection; use Laravel\Sanctum\HasApiTokens; use App\Traits\{ScopeActive,UserSwitch}; @@ -91,6 +92,31 @@ class User extends Authenticatable implements MustVerifyEmail */ public function isZC(): bool { - return $this->systems->pluck('addresses')->flatten()->where('role',Address::NODE_ZC)->count() > 0; + return $this->zc()->count() > 0; + } + + /** + * Return the zones that this user is ZC for + * + * @return Collection + */ + public function points(): Collection + { + $result = collect(); + + foreach($this->systems->pluck('addresses')->flatten()->where('role','>',Address::NODE_HC) as $ao) + $result = $result->merge($ao->children()); + + return $result; + } + + /** + * Return the zones that this user is ZC for + * + * @return Collection + */ + public function zc(): Collection + { + return $this->systems->pluck('addresses')->flatten()->where('role',Address::NODE_ZC); } } diff --git a/app/Policies/NetmailPolicy.php b/app/Policies/NetmailPolicy.php new file mode 100644 index 0000000..ef0e224 --- /dev/null +++ b/app/Policies/NetmailPolicy.php @@ -0,0 +1,35 @@ +zc()->pluck('zone') + //->merge($user->rc()->pluck('zone')) + //->merge($user->nc()->pluck('zone')) + //->merge($user->hub()->pluck('zone')) + ->merge($user->points()->pluck('zone')); + + // Site Admins can always view + return ( + $user->isAdmin() + || ($zones->contains($netmail->fftn->zone)) + || ($zones->contains($netmail->tftn->zone)) + ); + } +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 0bc7e03..933f96a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -134,10 +134,13 @@ Route::middleware(['auth','verified','activeuser'])->group(function () { ->where('o','[0-9]+'); }); +Route::middleware(['auth','can:view,o'])->group(function () { + Route::get('netmail/view/{o}',[NetmailController::class,'view']); +}); + Route::middleware(['auth','can:admin'])->group(function () { Route::match(['get','post'],'address/merge/{id}',[SystemController::class,'address_merge']); Route::get('echomail/view/{o}',[EchomailController::class,'view']); - Route::get('netmail/view/{o}',[NetmailController::class,'view']); Route::match(['get','post'],'setup',[HomeController::class,'setup']); Route::view('user','user.home');