Enabled akas() method to only show current active akas. Should fix the link register netmail from polling an invalid FTN id.

This commit is contained in:
2023-06-23 21:28:29 +10:00
parent b8534d8598
commit fdbc58856b
8 changed files with 52 additions and 26 deletions

View File

@@ -61,6 +61,18 @@ class Address extends Model
/* SCOPES */
public function scopeActive($query)
{
return $query->select($this->getTable().'.*')
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('addresses.active',TRUE)
->where('zones.active',TRUE)
->where('domains.active',TRUE)
->orderBy('domains.name')
->FTNorder();
}
public function scopeFTNOrder($query)
{
return $query
@@ -293,6 +305,17 @@ class Address extends Model
/* ATTRIBUTES */
/**
* Return if this address is active
*
* @param bool $value
* @return bool
*/
public function getActiveAttribute(bool $value): bool
{
return $value && $this->zone->active && $this->zone->domain->active;
}
/**
* Render the node name in full 5D
*
@@ -356,7 +379,6 @@ class Address extends Model
// Are we looking for a region address
if (($ftn['f'] === 0) && $ftn['p'] === 0) {
$o = (new self)->active()
->select('addresses.*')
->where('zones.zone_id',$ftn['z'])
->where(function($q) use ($ftn) {
return $q
@@ -367,11 +389,6 @@ class Address extends Model
})
->where('node_id',$ftn['f'])
->where('point_id',$ftn['p'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('zones.active',TRUE)
->where('domains.active',TRUE)
->where('addresses.active',TRUE)
->when($ftn['d'],function($query,$domain) {
$query->where('domains.name',$domain);
})
@@ -385,7 +402,6 @@ class Address extends Model
}
$o = (new self)->active()
->select('addresses.*')
->where('zones.zone_id',$ftn['z'])
->where(function($q) use ($ftn) {
return $q->where(function($qq) use ($ftn) {
@@ -400,11 +416,6 @@ class Address extends Model
})
->where('node_id',$ftn['f'])
->where('point_id',$ftn['p'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->join('domains',['domains.id'=>'zones.domain_id'])
->where('zones.active',TRUE)
->where('domains.active',TRUE)
->where('addresses.active',TRUE)
->when($ftn['d'],function($query,$domain) {
$query->where('domains.name',$domain);
})

View File

@@ -59,17 +59,19 @@ final class Netmail extends Model implements Packet
static::created(function($model) {
// Save the Path
$ppoid = NULL;
foreach ($model->set_path as $path) {
$po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[
$model->id,
$path['node']->id,
$ppoid,
(string)$path['datetime'],
$path['program'],
]);
$ppoid = $po[0]->id;
}
if (isset($model->set_path))
foreach ($model->set_path as $path) {
$po = DB::select('INSERT INTO netmail_path (netmail_id,address_id,parent_id,datetime,program) VALUES (?,?,?,?,?) RETURNING id',[
$model->id,
$path['node']->id,
$ppoid,
(string)$path['datetime'],
$path['program'],
]);
$ppoid = $po[0]->id;
}
});
}

View File

@@ -40,6 +40,12 @@ class System extends Model
->FTNorder();
}
public function akas()
{
return $this->hasMany(Address::class)
->active();
}
public function logs()
{
return $this->hasMany(SystemLog::class);