Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/DomainsController.php
Show All 15 Lines | class DomainsController extends Controller | ||||
/** | /** | ||||
* Return a list of domains owned by the current user | * Return a list of domains owned by the current user | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$user = $this->guard()->user(); | $user = $this->guard()->user(); | ||||
$list = []; | |||||
foreach ($user->domains() as $domain) { | $list = \collect($user->domains()) | ||||
if (!$domain->isPublic()) { | ->filter(function ($domain) { | ||||
$data = $domain->toArray(); | return !$domain->isPublic(); | ||||
$data = array_merge($data, self::domainStatuses($domain)); | }) | ||||
$list[] = $data; | ->map(function ($domain) { | ||||
} | return $this->domainToClient($domain); | ||||
} | }) | ||||
->sortBy('namespace') | |||||
usort($list, function ($a, $b) { | ->values() | ||||
return strcmp($a['namespace'], $b['namespace']); | ->all(); | ||||
}); | |||||
return response()->json($list); | return response()->json($list); | ||||
} | } | ||||
/** | /** | ||||
* Show the form for creating a new domain. | * Show the form for creating a new domain. | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | public function show($id) | ||||
if (!$this->checkTenant($domain)) { | if (!$this->checkTenant($domain)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
if (!$this->guard()->user()->canRead($domain)) { | if (!$this->guard()->user()->canRead($domain)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$response = $domain->toArray(); | $response = self::domainToClient($domain, true); | ||||
// Add hash information to the response | // Add hash information to the response | ||||
$response['hash_text'] = $domain->hash(Domain::HASH_TEXT); | $response['hash_text'] = $domain->hash(Domain::HASH_TEXT); | ||||
$response['hash_cname'] = $domain->hash(Domain::HASH_CNAME); | $response['hash_cname'] = $domain->hash(Domain::HASH_CNAME); | ||||
$response['hash_code'] = $domain->hash(Domain::HASH_CODE); | $response['hash_code'] = $domain->hash(Domain::HASH_CODE); | ||||
// Add DNS/MX configuration for the domain | // Add DNS/MX configuration for the domain | ||||
$response['dns'] = self::getDNSConfig($domain); | $response['dns'] = self::getDNSConfig($domain); | ||||
$response['mx'] = self::getMXConfig($domain->namespace); | $response['mx'] = self::getMXConfig($domain->namespace); | ||||
// Domain configuration, e.g. spf whitelist | // Domain configuration, e.g. spf whitelist | ||||
$response['config'] = $domain->getConfig(); | $response['config'] = $domain->getConfig(); | ||||
// Status info | // Status info | ||||
$response['statusInfo'] = self::statusInfo($domain); | $response['statusInfo'] = self::statusInfo($domain); | ||||
// Entitlements info | // Entitlements info | ||||
$response['skus'] = \App\Entitlement::objectEntitlementsSummary($domain); | $response['skus'] = \App\Entitlement::objectEntitlementsSummary($domain); | ||||
$response = array_merge($response, self::domainStatuses($domain)); | |||||
// Some basic information about the domain wallet | // Some basic information about the domain wallet | ||||
$wallet = $domain->wallet(); | $wallet = $domain->wallet(); | ||||
$response['wallet'] = $wallet->toArray(); | $response['wallet'] = $wallet->toArray(); | ||||
if ($wallet->discount) { | if ($wallet->discount) { | ||||
$response['wallet']['discount'] = $wallet->discount->discount; | $response['wallet']['discount'] = $wallet->discount->discount; | ||||
$response['wallet']['discount_description'] = $wallet->discount->description; | $response['wallet']['discount_description'] = $wallet->discount->description; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | protected static function domainStatuses(Domain $domain): array | ||||
'isVerified' => $domain->isVerified(), | 'isVerified' => $domain->isVerified(), | ||||
'isSuspended' => $domain->isSuspended(), | 'isSuspended' => $domain->isSuspended(), | ||||
'isActive' => $domain->isActive(), | 'isActive' => $domain->isActive(), | ||||
'isDeleted' => $domain->isDeleted() || $domain->trashed(), | 'isDeleted' => $domain->isDeleted() || $domain->trashed(), | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Prepare a domain for the UI. | |||||
* | |||||
* @param \App\Domain $domain Domain object | |||||
* @param bool $full Include all domain properties | |||||
* | |||||
* @return array Domain info | |||||
*/ | |||||
protected static function domainToClient(Domain $domain, bool $full = false): array | |||||
{ | |||||
if ($full) { | |||||
$result = $domain->toArray(); | |||||
} else { | |||||
$result = [ | |||||
'id' => $domain->id, | |||||
'namespace' => $domain->namespace, | |||||
'status' => $domain->status, | |||||
'type' => $domain->type, | |||||
]; | |||||
} | |||||
$result = array_merge($result, self::domainStatuses($domain)); | |||||
return $result; | |||||
} | |||||
/** | |||||
* Domain status (extended) information. | * Domain status (extended) information. | ||||
* | * | ||||
* @param \App\Domain $domain Domain object | * @param \App\Domain $domain Domain object | ||||
* | * | ||||
* @return array Status information | * @return array Status information | ||||
*/ | */ | ||||
public static function statusInfo(Domain $domain): array | public static function statusInfo(Domain $domain): array | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |