Move DomainController::NODE* to Address::NODE*, make role mandatory in the database, change logic so that mail generated by the host comes from a node address.

This commit is contained in:
Deon George
2022-01-24 22:56:13 +11:00
parent efa7195633
commit d660d5a6df
15 changed files with 143 additions and 110 deletions

View File

@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\DomainController;
class System extends Model
{
use HasFactory;
@@ -103,17 +101,17 @@ class System extends Model
public function full_name(Address $o): string
{
switch ($o->attributes['role']) {
case DomainController::NODE_ZC;
case Address::NODE_ZC;
return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id);
case DomainController::NODE_RC;
case Address::NODE_RC;
return sprintf('RC-%s-%05d',$o->zone->domain->name,$o->region_id);
case DomainController::NODE_NC;
case Address::NODE_NC;
return sprintf('NC-%s-%05d',$o->zone->domain->name,$o->host_id);
case DomainController::NODE_HC;
case NULL:
case Address::NODE_HC;
case Address::NODE_ACTIVE;
default:
return $this->name;
}
@@ -121,12 +119,18 @@ class System extends Model
/**
* Return the system's address in the same zone
* This function can filter based on the address type needed.
*
* @param Zone $o
* @param int $type
* @return Collection
*/
public function match(Zone $o): Collection
public function match(Zone $o,int $type=(Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection
{
return $this->addresses->where('zone_id',$o->id);
return $this->addresses
->where('zone_id',$o->id)
->filter(function($item) use ($type) {
return $item->role & $type;
});
}
}