From fdbc58856b723f090283ba7b6da560c5c181252a Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 23 Jun 2023 21:28:29 +1000 Subject: [PATCH] Enabled akas() method to only show current active akas. Should fix the link register netmail from polling an invalid FTN id. --- app/Http/Controllers/SystemController.php | 2 +- app/Models/Address.php | 35 ++++++++++++------- app/Models/Netmail.php | 22 ++++++------ app/Models/System.php | 6 ++++ public/oldschool/css/main.css | 4 +++ resources/views/dashboard.blade.php | 2 +- resources/views/system/addedit.blade.php | 5 ++- .../system/widget/register_confirm.blade.php | 2 +- 8 files changed, 52 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 636ae4c..1c31ff7 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -596,7 +596,7 @@ class SystemController extends Controller $ca = NULL; $la = NULL; - foreach ($s->addresses as $ao) { + foreach ($s->akas as $ao) { if (($ca=$so->match($ao->zone))->count()) break; } diff --git a/app/Models/Address.php b/app/Models/Address.php index 8f80594..98b06bb 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -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); }) diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index d9fbb9b..605dc00 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -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; + } }); } diff --git a/app/Models/System.php b/app/Models/System.php index 8a52847..2a0da80 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -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); diff --git a/public/oldschool/css/main.css b/public/oldschool/css/main.css index 81ce2cb..c71e8b7 100644 --- a/public/oldschool/css/main.css +++ b/public/oldschool/css/main.css @@ -819,6 +819,10 @@ a.link:focus:after { color: #0c0c0c; } +.inactive { + color: #3f6982; +} + .trashed { text-decoration: line-through; color: #3f6982; diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 5cfdf66..c85133d 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -24,7 +24,7 @@ @foreach ($user->systems as $o) {{ $o->name }} - {!! $o->addresses->pluck('ftn')->join('
') !!} + {!! $o->akas->pluck('ftn')->join('
') !!} @endforeach diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 9c06670..bd5fafd 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -107,7 +107,7 @@ @foreach ($o->addresses->sortBy(function($item) { return sprintf('%04x%04x%04x%04x%04x',$item->zone->zone_id,$item->region_id,$item->host_id,$item->node_id,$item->point_id); }) as $oo) - trashed()) class="trashed" @endif>{{ $oo->ftn }} + trashed()) class="trashed" @elseif (! $oo->active) class="inactive" @endif>{{ $oo->ftn }} {{ $oo->active ? 'YES' : 'NO' }} {{ $oo->role_name }} @@ -120,6 +120,9 @@ @if($oo->trashed()) + @elseif(! $oo->active) + + @else diff --git a/resources/views/user/system/widget/register_confirm.blade.php b/resources/views/user/system/widget/register_confirm.blade.php index 34c65e5..c979266 100644 --- a/resources/views/user/system/widget/register_confirm.blade.php +++ b/resources/views/user/system/widget/register_confirm.blade.php @@ -15,7 +15,7 @@ Networks - {{ $o->addresses->pluck('ftn')->join(', ') }} + {{ $o->akas->pluck('ftn')->join(', ') }} Address