feat(i18n): add administrator copy workspace
parent
de20e4df4b
commit
c980b4da73
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Services\AdminPermission;
|
||||
use App\Services\Auth;
|
||||
use App\Services\UserCopy\UserCopyAdminException;
|
||||
use App\Services\UserCopy\UserCopyAdminService;
|
||||
use App\Services\UserCopy\UserCopyCatalogException;
|
||||
|
||||
final class UserCopyController extends AdminController
|
||||
{
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$workspace = null;
|
||||
$error = '';
|
||||
$status = 200;
|
||||
try {
|
||||
$workspace = $this->service()->workspace(
|
||||
$request->getQueryParams()
|
||||
);
|
||||
} catch (\Throwable $exception) {
|
||||
error_log('User copy administrator page failed: '
|
||||
. get_class($exception));
|
||||
$error = '用户界面译文暂时无法读取,请稍后重试。';
|
||||
$status = 503;
|
||||
}
|
||||
|
||||
$bootstrap = json_encode(
|
||||
$workspace,
|
||||
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
|
||||
| JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE
|
||||
| JSON_THROW_ON_ERROR
|
||||
);
|
||||
$smarty = $this->view()->assign([
|
||||
'user_copy_workspace' => $workspace,
|
||||
'user_copy_error' => $error,
|
||||
'user_copy_bootstrap_json' => $bootstrap,
|
||||
'user_copy_can_manage' => AdminPermission::isSuperAdmin(),
|
||||
]);
|
||||
$response->getBody()->write(
|
||||
$smarty->fetch('admin/user_copy.tpl')
|
||||
);
|
||||
return $response->withStatus($status)
|
||||
->withHeader('Cache-Control', 'private, no-store');
|
||||
}
|
||||
|
||||
public function entries($request, $response, $args)
|
||||
{
|
||||
try {
|
||||
$workspace = $this->service()->workspace(
|
||||
$request->getQueryParams()
|
||||
);
|
||||
return $this->json($response, ['workspace' => $workspace]);
|
||||
} catch (UserCopyAdminException $exception) {
|
||||
return $this->failure(
|
||||
$response,
|
||||
$exception->getMessage(),
|
||||
$exception->httpStatus
|
||||
);
|
||||
} catch (UserCopyCatalogException $exception) {
|
||||
return $this->failure($response, $exception->getMessage(), 422);
|
||||
} catch (\Throwable $exception) {
|
||||
error_log('User copy entries failed: ' . get_class($exception));
|
||||
return $this->failure(
|
||||
$response,
|
||||
'用户界面译文暂时无法读取,请稍后重试。',
|
||||
503
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function history($request, $response, $args)
|
||||
{
|
||||
try {
|
||||
$history = $this->service()->history(
|
||||
(string) ($request->getQueryParams()['locale'] ?? '')
|
||||
);
|
||||
return $this->json($response, ['history' => $history]);
|
||||
} catch (UserCopyAdminException $exception) {
|
||||
return $this->failure(
|
||||
$response,
|
||||
$exception->getMessage(),
|
||||
$exception->httpStatus
|
||||
);
|
||||
} catch (UserCopyCatalogException $exception) {
|
||||
return $this->failure($response, $exception->getMessage(), 422);
|
||||
} catch (\Throwable $exception) {
|
||||
error_log('User copy history failed: ' . get_class($exception));
|
||||
return $this->failure($response, '发布历史暂时无法读取。', 503);
|
||||
}
|
||||
}
|
||||
|
||||
public function draft($request, $response, $args)
|
||||
{
|
||||
return $this->write($request, $response, $args, 'draft');
|
||||
}
|
||||
|
||||
public function publish($request, $response, $args)
|
||||
{
|
||||
return $this->write($request, $response, $args, 'publish');
|
||||
}
|
||||
|
||||
public function rollback($request, $response, $args)
|
||||
{
|
||||
return $this->write($request, $response, $args, 'rollback');
|
||||
}
|
||||
|
||||
private function write($request, $response, array $args, string $action)
|
||||
{
|
||||
if (!AdminPermission::isSuperAdmin()) {
|
||||
return $this->failure($response, '只有超级管理员可以修改译文。', 403);
|
||||
}
|
||||
$input = $request->getParsedBody();
|
||||
if (!is_array($input)) {
|
||||
return $this->failure($response, '请求格式不正确。', 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$actor = $this->actor();
|
||||
$service = $this->service();
|
||||
if ($action === 'draft') {
|
||||
$result = $service->saveDraft(
|
||||
$actor,
|
||||
(string) ($args['copy_key'] ?? ''),
|
||||
(string) ($input['locale'] ?? ''),
|
||||
(string) ($input['text'] ?? ''),
|
||||
($input['hidden'] ?? false) === true
|
||||
? 'hidden' : 'visible',
|
||||
(int) ($input['draft_version'] ?? 0)
|
||||
);
|
||||
} elseif ($action === 'publish') {
|
||||
$idempotencyKey = trim((string) $request->getHeaderLine(
|
||||
'Idempotency-Key'
|
||||
));
|
||||
if ($idempotencyKey === '') {
|
||||
return $this->failure(
|
||||
$response,
|
||||
'发布请求缺少幂等标识,请刷新页面后重试。',
|
||||
400
|
||||
);
|
||||
}
|
||||
$result = $service->publish(
|
||||
$actor,
|
||||
(string) ($input['locale'] ?? ''),
|
||||
hash('sha256', $idempotencyKey)
|
||||
);
|
||||
} else {
|
||||
$result = $service->rollback(
|
||||
$actor,
|
||||
(string) ($input['locale'] ?? ''),
|
||||
(string) ($args['publication_key'] ?? '')
|
||||
);
|
||||
}
|
||||
return $this->json($response, ['entry' => $result]);
|
||||
} catch (UserCopyAdminException $exception) {
|
||||
return $this->failure(
|
||||
$response,
|
||||
$exception->getMessage(),
|
||||
$exception->httpStatus
|
||||
);
|
||||
} catch (UserCopyCatalogException $exception) {
|
||||
return $this->failure($response, $exception->getMessage(), 409);
|
||||
} catch (\Throwable $exception) {
|
||||
error_log('User copy write failed: ' . get_class($exception));
|
||||
return $this->failure(
|
||||
$response,
|
||||
'译文操作失败,请刷新页面核对后再试。',
|
||||
503
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function json($response, array $payload, int $status = 200)
|
||||
{
|
||||
return $response->withJson(['ret' => 1] + $payload, $status)
|
||||
->withHeader('Cache-Control', 'private, no-store');
|
||||
}
|
||||
|
||||
private function failure($response, string $message, int $status)
|
||||
{
|
||||
return $response->withJson([
|
||||
'ret' => 0,
|
||||
'msg' => $message,
|
||||
], $status)->withHeader('Cache-Control', 'private, no-store');
|
||||
}
|
||||
|
||||
private function service(): UserCopyAdminService
|
||||
{
|
||||
return UserCopyAdminService::fromApplication();
|
||||
}
|
||||
|
||||
/** @return array{user_id:int,is_admin:bool,is_super_admin:bool,can_manage:bool} */
|
||||
private function actor(): array
|
||||
{
|
||||
$user = Auth::getUser();
|
||||
$super = AdminPermission::isSuperAdmin();
|
||||
return [
|
||||
'user_id' => is_object($user) && isset($user->id)
|
||||
? (int) $user->id : 0,
|
||||
'is_admin' => is_object($user) && method_exists($user, 'isAdmin')
|
||||
? (bool) $user->isAdmin() : false,
|
||||
'is_super_admin' => $super,
|
||||
'can_manage' => $super,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
.user-copy-admin { --copy-ink: #17364a; --copy-muted: #718795; --copy-line: #dce6ea; --copy-soft: #f5f8f9; --copy-teal: #159fa6; }
|
||||
.user-copy-page-actions { display: flex; justify-content: flex-end; align-items: center; gap: 9px; flex-wrap: wrap; }
|
||||
.user-copy-toolbar { margin-bottom: 16px; padding: 18px; border: 1px solid var(--copy-line); border-radius: 14px; background: #fff; display: grid; grid-template-columns: minmax(220px, .8fr) minmax(180px, .55fr) minmax(320px, 1.4fr); gap: 16px; align-items: end; }
|
||||
.user-copy-toolbar label > span { margin-bottom: 7px; display: block; color: var(--copy-muted); font-size: 12px; font-weight: 700; }
|
||||
.user-copy-toolbar-note { min-height: 48px; padding: 10px 13px; border-radius: 10px; color: #3d6874; background: #edf8f7; display: flex; align-items: center; gap: 10px; font-size: 12px; line-height: 1.55; }
|
||||
.user-copy-toolbar-note i { color: var(--copy-teal); font-size: 20px; }
|
||||
.user-copy-coverage { margin-bottom: 16px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
|
||||
.user-copy-coverage article { padding: 17px 18px; border: 1px solid var(--copy-line); border-radius: 13px; background: #fff; }
|
||||
.user-copy-coverage article span { display: block; color: var(--copy-muted); font-size: 12px; }
|
||||
.user-copy-coverage article strong { margin-top: 5px; display: block; color: var(--copy-ink); font-size: 23px; }
|
||||
.user-copy-progress { height: 7px; border-radius: 999px; background: #e8eef0; grid-column: 1 / -2; overflow: hidden; }
|
||||
.user-copy-progress span { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #21b7ad, #108c9d); display: block; transition: width .25s ease; }
|
||||
.user-copy-coverage > p { margin: -8px 0 0; color: var(--copy-muted); display: flex; justify-content: flex-end; align-items: baseline; gap: 7px; font-size: 11px; }
|
||||
.user-copy-coverage > p strong { color: var(--copy-ink); font-size: 18px; }
|
||||
.user-copy-catalog { border-color: var(--copy-line); border-radius: 14px; overflow: hidden; }
|
||||
.user-copy-catalog-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
|
||||
.user-copy-filters { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
|
||||
.user-copy-search { min-width: 270px; height: 38px; padding: 0 11px; border: 1px solid var(--copy-line); border-radius: 9px; background: #fff; display: flex; align-items: center; gap: 8px; }
|
||||
.user-copy-search i { color: #8da0aa; font-size: 18px; }
|
||||
.user-copy-search input { width: 100%; border: 0; outline: 0; color: var(--copy-ink); background: transparent; font-size: 13px; }
|
||||
.user-copy-filters .form-select { min-width: 142px; }
|
||||
.user-copy-toast-filter { min-height: 38px; padding: 0 11px; border: 1px solid var(--copy-line); border-radius: 9px; display: inline-flex; align-items: center; gap: 7px; color: #526d7a; font-size: 12px; font-weight: 700; cursor: pointer; }
|
||||
.user-copy-list { display: grid; gap: 12px; }
|
||||
.user-copy-entry { padding: 18px; border: 1px solid var(--copy-line); border-radius: 12px; background: #fff; }
|
||||
.user-copy-entry-meta { margin-bottom: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.user-copy-entry-meta code { color: #1b5368; font-size: 12px; font-weight: 700; }
|
||||
.user-copy-entry-meta > span { padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 750; }
|
||||
.user-copy-kind { color: #687f8b; background: #edf2f4; }
|
||||
.user-copy-state.is-published { color: #168058; background: #e5f7ef; }
|
||||
.user-copy-state.is-draft { color: #8b6717; background: #fff4d7; }
|
||||
.user-copy-state.is-missing { color: #7b6b75; background: #f2edef; }
|
||||
.user-copy-state.is-hidden { color: #a04450; background: #fdecef; }
|
||||
.user-copy-state.is-invalid { color: #a04450; background: #fdecef; }
|
||||
.user-copy-critical { color: #aa3e49; background: #fde9ec; }
|
||||
.user-copy-entry-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 14px; }
|
||||
.user-copy-source,.user-copy-target { min-width: 0; }
|
||||
.user-copy-field-label { margin-bottom: 7px; color: var(--copy-muted); display: block; font-size: 11px; font-weight: 750; }
|
||||
.user-copy-source-text { min-height: 78px; padding: 12px 13px; border: 1px solid #e4ebee; border-radius: 9px; color: #3f5967; background: var(--copy-soft); white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.user-copy-target-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
||||
.user-copy-hide { margin-bottom: 7px; display: inline-flex; align-items: center; gap: 6px; color: #6f8490; font-size: 11px; }
|
||||
.user-copy-target textarea { min-height: 78px; resize: vertical; }
|
||||
.user-copy-parameters { margin: 7px 0 0; color: #8a6c25; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
|
||||
.user-copy-validation-error { margin: 7px 0 0; color: #a04450; font-size: 11px; line-height: 1.55; }
|
||||
.user-copy-entry-actions { margin-top: 13px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
|
||||
.user-copy-empty { margin: 0; padding: 48px 12px; color: var(--copy-muted); text-align: center; }
|
||||
.user-copy-preview,.user-copy-history { width: min(520px, 100vw); height: 100vh; padding: 22px; position: fixed; z-index: 1061; top: 0; right: 0; background: #fff; box-shadow: -18px 0 50px rgba(22, 49, 64, .16); overflow-y: auto; }
|
||||
.user-copy-preview[hidden],.user-copy-history[hidden],.user-copy-backdrop[hidden] { display: none; }
|
||||
.user-copy-preview > header,.user-copy-history > header { margin-bottom: 18px; padding-bottom: 15px; border-bottom: 1px solid var(--copy-line); display: flex; justify-content: space-between; align-items: center; gap: 16px; }
|
||||
.user-copy-preview header span,.user-copy-history header span { color: var(--copy-teal); font-size: 9px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
|
||||
.user-copy-preview h2,.user-copy-history h2 { margin: 4px 0 0; color: var(--copy-ink); font-size: 20px; }
|
||||
.user-copy-preview header button,.user-copy-history header button { width: 38px; height: 38px; border: 0; border-radius: 50%; color: #617986; background: transparent; font-size: 21px; }
|
||||
.user-copy-preview > p { color: var(--copy-muted); font-size: 12px; line-height: 1.7; }
|
||||
.user-copy-preview iframe { width: 100%; min-height: 360px; border: 1px solid var(--copy-line); border-radius: 11px; background: #f4f7f9; }
|
||||
.user-copy-backdrop { padding: 0; border: 0; position: fixed; z-index: 1060; inset: 0; background: rgba(14, 35, 47, .34); }
|
||||
body.user-copy-drawer-open { overflow: hidden; }
|
||||
.user-copy-history-empty { padding: 42px 12px; color: var(--copy-muted); text-align: center; }
|
||||
.user-copy-history-item { padding: 15px 0; border-bottom: 1px solid var(--copy-line); }
|
||||
.user-copy-history-item > div { display: flex; justify-content: space-between; gap: 12px; }
|
||||
.user-copy-history-item time { color: var(--copy-muted); font-size: 11px; }
|
||||
.user-copy-history-item p { margin: 10px 0; color: #4e6875; white-space: pre-wrap; }
|
||||
|
||||
@media (max-width: 991.98px) {
|
||||
.user-copy-toolbar { grid-template-columns: 1fr 1fr; }
|
||||
.user-copy-toolbar-note { grid-column: 1 / -1; }
|
||||
.user-copy-catalog-head { align-items: stretch; flex-direction: column; }
|
||||
.user-copy-filters { justify-content: flex-start; }
|
||||
.user-copy-entry-columns { grid-template-columns: 1fr; }
|
||||
}
|
||||
@media (max-width: 575.98px) {
|
||||
.user-copy-page-actions,.user-copy-page-actions .btn { width: 100%; }
|
||||
.user-copy-page-actions .admin-config-status { width: 100%; text-align: center; }
|
||||
.user-copy-toolbar { padding: 14px; grid-template-columns: 1fr; }
|
||||
.user-copy-toolbar-note { grid-column: auto; }
|
||||
.user-copy-coverage { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.user-copy-progress { grid-column: 1 / -1; }
|
||||
.user-copy-coverage > p { margin-top: 0; grid-column: 1 / -1; }
|
||||
.user-copy-filters,.user-copy-search,.user-copy-filters label,.user-copy-filters .form-select { width: 100%; min-width: 0; }
|
||||
.user-copy-entry { padding: 14px; }
|
||||
.user-copy-entry-actions > .btn { flex: 1 1 calc(50% - 8px); }
|
||||
.user-copy-preview,.user-copy-history { padding: 17px; }
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
{assign var=admin_title value='用户界面译文'}
|
||||
{assign var=admin_active value='user-copy'}
|
||||
{include file='admin/static_header.tpl'}
|
||||
<link rel="stylesheet" href="/cloud/admin-user-copy.css?v={$venix_asset_version}">
|
||||
<main class="user-copy-admin"
|
||||
data-user-copy-admin
|
||||
data-can-manage="{if $user_copy_can_manage|default:false}1{else}0{/if}">
|
||||
<div class="py-3 d-flex align-items-sm-center flex-sm-row flex-column gap-3">
|
||||
<div class="flex-grow-1">
|
||||
<p class="admin-eyebrow mb-1">Interface copy</p>
|
||||
<h1 class="fs-20 fw-semibold mb-1">用户界面译文</h1>
|
||||
<p class="text-muted mb-0">中文源文案由代码定义且只读;目标语言先保存草稿,发布后才会进入用户页面。</p>
|
||||
</div>
|
||||
<div class="user-copy-page-actions">
|
||||
<span class="admin-config-status{if $user_copy_error|default:''} is-error{/if}"
|
||||
id="user-copy-feedback" role="status" aria-live="polite">
|
||||
{if $user_copy_error|default:''}{$user_copy_error|escape}{elseif !$user_copy_can_manage|default:false}只读模式{elseif !$user_copy_workspace.write_ready|default:false}{$user_copy_workspace.write_block_reason|default:'译文存储未就绪'|escape}{else}管理目录已读取{/if}
|
||||
</span>
|
||||
{if !$user_copy_error|default:''}
|
||||
<button class="btn btn-light" id="user-copy-history-open" type="button"><i class="mdi mdi-history me-1" aria-hidden="true"></i>发布历史</button>
|
||||
<button class="btn btn-primary" id="user-copy-publish" type="button" {if !$user_copy_can_manage|default:false || !$user_copy_workspace.write_ready|default:false}disabled{/if}><i class="mdi mdi-publish me-1" aria-hidden="true"></i>发布目标语言</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if $user_copy_error|default:''}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>用户界面译文暂时不可用。</strong>
|
||||
<span>中文源文案仍由源码保护,现有用户页面不会因此改变。</span>
|
||||
</div>
|
||||
{else}
|
||||
<section class="user-copy-toolbar" aria-label="译文目录选择">
|
||||
<label for="user-copy-page"><span>页面</span><select class="form-select" id="user-copy-page"></select></label>
|
||||
<label for="user-copy-locale"><span>目标语言</span><select class="form-select" id="user-copy-locale"></select></label>
|
||||
<div class="user-copy-toolbar-note" role="note">
|
||||
<i class="mdi mdi-shield-check-outline" aria-hidden="true"></i>
|
||||
<span>预览只在隔离区域渲染纯文本,不会载入用户页面脚本,也不会触发实例、账单或账户操作。</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="user-copy-coverage" aria-label="译文覆盖率">
|
||||
<article><span>页面词条</span><strong id="user-copy-total">0</strong></article>
|
||||
<article><span>已发布</span><strong id="user-copy-published">0</strong></article>
|
||||
<article><span>仅有草稿</span><strong id="user-copy-draft">0</strong></article>
|
||||
<article><span>待翻译</span><strong id="user-copy-missing">0</strong></article>
|
||||
<div class="user-copy-progress" aria-label="目标语言覆盖率"><span id="user-copy-progress-bar"></span></div>
|
||||
<p><strong id="user-copy-percent">0%</strong><span>已发布覆盖率</span></p>
|
||||
</section>
|
||||
|
||||
<section class="card user-copy-catalog" aria-labelledby="user-copy-catalog-title">
|
||||
<div class="card-header user-copy-catalog-head">
|
||||
<div><h2 class="h5 card-title mb-1" id="user-copy-catalog-title">词条目录</h2><p class="text-muted fs-13 mb-0">按稳定键管理译文;修改中文内容需要回到源码 Manifest。</p></div>
|
||||
<div class="user-copy-filters">
|
||||
<label class="user-copy-search" for="user-copy-search"><i class="mdi mdi-magnify" aria-hidden="true"></i><input id="user-copy-search" type="search" placeholder="搜索键名或中文文案" autocomplete="off"></label>
|
||||
<label for="user-copy-state"><span class="visually-hidden">翻译状态</span><select class="form-select" id="user-copy-state"><option value="">全部状态</option><option value="published">已发布</option><option value="draft">仅有草稿</option><option value="untranslated">待翻译</option><option value="hidden">已隐藏</option></select></label>
|
||||
<label class="user-copy-toast-filter" for="user-copy-toast-only"><input id="user-copy-toast-only" type="checkbox"><span>仅 Toast</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="user-copy-list" id="user-copy-list" aria-live="polite"></div>
|
||||
<p class="user-copy-empty" id="user-copy-empty" hidden>没有符合当前筛选条件的词条。</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<aside class="user-copy-preview" id="user-copy-preview" aria-labelledby="user-copy-preview-title" hidden>
|
||||
<header><div><span>Safe preview</span><h2 id="user-copy-preview-title">安全预览</h2></div><button type="button" id="user-copy-preview-close" aria-label="关闭预览"><i class="mdi mdi-close" aria-hidden="true"></i></button></header>
|
||||
<p>预览使用隔离 iframe 和转义后的纯文本,不发送任何业务请求。</p>
|
||||
<iframe id="user-copy-preview-frame" title="用户界面译文安全预览" sandbox=""></iframe>
|
||||
</aside>
|
||||
|
||||
<aside class="user-copy-history" id="user-copy-history" aria-labelledby="user-copy-history-title" hidden>
|
||||
<header><div><span>Revision history</span><h2 id="user-copy-history-title">发布历史</h2></div><button type="button" id="user-copy-history-close" aria-label="关闭发布历史"><i class="mdi mdi-close" aria-hidden="true"></i></button></header>
|
||||
<div id="user-copy-history-list"></div>
|
||||
</aside>
|
||||
<button class="user-copy-backdrop" id="user-copy-backdrop" type="button" aria-label="关闭侧栏" hidden></button>
|
||||
|
||||
<script id="user-copy-bootstrap" type="application/json">{$user_copy_bootstrap_json nofilter}</script>
|
||||
<script src="/cloud/admin-user-copy.js?v={$venix_asset_version}" defer></script>
|
||||
{/if}
|
||||
</main>
|
||||
{include file='admin/static_footer.tpl'}
|
||||
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$read = static function (string $path) use ($root): string {
|
||||
$contents = file_get_contents($root . '/' . $path);
|
||||
if (!is_string($contents)) {
|
||||
throw new RuntimeException('Cannot read ' . $path);
|
||||
}
|
||||
return $contents;
|
||||
};
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$routes = $read('config/routes.php');
|
||||
$controller = $read('app/Controllers/Admin/UserCopyController.php');
|
||||
$service = $read('app/Services/UserCopy/UserCopyAdminService.php');
|
||||
$template = $read('resources/views/venix/admin/user_copy.tpl');
|
||||
$sidebar = $read('resources/views/venix/admin/static_header.tpl');
|
||||
$javascript = $read('public/cloud/admin-user-copy.js');
|
||||
$css = $read('public/cloud/admin-user-copy.css');
|
||||
$manifest = $read('resources/user-copy/manifest.php');
|
||||
|
||||
$assert(str_contains($routes,
|
||||
"'/user-copy',\n 'App\\Controllers\\Admin\\UserCopyController:index'"),
|
||||
'Administrator user-copy page route is missing.');
|
||||
foreach (['index', 'entries', 'history', 'draft', 'publish', 'rollback'] as $action) {
|
||||
$pattern = "#UserCopyController:{$action}'\)\s*->add\(new SuperAdmin\(\)\)#";
|
||||
$assert(preg_match($pattern, $routes) === 1,
|
||||
'User-copy route is not protected by SuperAdmin: ' . $action);
|
||||
}
|
||||
|
||||
$assert(str_contains($controller, 'UserCopyAdminService::fromApplication()')
|
||||
&& str_contains($controller, 'AdminPermission::isSuperAdmin()')
|
||||
&& str_contains($controller, "'private, no-store'"),
|
||||
'Controller lost its service seam, write guard or private caching contract.');
|
||||
$assert(!str_contains($controller, 'UserCopyPublicationStore')
|
||||
&& !str_contains($controller, 'Capsule::')
|
||||
&& !str_contains($controller, 'DB::'),
|
||||
'Administrator controller bypasses the UserCopyAdminService seam.');
|
||||
|
||||
foreach (['workspace', 'history', 'saveDraft', 'publish', 'rollback'] as $method) {
|
||||
$assert(str_contains($service, 'function ' . $method . '('),
|
||||
'UserCopyAdminService contract is missing: ' . $method);
|
||||
}
|
||||
$assert(!str_contains($manifest, "'translations' =>")
|
||||
&& !str_contains($manifest, "'target' =>")
|
||||
&& str_contains($manifest, 'target-locale translation are maintained by')
|
||||
&& str_contains($manifest, 'must never be committed to this source manifest'),
|
||||
'Target-locale translations were stored in the source manifest.');
|
||||
|
||||
$assert(str_contains($sidebar, 'href="/admin/user-copy"')
|
||||
&& str_contains($sidebar, '用户界面译文'),
|
||||
'Administrator navigation does not expose user-copy management.');
|
||||
foreach ([
|
||||
'id="user-copy-page"',
|
||||
'id="user-copy-locale"',
|
||||
'id="user-copy-progress-bar"',
|
||||
'发布历史',
|
||||
'id="user-copy-toast-only"',
|
||||
'sandbox=""',
|
||||
] as $contract) {
|
||||
$assert(str_contains($template, $contract),
|
||||
'Administrator user-copy template is missing: ' . $contract);
|
||||
}
|
||||
$assert(str_contains($template . $javascript, '中文源文案(只读)')
|
||||
&& str_contains($template . $javascript, '目标语言草稿'),
|
||||
'Source copy is not read-only or target drafts are missing.');
|
||||
$assert(str_contains($template, 'data-can-manage=')
|
||||
&& str_contains($template, 'write_block_reason'),
|
||||
'The template does not expose read-only or unavailable-write state.');
|
||||
|
||||
$assert(str_contains($javascript, 'function previewEntry(')
|
||||
&& str_contains($javascript, 'previewFrame.srcdoc = previewDocument(')
|
||||
&& str_contains($javascript, "entry.kind === 'toast_title'")
|
||||
&& str_contains($javascript, "entry.kind === 'toast_body'"),
|
||||
'Local safe preview or Toast preview/filtering is missing.');
|
||||
$previewStart = strpos($javascript, 'function previewEntry(');
|
||||
$previewEnd = strpos($javascript, 'function closeDrawers(', $previewStart);
|
||||
$previewBody = substr($javascript, $previewStart, $previewEnd - $previewStart);
|
||||
$assert(!str_contains($previewBody, 'transport.')
|
||||
&& !str_contains($previewBody, 'fetch('),
|
||||
'Safe preview performs a network operation.');
|
||||
foreach (['/api/v1/vms', '/api/v1/orders', '/api/v1/invoices'] as $businessPath) {
|
||||
$assert(!str_contains($javascript, $businessPath),
|
||||
'Translation management references a business mutation endpoint.');
|
||||
}
|
||||
$assert(str_contains($javascript, "'/admin/user-copy/entries/'")
|
||||
&& str_contains($javascript, "'/admin/user-copy/publications'")
|
||||
&& str_contains($javascript, "'/admin/user-copy/publications/'")
|
||||
&& str_contains($javascript, 'mutationMayHaveApplied'),
|
||||
'Draft, publish, rollback or uncertain mutation handling is incomplete.');
|
||||
$assert(str_contains($javascript, 'validation_state')
|
||||
&& str_contains($javascript, 'user-copy-validation-error')
|
||||
&& str_contains($javascript, '存在无效或过期草稿'),
|
||||
'Invalid or stale drafts are not visible before locale publication.');
|
||||
$assert(str_contains($css, '@media (max-width: 575.98px)')
|
||||
&& str_contains($css, '.user-copy-entry-columns'),
|
||||
'Administrator user-copy page lacks responsive layout contracts.');
|
||||
|
||||
echo "User copy administrator UI contracts passed.\n";
|
||||
Loading…
Reference in New Issue