fix(cloud): complete instance operation history

go
codex 4 weeks ago
parent 92179b6eb9
commit cccd2b9fda

@ -4125,16 +4125,12 @@ final class CloudJobService
return $fields;
}
/**
* Read the user's instance operation history directly from cloud_jobs.
* Power, reinstall and snapshot jobs are part of this user-facing audit view.
*/
/** Read the user's complete instance operation history from cloud_jobs. */
public static function operationLogs(CloudInstance $instance, int $page = 1, int $perPage = 10): array
{
$perPage = max(1, min(50, $perPage));
$query = CloudJob::where('instance_id', $instance->id)
->whereIn('kind', ['action', 'reinstall', 'snapshot_create',
'snapshot_restore', 'snapshot_delete', 'firewall_apply'])
->whereIn('kind', CloudOperationCatalog::instanceLogKinds())
->orderByDesc('id');
$total = max(0, (int) (clone $query)->count('id'));
$pages = max(1, (int) ceil($total / $perPage));

@ -52,6 +52,19 @@ final class CloudOperationCatalog
'reset' => '强制重置',
];
/** Jobs shown in the operation log on an instance detail page. */
private const INSTANCE_LOG_KINDS = [
'action',
'reinstall',
'instance_settings',
'network_change',
'firewall_apply',
'snapshot_create',
'snapshot_restore',
'snapshot_delete',
'rescue',
];
/** Safe server-derived detail codes retained with instance-setting jobs. */
private const INSTANCE_SETTING_FIELDS = [
'hostname' => '修改主机名',
@ -80,6 +93,12 @@ final class CloudOperationCatalog
return array_key_exists($action, self::POWER_ACTIONS);
}
/** Return every user-visible operation retained in instance history. */
public static function instanceLogKinds(): array
{
return self::INSTANCE_LOG_KINDS;
}
public static function kindLabel(?string $kind, ?string $action = null,
array $settingsFields = []): string
{

@ -31,7 +31,7 @@
</div>
<div id="vm-detail-operations-log-panel" class="vm-operation-log-view" role="tabpanel" aria-labelledby="vm-detail-tab-operations-log" hidden>
<section class="inventory-panel" aria-labelledby="vm-operation-log-title">
<div class="panel-heading"><div><h2 id="vm-operation-log-title">操作日志</h2><p>记录这台实例的开机、关机、重启和重装系统任务。</p></div><button id="vm-operation-log-refresh" class="button button-outline" type="button">刷新</button></div>
<div class="panel-heading"><div><h2 id="vm-operation-log-title">操作日志</h2><p>记录这台实例的电源、重装、设置、网络、防火墙、快照和救援操作。</p></div><button id="vm-operation-log-refresh" class="button button-outline" type="button">刷新</button></div>
<p id="vm-operation-log-status" class="vm-operation-log-status" role="status">打开操作日志后加载。</p>
<div class="vm-operation-log-table" role="table" aria-label="实例操作日志">
<div class="vm-operation-log-row vm-operation-log-header" role="row"><span role="columnheader">执行操作</span><span role="columnheader">提交时间</span><span role="columnheader">结果</span></div>

@ -26,6 +26,7 @@ namespace {
use App\Services\Cloud\CloudError;
use App\Services\Cloud\CloudInput;
use App\Services\Cloud\CloudJobService;
use App\Services\Cloud\CloudOperationCatalog;
use App\Services\Cloud\CloudOperationErrorCatalog;
use App\Services\Cloud\CloudSecrets;
use App\Services\Cloud\CloudSnapshotService;
@ -625,5 +626,16 @@ namespace {
$assert((string) $reinstallAfterDelete->status === 'queued',
'Deleting the final snapshot did not release reinstall admission.');
$operationLogIds = array_column(
CloudJobService::operationLogs($instance, 1, 50)['items'], 'id'
);
$assert(CloudOperationCatalog::instanceLogKinds() === [
'action', 'reinstall', 'instance_settings', 'network_change',
'firewall_apply', 'snapshot_create', 'snapshot_restore',
'snapshot_delete', 'rescue',
], 'The instance operation log does not cover every settings operation.');
$assert(in_array((string) $settingsAfterDelete->id, $operationLogIds, true),
'An instance-settings task was omitted from the instance operation log.');
echo "Cloud snapshot catalog, admission and worker state machine passed.\n";
}

@ -737,7 +737,11 @@ $assert(str_contains($cloudRoutes, "'/vms/{id:[0-9]+}/operations'")
'VM operation logs must use a bounded PHP database-only API route');
$assert(str_contains($cloudTemplate, 'vm-operation-log-header')
&& str_contains($cloudTemplate, 'vm-operation-log-footer')
&& str_contains($clientScript, 'operationLogsPage'),
&& str_contains($clientScript, 'operationLogsPage')
&& str_contains($cloudTemplate,
'记录这台实例的电源、重装、设置、网络、防火墙、快照和救援操作。')
&& str_contains($cloudJobService,
'CloudOperationCatalog::instanceLogKinds()'),
'VM operation logs must remain a compact three-column paginated list');
$assert(is_string($cloudOperationCatalog)
&& str_contains($cloudOperationCatalog, "'network_change' => '更换公网 IP'")

Loading…
Cancel
Save