fix(admin): align overview filters and resource locks

go
codex 4 weeks ago
parent 873acf0fd8
commit eaea180b49

@ -41,10 +41,11 @@ final class CloudAdminInstanceService
self::applyFilters($query, $filters, $now);
$summary = (clone $query)->selectRaw(
'COUNT(*) AS total, '
. "COALESCE(SUM(CASE WHEN cloud_instances.service_status <> 'exempt' "
. "COALESCE(SUM(CASE WHEN cloud_instances.status = 'active' "
. "AND cloud_instances.service_status <> 'exempt' "
. 'AND cloud_instances.expires_at > ? AND cloud_instances.expires_at <= ? '
. 'THEN 1 ELSE 0 END), 0) AS expiring, '
. "COALESCE(SUM(CASE WHEN cloud_instances.network_status <> 'active' "
. "COALESCE(SUM(CASE WHEN COALESCE(cloud_instances.network_status, '') <> 'active' "
. 'THEN 1 ELSE 0 END), 0) AS network_restricted, '
. 'COALESCE(SUM(CASE WHEN ' . self::attentionSql()
. ' THEN 1 ELSE 0 END), 0) AS attention',
@ -265,7 +266,8 @@ final class CloudAdminInstanceService
if ($filters['expiry'] === 'exempt') {
$query->where('cloud_instances.service_status', 'exempt');
} elseif ($filters['expiry'] === 'soon') {
$query->where('cloud_instances.service_status', '<>', 'exempt')
$query->where('cloud_instances.status', 'active')
->where('cloud_instances.service_status', '<>', 'exempt')
->where('cloud_instances.expires_at', '>', $now)
->where('cloud_instances.expires_at', '<=', $now + 7 * 86400);
} elseif ($filters['expiry'] === 'expired') {
@ -273,7 +275,9 @@ final class CloudAdminInstanceService
->whereNotNull('cloud_instances.expires_at')->where('cloud_instances.expires_at', '<=', $now);
}
if ($filters['attention'] === 'network') {
$query->where('cloud_instances.network_status', '<>', 'active');
$query->whereRaw(
"COALESCE(cloud_instances.network_status, '') <> 'active'"
);
} elseif ($filters['attention'] === 'jobs') {
$query->whereRaw(self::attentionSql(), [$now - 86400]);
}

@ -25,7 +25,7 @@ final class CloudAdminOperationsService
$filters = self::filters($input);
$query = self::query();
self::applyFilters($query, $filters);
$lockedSql = self::lockedSql('cloud_jobs');
$lockedSql = self::resourceLockedSql('cloud_jobs');
$summaryRow = (clone $query)->selectRaw(
"COUNT(*) AS total, "
. "COALESCE(SUM(CASE WHEN cloud_jobs.phase <> 'terminal' THEN 1 ELSE 0 END), 0) AS active, "
@ -366,7 +366,7 @@ final class CloudAdminOperationsService
private static function applyFilters($query, array $filters): void
{
if ($filters['status'] === 'locked') {
$query->whereRaw(self::lockedSql('cloud_jobs'));
$query->whereRaw(self::resourceLockedSql('cloud_jobs'));
} elseif ($filters['status'] === 'attention') {
$query->where(static function ($attention): void {
$attention->where(static function ($failed): void {
@ -722,8 +722,8 @@ final class CloudAdminOperationsService
. self::terminalStateConflictSql($alias) . ')';
}
/** Keep the locked filter identical to the summary's resource fence count. */
private static function lockedSql(string $alias): string
/** Shared source of truth for every resource-fence counter and filter. */
public static function resourceLockedSql(string $alias): string
{
return '((' . $alias . ".phase = 'terminal' AND "
. $alias . ".outcome = 'failed' AND "

@ -132,7 +132,7 @@ final class CloudAdminOverviewService
. "SUM(CASE WHEN status = 'active' AND (service_status = 'exempt' "
. "OR (service_status = 'active' AND expires_at IS NOT NULL "
. "AND expires_at > {$now})) THEN 1 ELSE 0 END) AS service_normal, "
. "SUM(CASE WHEN status = 'active' AND network_status = 'active' "
. "SUM(CASE WHEN COALESCE(network_status, '') = 'active' "
. 'THEN 1 ELSE 0 END) AS network_normal, '
. "SUM(CASE WHEN status = 'active' AND service_status <> 'exempt' "
. "AND expires_at > {$now} AND expires_at <= {$weekEnd} THEN 1 ELSE 0 END) "
@ -163,8 +163,11 @@ final class CloudAdminOverviewService
private static function jobs(int $now, int $todayStart, int $tomorrow): array
{
$dayAgo = $now - self::DAY;
$lockedSql = CloudAdminOperationsService::resourceLockedSql(
'cloud_jobs'
);
$row = CloudJob::query()
->where(function ($query) use ($dayAgo) {
->where(function ($query) use ($dayAgo, $lockedSql) {
$query->where('phase', '<>', 'terminal')
->orWhere(function ($failed) use ($dayAgo) {
$failed->where('phase', 'terminal')
@ -173,12 +176,12 @@ final class CloudAdminOverviewService
$attention->where('terminal_at', '>=', $dayAgo)
->orWhere('effect_resolution', 'unknown');
});
});
})->orWhereRaw($lockedSql);
})->selectRaw(
"SUM(CASE WHEN phase = 'accepted' THEN 1 ELSE 0 END) AS queued_count, "
. "SUM(CASE WHEN phase IN ('dispatching','awaiting_receipt') THEN 1 ELSE 0 END) AS running_count, "
. "SUM(CASE WHEN phase = 'terminal' AND outcome = 'failed' "
. "AND effect_resolution = 'unknown' THEN 1 ELSE 0 END) AS unresolved_effect_count, "
. 'SUM(CASE WHEN ' . $lockedSql
. ' THEN 1 ELSE 0 END) AS unresolved_effect_count, '
. "SUM(CASE WHEN phase = 'terminal' AND outcome = 'failed' "
. "AND terminal_at >= {$dayAgo} "
. 'THEN 1 ELSE 0 END) AS failed_24h'

@ -1,6 +1,6 @@
# 验证码设置迁移
管理员后台的「配置文件 → 验证码设置」管理以下六项。登录、注册和密码找回流程都从 `configurations` 数据表读取,不读取 `config/.config.php` 中同名参数。付费注册已删除。
管理员后台的「站点设置 → 验证码设置」管理以下六项。登录、注册和密码找回流程都从 `configurations` 数据表读取,不读取 `config/.config.php` 中同名参数。付费注册已删除。
| 配置项 | 无数据库记录时的默认值 | 作用 |
| --- | --- | --- |

@ -1,6 +1,6 @@
# 中国大陆 IP 注册限制
后台配置文件页面的“禁止中国大陆 IP 注册”开启后,服务端会在注册提交和注册邮箱验证码发送时检查连接 IP。中国大陆地址会被拒绝;香港、澳门、台湾按独立地区处理。付费注册已删除。
后台站点设置页面的“禁止中国大陆 IP 注册”开启后,服务端会在注册提交和注册邮箱验证码发送时检查连接 IP。中国大陆地址会被拒绝;香港、澳门、台湾按独立地区处理。付费注册已删除。
## 上线前准备

@ -1,6 +1,6 @@
# 注册邮箱白名单迁移
注册验证码的邮箱域名白名单现由管理后台「配置文件 → 注册设置」维护。运行时读取主数据库 `configurations` 表中的 `verifyEmailType`(`0` 关闭、`1` 开启)和 `verifyEmail`(例如 `@qq.com,@gmail.com`),不再读取 `config/.config.php` 的同名配置。
注册验证码的邮箱域名白名单现由管理后台「站点设置 → 注册设置」维护。运行时读取主数据库 `configurations` 表中的 `verifyEmailType`(`0` 关闭、`1` 开启)和 `verifyEmail`(例如 `@qq.com,@gmail.com`),不再读取 `config/.config.php` 的同名配置。
已有站点上线前,请先从现网 `config/.config.php` 记录这两项的实际值,并在主数据库 `configurations` 表中写入相同的 `name`/`value`;已存在的同名记录应更新,不要重复插入。建议在维护窗口暂停注册后完成预置、发布代码,再到后台确认显示与旧值一致,然后恢复注册。保存后台表单后会刷新对应 Redis 缓存。

@ -0,0 +1,30 @@
<?php
$root = dirname(__DIR__);
$documents = [
'captcha-configuration.md' => [
'old' => '配置文件 → 验证码设置',
'new' => '站点设置 → 验证码设置',
],
'registration-email-whitelist.md' => [
'old' => '配置文件 → 注册设置',
'new' => '站点设置 → 注册设置',
],
'china-ip-registration.md' => [
'old' => '后台配置文件页面',
'new' => '后台站点设置页面',
],
];
foreach ($documents as $name => $phrases) {
$contents = file_get_contents($root . '/docs/' . $name);
if (!is_string($contents)
|| str_contains($contents, $phrases['old'])
|| !str_contains($contents, $phrases['new'])) {
throw new RuntimeException(
$name . ' must use the current administrator navigation name.'
);
}
}
echo "Administrator documentation terminology contract passed.\n";

@ -2,6 +2,7 @@
$root = dirname(__DIR__);
$servicePath = $root . '/app/Services/Cloud/CloudAdminOverviewService.php';
$operationsPath = $root . '/app/Services/Cloud/CloudAdminOperationsService.php';
$controllerPath = $root . '/app/Controllers/AdminController.php';
$templatePath = $root . '/resources/views/venix/admin/index.tpl';
$headerPath = $root . '/resources/views/venix/admin/static_header.tpl';
@ -22,6 +23,7 @@ $assert(is_file($servicePath) && is_file($sharedStylePath) && !is_file($removedS
'Administrator overview must use the shared legacy administrator stylesheet.');
$service = file_get_contents($servicePath);
$operations = file_get_contents($operationsPath);
$controller = file_get_contents($controllerPath);
$template = file_get_contents($templatePath);
$header = file_get_contents($headerPath);
@ -55,7 +57,7 @@ $assert(str_contains($service, "where('status', 'paid')")
&& str_contains($service, "where('phase', 'terminal')")
&& str_contains($service, "where('outcome', 'failed')")
&& str_contains($service,
"effect_resolution = 'unknown' THEN 1 ELSE 0 END) AS unresolved_effect_count")
"CloudAdminOperationsService::resourceLockedSql(")
&& str_contains($service,
"'unresolved_effect' => (int) (\$row?->unresolved_effect_count ?? 0)")
&& str_contains($service, "outcome = 'failed'")
@ -65,6 +67,11 @@ $assert(str_contains($service, "where('status', 'paid')")
&& str_contains($service, "modify('+1 day')"),
'Financial, instance and job overview boundaries are incomplete.');
$assert(str_contains($operations,
'public static function resourceLockedSql(string $alias): string')
&& substr_count($operations, "resourceLockedSql('cloud_jobs')") >= 2,
'Resource-lock counters and filters must use one shared predicate.');
$assert(str_contains($service, '$row = CloudJob::query()')
&& str_contains($service, '$today = CloudJob::where(\'kind\', \'create\')'),
'Operational task cards must cover every task while business-flow totals remain provisioning-only.');

@ -29,16 +29,39 @@ $schema->create('cloud_instances', static function (Blueprint $table): void {
});
$schema->create('cloud_jobs', static function (Blueprint $table): void {
$table->increments('id');
$table->string('operation_id')->default('00000000000000000000000000000000');
$table->string('request_idempotency_key')->default('overview-fixture-key');
$table->string('request_fingerprint')->default(
'0000000000000000000000000000000000000000000000000000000000000000'
);
$table->integer('parent_job_id')->nullable();
$table->integer('order_id')->nullable();
$table->integer('invoice_id')->nullable();
$table->integer('instance_id')->nullable();
$table->integer('snapshot_id')->nullable();
$table->integer('user_id')->default(1);
$table->integer('host_id')->default(1);
$table->string('kind');
$table->string('execution_mode')->default('agent');
$table->string('phase');
$table->string('outcome')->nullable();
$table->integer('attempts')->default(1);
$table->integer('dispatch_attempts')->nullable()->default(1);
$table->integer('dispatch_deadline_at')->default(1);
$table->integer('dispatch_started_at')->nullable()->default(1);
$table->integer('agent_accepted_at')->nullable()->default(1);
$table->integer('receipt_deadline_at')->nullable()->default(1);
$table->integer('dispatched_at')->nullable()->default(1);
$table->string('completion_event_id')->nullable();
$table->boolean('effect_may_have_applied')->nullable()->default(0);
$table->boolean('safe_to_resubmit')->nullable()->default(0);
$table->string('effect_resolution')->default('not_applicable');
$table->integer('terminal_at')->nullable();
$table->string('status');
$table->string('error_code')->nullable();
$table->boolean('finalization_incident')->default(0);
$table->string('finalization_error_code')->nullable();
$table->text('result_json')->nullable();
$table->integer('created_at');
$table->integer('updated_at');
});
@ -127,6 +150,24 @@ Capsule::table('cloud_jobs')->insert([
'outcome' => 'failed', 'effect_resolution' => 'not_applicable',
'terminal_at' => $now - 90000, 'status' => 'failed', 'created_at' => $today - 172800,
'updated_at' => $now - 90000],
['order_id' => null, 'kind' => 'host_storage_configure', 'phase' => 'terminal',
'outcome' => 'failed', 'effect_resolution' => 'unknown',
'terminal_at' => $now - 15, 'status' => 'failed',
'created_at' => $today + 80, 'updated_at' => $now],
]);
Capsule::table('cloud_jobs')->insert([
['order_id' => null, 'kind' => 'rescue', 'phase' => 'terminal',
'outcome' => 'succeeded', 'effect_resolution' => 'applied',
'terminal_at' => $now - 14, 'status' => 'succeeded',
'finalization_incident' => 1,
'finalization_error_code' => 'recovery_dispatch_ledger_conflict',
'created_at' => $today + 81, 'updated_at' => $now],
['order_id' => null, 'kind' => 'reinstall', 'phase' => 'terminal',
'outcome' => 'succeeded', 'effect_resolution' => 'applied',
'terminal_at' => $now - 13, 'status' => 'succeeded',
'finalization_incident' => 1,
'finalization_error_code' => 'recovery_dispatch_repair_evidence_conflict',
'created_at' => $today + 82, 'updated_at' => $now],
]);
Capsule::table('shop')->insert(['id' => 1, 'name' => '2c4g']);
Capsule::table('cloud_invoices')->insert([
@ -173,16 +214,19 @@ $assert = static function ($condition, string $message): void {
$assert($overview['hosts'] === ['total' => 2, 'enabled' => 1],
'Host enabled/configured aggregation is incorrect.');
$assert($overview['jobs']['unresolved_effect'] === 5,
'Resource-lock count must include recovery incidents while excluding retryable host storage failures.');
$assert($overview['instances']['managed'] === 4
&& $overview['instances']['billable'] === 3
&& $overview['instances']['service_normal'] === 2
&& $overview['instances']['network_normal'] === 2
&& $overview['instances']['network_normal'] === 3
&& $overview['instances']['network_attention'] === 1
&& $overview['instances']['expiring_7d'] === 1
&& $overview['instances']['grace'] === 1,
'Instance lifecycle aggregation is incorrect.');
$assert($overview['jobs']['active'] === 2
&& $overview['jobs']['unresolved_effect'] === 3
&& $overview['jobs']['failed_24h'] === 4
&& $overview['jobs']['unresolved_effect'] === 5
&& $overview['jobs']['failed_24h'] === 5
&& $overview['jobs']['today_total'] === 5
&& $overview['jobs']['today_succeeded'] === 2
&& $overview['jobs']['today_failed'] === 3,

@ -270,6 +270,9 @@ namespace {
$insertInstance(214, ['spec_json' => json_encode([
'public_ip_cidr' => '203.0.113.74/24', 'vcpu' => 4, 'memory_mib' => 4096,
])]);
$insertInstance(215, [
'status' => 'delete_failed', 'expires_at' => $now + 2 * 86400,
]);
Capsule::table('cloud_service_periods')->insert([
'id' => 1, 'instance_id' => 206, 'user_id' => 2,
'starts_at' => $now - 28 * 86400, 'ends_at' => $now + 2 * 86400, 'status' => 'active',
@ -357,10 +360,10 @@ namespace {
// All timestamps are deliberately identical: ordering must include the ID.
$page = CloudAdminInstanceService::page($admin);
$assert($page['pagination']['total'] === 213 && count($page['items']) === 20
&& $ids($page['items']) === array_values(array_diff(range(214, 194), [211])),
$assert($page['pagination']['total'] === 214 && count($page['items']) === 20
&& $ids($page['items']) === array_values(array_diff(range(215, 195), [211])),
'Administrator first page lost records above 200, included deleted rows, or sorted ties unstably.');
$assert($page['summary']['total'] === 213 && $page['summary']['expiring'] === 1
$assert($page['summary']['total'] === 214 && $page['summary']['expiring'] === 1
&& $page['summary']['network_restricted'] === 2 && $page['summary']['attention'] === 2,
'Database statistics must cover the complete filtered population and preserve state meanings.');
$assert(!isset($page['summary']['running']) && !isset($page['summary']['stopped']),
@ -370,11 +373,11 @@ namespace {
$chunk = CloudAdminInstanceService::page($admin, ['page' => (string) $number, 'per_page' => '100']);
$seen = array_merge($seen, $ids($chunk['items']));
}
$assert(count($seen) === 213 && count(array_unique($seen)) === 213
&& $seen === array_values(array_diff(range(214, 1), [211])),
$assert(count($seen) === 214 && count(array_unique($seen)) === 214
&& $seen === array_values(array_diff(range(215, 1), [211])),
'Paging beyond 200 duplicated or silently truncated instances.');
$last = CloudAdminInstanceService::page($admin, ['page' => '9999', 'per_page' => '100']);
$assert($last['pagination']['page'] === 3 && count($last['items']) === 13,
$assert($last['pagination']['page'] === 3 && count($last['items']) === 14,
'Out-of-range pages did not clamp to the last valid page.');
$oldest = CloudAdminInstanceService::page($admin, ['sort' => 'oldest']);
$assert($ids($oldest['items']) === range(1, 20), 'Oldest sorting needs a stable ascending ID order.');

Loading…
Cancel
Save