Abstract address session() details

This commit is contained in:
2024-06-14 15:09:04 +10:00
parent 0304967e80
commit df2873287c
14 changed files with 70 additions and 29 deletions

View File

@@ -40,7 +40,6 @@ use App\Traits\{QueryCacheableConfig,ScopeActive};
class Address extends Model
{
use QueryCacheableConfig,ScopeActive,SoftDeletes;
const CACHE_KEY = 0;
private const LOGKEY = 'MA-';
@@ -358,12 +357,12 @@ class Address extends Model
}
return [
'z'=>(int)$zone_id ?: $matches[1],
'r'=>(int)$region_id,
'n'=>(int)$matches[2],
'f'=>(int)$matches[3],
'p'=>empty($matches[4]) ? 0 : (int)$matches[4],
'd'=>$matches[5] ?? NULL
'z' => (int)$zone_id ?: $matches[1],
'r' => (int)$region_id,
'n' => (int)$matches[2],
'f' => (int)$matches[3],
'p' => empty($matches[4]) ? 0 : (int)$matches[4],
'd' => $matches[5] ?? NULL
];
}
@@ -386,6 +385,18 @@ class Address extends Model
->FTNorder();
}
/**
* Select to support returning FTN address
*
* @param $query
* @return void
*/
public function scopeFTN($query)
{
return $query->select(['zone_id','host_id','node_id','point_id'])
->with('zone.domain');
}
public function scopeFTNOrder($query)
{
return $query
@@ -744,11 +755,21 @@ class Address extends Model
return sprintf('%s.%d',$this->getFTN3DAttribute(),$this->point_id);
}
public function getIsDefaultRouteAttribute(): bool
{
return ! is_null($this->session('default'));
}
public function getIsDownAttribute(): bool
{
return $this->role & self::NODE_DOWN;
}
public function getIsHostedAttribute(): bool
{
return ! is_null($this->getPassSessionAttribute());
}
public function getIsHoldAttribute(): bool
{
return $this->role & self::NODE_HOLD;
@@ -816,6 +837,26 @@ class Address extends Model
}
}
public function getPassFixAttribute(): ?string
{
return strtoupper($this->session('fixpass'));
}
public function getPassPacketAttribute(): ?string
{
return strtoupper($this->session('pktpass'));
}
public function getPassSessionAttribute(): ?string
{
return $this->session('sespass');
}
public function getPassTicAttribute(): ?string
{
return strtoupper($this->session('ticpass'));
}
/* METHODS */
/**
@@ -902,11 +943,11 @@ class Address extends Model
public function downlinks(): Collection
{
// We have no session data for this address, by definition it has no children
if (! $this->session('sespass') && (! our_address()->pluck('id')->contains($this->id)))
if (! $this->is_hosted && (! our_address()->pluck('id')->contains($this->id)))
return new Collection;
// If this system is not marked to default route for this address
if (! $this->session('default')) {
if (! $this->is_default_route) {
$children = $this->children();
// We route everything for this domain
@@ -1284,7 +1325,7 @@ class Address extends Model
* @param string $type
* @return string|null
*/
public function session(string $type): ?string
private function session(string $type): ?string
{
return ($this->exists && ($x=$this->system->sessions->where('id',$this->zone_id)->first())) ? ($x->pivot->{$type} ?: '') : NULL;
}
@@ -1302,7 +1343,7 @@ class Address extends Model
return NULL;
// If we have session password, then we are the parent
if ($x=$this->session('sespass'))
if ($this->is_hosted)
return $this;
if ($x=$this->parent()?->uplink()) {