diff --git a/app/Models/User.php b/app/Models/User.php index edce3cc..0263cbd 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -74,6 +74,17 @@ class User extends Authenticatable implements MustVerifyEmail /* GENERAL METHODS */ + public function addresses(): Collection + { + return Address::select('addresses.*') + ->join('systems',['systems.id'=>'addresses.system_id']) + ->join('system_user',['system_user.system_id'=>'systems.id']) + ->where('system_user.user_id',$this->id) + ->with(['zone.domain']) + ->get(); + } + + /** * See if the user is already a member of the chosen network * diff --git a/app/Policies/EchomailPolicy.php b/app/Policies/EchomailPolicy.php new file mode 100644 index 0000000..eaccc9e --- /dev/null +++ b/app/Policies/EchomailPolicy.php @@ -0,0 +1,28 @@ +isAdmin() + || $user->isZC() + || $o->seenby->pluck('id')->intersect($user->addresses()->pluck('id'))->count() + ); + } +} \ No newline at end of file diff --git a/app/Policies/NetmailPolicy.php b/app/Policies/NetmailPolicy.php index ef0e224..d4dae03 100644 --- a/app/Policies/NetmailPolicy.php +++ b/app/Policies/NetmailPolicy.php @@ -14,10 +14,10 @@ class NetmailPolicy * This determines whether a logged-in user can view a netmail * * @param User $user - * @param Netmail $netmail + * @param Netmail $o * @return bool */ - public function view(User $user, Netmail $netmail): bool + public function view(User $user, Netmail $o): bool { $zones = $user->zc()->pluck('zone') //->merge($user->rc()->pluck('zone')) @@ -28,8 +28,8 @@ class NetmailPolicy // Site Admins can always view return ( $user->isAdmin() - || ($zones->contains($netmail->fftn->zone)) - || ($zones->contains($netmail->tftn->zone)) + || ($zones->contains($o->fftn->zone)) + || ($zones->contains($o->tftn->zone)) ); } } \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 933f96a..97143f4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -135,12 +135,12 @@ Route::middleware(['auth','verified','activeuser'])->group(function () { }); Route::middleware(['auth','can:view,o'])->group(function () { + Route::get('echomail/view/{o}',[EchomailController::class,'view']); 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::match(['get','post'],'setup',[HomeController::class,'setup']); Route::view('user','user.home');