Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | class Domain extends Model | ||||
* | * | ||||
* @param \App\Package $package The package to assign. | * @param \App\Package $package The package to assign. | ||||
* @param \App\User $user The wallet owner. | * @param \App\User $user The wallet owner. | ||||
* | * | ||||
* @return \App\Domain Self | * @return \App\Domain Self | ||||
*/ | */ | ||||
public function assignPackage($package, $user) | public function assignPackage($package, $user) | ||||
{ | { | ||||
// If this domain is public it can not be assigned to a user. | |||||
if ($this->isPublic()) { | |||||
machniak: We need a test for this change. I also propose to throw an exception here. | |||||
return $this; | |||||
} | |||||
// See if this domain is already owned by another user. | |||||
$wallet = $this->wallet(); | |||||
if ($wallet) { | |||||
\Log::error( | |||||
Not Done Inline ActionsI propose to use an exception here. Would be good to test this too. machniak: I propose to use an exception here. Would be good to test this too. | |||||
"Domain {$this->namespace} is already assigned to {$wallet->owner->email}" | |||||
); | |||||
return $this; | |||||
} | |||||
$wallet_id = $user->wallets()->first()->id; | $wallet_id = $user->wallets()->first()->id; | ||||
foreach ($package->skus as $sku) { | foreach ($package->skus as $sku) { | ||||
for ($i = $sku->pivot->qty; $i > 0; $i--) { | for ($i = $sku->pivot->qty; $i > 0; $i--) { | ||||
\App\Entitlement::create( | \App\Entitlement::create( | ||||
[ | [ | ||||
'wallet_id' => $wallet_id, | 'wallet_id' => $wallet_id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => $sku->pivot->cost(), | 'cost' => $sku->pivot->cost(), | ||||
'entitleable_id' => $this->id, | 'entitleable_id' => $this->id, | ||||
'entitleable_type' => Domain::class | 'entitleable_type' => Domain::class | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
public function entitlement() | public function entitlement() | ||||
{ | { | ||||
return $this->morphOne('App\Entitlement', 'entitleable'); | return $this->morphOne('App\Entitlement', 'entitleable'); | ||||
} | } | ||||
/** | /** | ||||
* Return list of public+active domain names | * Return list of public+active domain names | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | class Domain extends Model | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isVerified(): bool | public function isVerified(): bool | ||||
{ | { | ||||
return ($this->status & self::STATUS_VERIFIED) > 0; | return ($this->status & self::STATUS_VERIFIED) > 0; | ||||
} | } | ||||
/** | /** | ||||
* Ensure the namespace is appropriately cased. | |||||
*/ | |||||
public function setNamespaceAttribute($namespace) | |||||
{ | |||||
$this->attributes['namespace'] = strtolower($namespace); | |||||
} | |||||
/** | |||||
* Domain status mutator | * Domain status mutator | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
public function setStatusAttribute($status) | public function setStatusAttribute($status) | ||||
{ | { | ||||
$new_status = 0; | $new_status = 0; | ||||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |
We need a test for this change. I also propose to throw an exception here.