Enable ZC to see netmail in their zone, and point owners to see their own netmail
This commit is contained in:
parent
6fb7d165ae
commit
1ded66990c
@ -6,6 +6,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
|
|
||||||
use App\Traits\{ScopeActive,UserSwitch};
|
use App\Traits\{ScopeActive,UserSwitch};
|
||||||
@ -91,6 +92,31 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function isZC(): bool
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
app/Policies/NetmailPolicy.php
Normal file
35
app/Policies/NetmailPolicy.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||||
|
|
||||||
|
use App\Models\{Netmail,User};
|
||||||
|
|
||||||
|
class NetmailPolicy
|
||||||
|
{
|
||||||
|
use HandlesAuthorization;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This determines whether a logged-in user can view a netmail
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param Netmail $netmail
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function view(User $user, Netmail $netmail): bool
|
||||||
|
{
|
||||||
|
$zones = $user->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))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -134,10 +134,13 @@ Route::middleware(['auth','verified','activeuser'])->group(function () {
|
|||||||
->where('o','[0-9]+');
|
->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::middleware(['auth','can:admin'])->group(function () {
|
||||||
Route::match(['get','post'],'address/merge/{id}',[SystemController::class,'address_merge']);
|
Route::match(['get','post'],'address/merge/{id}',[SystemController::class,'address_merge']);
|
||||||
Route::get('echomail/view/{o}',[EchomailController::class,'view']);
|
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::match(['get','post'],'setup',[HomeController::class,'setup']);
|
||||||
|
|
||||||
Route::view('user','user.home');
|
Route::view('user','user.home');
|
||||||
|
Loading…
Reference in New Issue
Block a user