Enable ZC to see netmail in their zone, and point owners to see their own netmail

This commit is contained in:
2023-12-18 13:00:04 +11:00
parent 6fb7d165ae
commit 1ded66990c
3 changed files with 66 additions and 2 deletions

View File

@@ -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);
}
}