From 0bd2f6e82cd57eed96b2e8a5471f557a6c748b7c Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 4 Nov 2024 15:58:20 +1100 Subject: [PATCH] Continue to show all common addresses in Items Waiting tab, Add Address Clear Queue job to delete anything in the queue for an address --- app/Console/Commands/AddressClearQueue.php | 42 ++++++++++++++ app/Jobs/AddressClearQueue.php | 67 ++++++++++++++++++++++ app/Jobs/AddressIdle.php | 23 +------- app/Models/Address.php | 23 +++++--- app/Models/System.php | 8 +++ resources/views/system/addedit.blade.php | 20 +++---- 6 files changed, 146 insertions(+), 37 deletions(-) create mode 100644 app/Console/Commands/AddressClearQueue.php create mode 100644 app/Jobs/AddressClearQueue.php diff --git a/app/Console/Commands/AddressClearQueue.php b/app/Console/Commands/AddressClearQueue.php new file mode 100644 index 0000000..95952ab --- /dev/null +++ b/app/Console/Commands/AddressClearQueue.php @@ -0,0 +1,42 @@ +argument('ftn'),TRUE,TRUE); + + if (! $ao) { + $this->error('FTN not found: '.$this->argument('ftn')); + + return self::FAILURE; + } + + return Job::dispatchSync($ao); + } +} \ No newline at end of file diff --git a/app/Jobs/AddressClearQueue.php b/app/Jobs/AddressClearQueue.php new file mode 100644 index 0000000..6686012 --- /dev/null +++ b/app/Jobs/AddressClearQueue.php @@ -0,0 +1,67 @@ +ao = $ao->withoutRelations(); + } + + /** + * Execute the job. + */ + public function handle(): void + { + // Remove echomail not collected from echomail_seenby + DB::table('echomail_seenby') + ->where('address_id',$this->ao->id) + ->whereNotNull('export_at') + ->whereNull('sent_at') + ->delete(); + + // Remove FLAG_INTRANSIT from netmail that hasnt been delivered + DB::table('netmails') + ->where('tftn_id',$this->ao->id) + ->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT)) + ->update(['flags'=>DB::raw(sprintf('(flags & ~%d)',Message::FLAG_INTRANSIT))]); + + // Remove files not collected + DB::table('file_seenby') + ->where('address_id',$this->ao->id) + ->whereNotNull('export_at') + ->whereNull('sent_at') + ->delete(); + } +} \ No newline at end of file diff --git a/app/Jobs/AddressIdle.php b/app/Jobs/AddressIdle.php index b2cb3a6..8c9a80d 100644 --- a/app/Jobs/AddressIdle.php +++ b/app/Jobs/AddressIdle.php @@ -67,26 +67,6 @@ class AddressIdle implements ShouldQueue Log::info(sprintf('%s:- Delisting [%s], not seen for at least [%d] days',self::LOGKEY,$ao->ftn,$ao->system->last_seen?->diffInDays())); $contact = FALSE; - // Remove echomail not collected from echomail_seenby - DB::table('echomail_seenby') - ->where('address_id',$ao->id) - ->whereNotNull('export_at') - ->whereNull('sent_at') - ->delete(); - - // Remove FLAG_INTRANSIT from netmail that hasnt been delivered - DB::table('netmails') - ->where('tftn_id',$ao->id) - ->whereRaw(sprintf('(flags & %d) > 0',Message::FLAG_INTRANSIT)) - ->update(['flags'=>DB::raw(sprintf('(flags & ~%d)',Message::FLAG_INTRANSIT))]); - - // Remove files not collected - DB::table('file_seenby') - ->where('address_id',$ao->id) - ->whereNotNull('export_at') - ->whereNull('sent_at') - ->delete(); - // Remove subscribed echoareas $ao->echoareas()->detach(); @@ -97,6 +77,9 @@ class AddressIdle implements ShouldQueue $ao->validated = FALSE; $ao->save(); + // Clear the queue + AddressClearQueue::dispatchSync($ao); + // Email Alert if ($ao->system->users->count()) { Notification::send($ao->system->users,new NodeDelistedEmail($ao->withoutRelations())); diff --git a/app/Models/Address.php b/app/Models/Address.php index 17c923b..eb7e9f0 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -24,19 +24,28 @@ use App\Traits\{QueryCacheableConfig,ScopeActive}; * * If an address is validated, we know that the system is using the address (we've confirmed that during a session). * validated is update/removed is during a mailer session, confirming if the node has the address + * @todo Remove validated, if that system hasnt used the address for a defined period (eg: 30) * * We'll only trigger a poll to a system that we have mail for if active && validated, unless "forced". * * Any mail for that address will be delivered, if active && validated. * + * Address status: + * + Active (active=true/validated=true) - mail can flow and in one of our networks (we have session details) + * + Pending (active=true/validated=false) - remote hasnt configured address during a session and in one of our networks + * + Known (active=true/validated=true) - the node presented this address, but we didnt auth it, and its a network we are not in + * + Unconfirm (active=true/validated=true) - the node presented this address, but we dont manage the address (it uses a different hub) + * + Nodelist (active=true/validated=true) - the node presented this address, but we dont manage the address and its in a recent nodelist + * + Delisted (active=false/validated=true) - this node shouldnt use this address any more + * + Freed (active=false/validated=false) - this node shouldnt is known to not be using this address any more + * + * Other Status + * + citizen - The address belongs to one of our jurisdiction (hub_id = our address, NC,RC,ZC) + * + foreign - The address doesnt belong to our jurisdiction + * * @see \App\Http\Requests\AddressAdd::class for rules about AKA and role */ -// Need to add -// Calculated Region for an FTN, ie: find the parent and use their region id -// - if creating an RC, then the region is part of the creation, ZC region is 0 -// Then use this in createFTN - class Address extends Model { use QueryCacheableConfig,ScopeActive,SoftDeletes; @@ -246,7 +255,7 @@ class Address extends Model $o = self::findZone($do,$ftn['n'],$ftn['f'],$ftn['p'],$trashed); } - return ($o && $o->system->active) ? $o : NULL; + return ($o && ($trashed || $o->system->active)) ? $o : NULL; } public static function newFTN(string $address): self @@ -414,7 +423,7 @@ class Address extends Model public function scopeFTN($query) { return $query - ->select(['addresses.id','region_id','host_id','node_id','point_id','addresses.zone_id','addresses.active','role','security','addresses.system_id','addresses.active','validated']) + ->select(['addresses.id','region_id','host_id','node_id','point_id','addresses.zone_id','addresses.active','role','security','addresses.system_id','addresses.active','validated','deleted_at']) ->join('zones',['zones.id'=>'addresses.zone_id']) ->join('domains',['domains.id'=>'zones.domain_id']) ->orderBy('domains.name') diff --git a/app/Models/System.php b/app/Models/System.php index abc7dbc..bb03562 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -200,6 +200,14 @@ class System extends Model /* METHODS */ + public function addresses_common(): Collection + { + $our = our_address()->pluck('zone.domain_id')->unique(); + + // Return our akas, filter with our_addresses() + return $this->addresses->filter(fn($item)=>$our->contains($item->zone->domain_id)); + } + /** * Return the ACTIVE addresses that are common with our addresses * diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index bb2e599..1e61cf0 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -125,7 +125,7 @@ @foreach ($o->addresses as $oo) - trashed()) class="trashed" @elseif (! $oo->active) class="inactive" @endif>{{ $oo->ftn }}$oo->validated,'bi-radioactive'=>(! $oo->validated)])> + $oo->trashed(),'inactive'=>(! $oo->trashed()) && (! $oo->active)])>{{ $oo->ftn }}$oo->validated,'bi-radioactive'=>(! $oo->validated)])> {{ $oo->active ? 'YES' : 'NO' }} {{ $oo->security }} {{ $oo->role_name }} @@ -320,10 +320,10 @@ - @foreach ($o->aka_common() as $ao) + @foreach ($o->addresses_common() as $ao) - {{ $ao->ftn }} - {{ $ao->netmailWaiting()->count() }} + $ao->trashed(),'inactive'=>(! $ao->trashed()) && (! $ao->active)])>{{ $ao->ftn }} + {{ $ao->netmailWaiting()->count() }} @endforeach @@ -342,10 +342,10 @@ - @foreach ($o->aka_common() as $ao) + @foreach ($o->addresses_common() as $ao) - {{ $ao->ftn }} - {{ $ao->echomailWaiting()->count() }} + $ao->trashed(),'inactive'=>(! $ao->trashed()) && (! $ao->active)])>{{ $ao->ftn }} + {{ $ao->echomailWaiting()->count() }} @endforeach @@ -364,10 +364,10 @@ - @foreach ($o->aka_common() as $ao) + @foreach ($o->addresses_common() as $ao) - {{ $ao->ftn }} - {{ $ao->filesWaiting()->count() }} + $ao->trashed(),'inactive'=>(! $ao->trashed()) && (! $ao->active)])>{{ $ao->ftn }} + {{ $ao->filesWaiting()->count() }} @endforeach