From 1d6d600952453ef2e36be427d3435cf8967339af Mon Sep 17 00:00:00 2001
From: dongjf <1+dongjf@noreply.git.tutudog.com>
Date: Mon, 30 Nov 2026 18:46:09 +0800
Subject: [PATCH] =?UTF-8?q?fix(admin):=20=E7=BB=9F=E4=B8=80=E4=B8=AD?=
=?UTF-8?q?=E6=96=87=E7=99=BB=E5=BD=95=E5=92=8C=E9=BB=98=E8=AE=A4=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E5=91=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apps/admin/README.md | 2 +-
apps/admin/index.html | 2 +-
apps/admin/src/App.vue | 6 ++++--
deploy/admin-preview/README.md | 9 +++++----
deploy/admin-preview/prepare-secrets.py | 27 ++++++++++++++++---------
deploy/admin-preview/web.yaml | 2 +-
6 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/apps/admin/README.md b/apps/admin/README.md
index a7ddf02..8b87fb6 100644
--- a/apps/admin/README.md
+++ b/apps/admin/README.md
@@ -1,6 +1,6 @@
# 见物管理后台
-用平台管理员账号登录。空间列表每页 25 条,可以按名称查找,也可输入完整空间 ID 直达详情。列表只返回名称和 ID,物品和照片数量打开详情时读取。删除需要再次输入空间 ID。服务端记录操作人和时间,并异步清理原图和缩略图。
+用平台管理员账号登录。本机预览的默认账号是 `dongjf`,登录页和管理页面使用简体中文。空间列表每页 25 条,可以按名称查找,也可输入完整空间 ID 直达详情。列表只返回名称和 ID,物品和照片数量打开详情时读取。删除需要再次输入空间 ID。服务端记录操作人和时间,并异步清理原图和缩略图。
```sh
npm ci
diff --git a/apps/admin/index.html b/apps/admin/index.html
index 35cc9e4..7491b85 100644
--- a/apps/admin/index.html
+++ b/apps/admin/index.html
@@ -3,7 +3,7 @@
- 见物 · 空间管理
+ 见物 · 管理后台
diff --git a/apps/admin/src/App.vue b/apps/admin/src/App.vue
index 6340d3e..af60f15 100644
--- a/apps/admin/src/App.vue
+++ b/apps/admin/src/App.vue
@@ -16,6 +16,7 @@ const spacesApi = '/api/admin/households'
const auditApi = '/api/admin/space-deletions'
const cleanupApi = '/api/admin/media-cleanup'
const identityUrl = import.meta.env.VITE_OIDC_URL || 'https://api-atlas.tutudog.com/auth'
+const loginLocale = 'zh-CN'
const keycloak = new Keycloak({
url: new URL(identityUrl, window.location.origin).href,
@@ -23,6 +24,7 @@ const keycloak = new Keycloak({
clientId: 'atlas-admin',
})
const logout = () => keycloak.logout({ redirectUri: window.location.origin + '/' })
+const login = () => keycloak.login({ locale: loginLocale })
const initialized = ref(false)
const authenticated = ref(false)
const authorized = ref(false)
@@ -48,7 +50,7 @@ const auditDate = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'medium', timeSt
onMounted(async () => {
try {
- await keycloak.init({ onLoad: 'login-required', pkceMethod: 'S256', checkLoginIframe: false })
+ await keycloak.init({ onLoad: 'login-required', pkceMethod: 'S256', checkLoginIframe: false, locale: loginLocale })
authenticated.value = keycloak.authenticated === true
const roles: unknown = keycloak.tokenParsed?.atlas_roles
authorized.value = authenticated.value && Array.isArray(roles) && roles.includes('atlas-space-admin')
@@ -218,7 +220,7 @@ async function deleteSpace() {
见物 管理后台
退出登录
- 重新登录
+ 重新登录
diff --git a/deploy/admin-preview/README.md b/deploy/admin-preview/README.md
index 02f6800..2017ed2 100644
--- a/deploy/admin-preview/README.md
+++ b/deploy/admin-preview/README.md
@@ -24,16 +24,17 @@ kind_cluster=atlas-dev
context="kind-$kind_cluster"
namespace=item-atlas-admin-preview
secret_dir=/path/on/ssd/item-atlas-admin-preview
+admin_password_file=/path/on/ssd/managed-preview-admin-password
mvn -B -ntp -f backend/pom.xml -pl inventory-service -am package
docker build -t item-atlas-inventory-service:admin-preview-0.1.3 backend/inventory-service
docker build --build-arg VITE_OIDC_URL=/auth \
--build-arg VITE_OIDC_REALM=item-atlas-admin-preview \
- -t item-atlas-admin:admin-preview-0.1.3 apps/admin
+ -t item-atlas-admin:admin-preview-0.1.4 apps/admin
kind load docker-image --name "$kind_cluster" \
- item-atlas-inventory-service:admin-preview-0.1.3 item-atlas-admin:admin-preview-0.1.3
+ item-atlas-inventory-service:admin-preview-0.1.3 item-atlas-admin:admin-preview-0.1.4
-python3 deploy/admin-preview/prepare-secrets.py "$secret_dir"
+python3 deploy/admin-preview/prepare-secrets.py "$secret_dir" --admin-password-file "$admin_password_file"
kubectl --context "$context" create namespace "$namespace"
for component in postgres keycloak inventory; do
kubectl --context "$context" -n "$namespace" create secret generic "atlas-admin-$component" \
@@ -48,7 +49,7 @@ kubectl --context "$context" -n "$namespace" get pods,pvc
kubectl --context "$context" -n "$namespace" port-forward --address 127.0.0.1 svc/item-atlas-admin 18482:8080
```
-首次部署生成两位预览用户 `preview-admin`、`preview-viewer`,密码在私有目录的 `credentials.json`。保留该目录。已有预览更新镜像后重新执行 `apply -k`,无需重新建 Secret。Keycloak 仅在首次创建 realm 时从文件导入用户。
+首次部署使用 `dongjf` 作为后台管理员,密码由受控文件提供。生成的 `preview-viewer` 供权限验收,凭据位于私有目录的 `credentials.json`。后台和 Keycloak 登录统一使用简体中文。首次导入后,已有 realm 的语言、账号和角色应通过 Keycloak 管理接口更新并复验。重新生成启动文件用于新环境初始化。 [Keycloak 语言配置](https://www.keycloak.org/docs/latest/server_admin/#_user-locale-selection) · [Keycloak 管理接口](https://www.keycloak.org/docs-api/latest/rest-api/)
## 验收和排错
diff --git a/deploy/admin-preview/prepare-secrets.py b/deploy/admin-preview/prepare-secrets.py
index 9f10f95..92fb5ac 100644
--- a/deploy/admin-preview/prepare-secrets.py
+++ b/deploy/admin-preview/prepare-secrets.py
@@ -6,7 +6,7 @@ import secrets
from pathlib import Path
-def prepare(directory):
+def prepare(directory, admin_password_file):
directory.mkdir(mode=0o700, parents=True, exist_ok=True)
if directory.stat().st_mode & 0o077:
raise SystemExit('Use a private directory (chmod 700) outside the Git worktree.')
@@ -15,11 +15,14 @@ def prepare(directory):
if not vault.exists():
values = {
name: secrets.token_urlsafe(24)
- for name in ('postgres', 'inventory', 'identity', 'preview-admin', 'preview-viewer')
+ for name in ('postgres', 'inventory', 'identity', 'preview-viewer')
}
with vault.open('x') as stream:
json.dump(values, stream, indent=2)
values = json.loads(vault.read_text())
+ admin_password = admin_password_file.read_text().rstrip('\r\n')
+ if not admin_password or '\r' in admin_password or '\n' in admin_password:
+ raise SystemExit('The administrator password file must contain exactly one non-empty line.')
write_env(directory / 'postgres.env', {
'POSTGRES_PASSWORD': values['postgres'],
@@ -28,14 +31,14 @@ def prepare(directory):
})
write_env(directory / 'keycloak.env', {'KC_DB_PASSWORD': values['identity']})
write_env(directory / 'inventory.env', {'ATLAS_DB_PASSWORD': values['inventory']})
- (directory / 'item-atlas-admin-preview-realm.json').write_text(json.dumps(realm(values)))
+ (directory / 'item-atlas-admin-preview-realm.json').write_text(json.dumps(realm(values, admin_password)))
def write_env(path, values):
path.write_text(''.join(f'{name}={value}\n' for name, value in values.items()))
-def realm(values):
+def realm(values, admin_password):
origin = 'http://127.0.0.1:18482'
return {
'realm': 'item-atlas-admin-preview',
@@ -43,7 +46,11 @@ def realm(values):
'enabled': True,
'sslRequired': 'none',
'registrationAllowed': False,
+ 'loginWithEmailAllowed': False,
'bruteForceProtected': True,
+ 'internationalizationEnabled': True,
+ 'supportedLocales': ['zh-CN'],
+ 'defaultLocale': 'zh-CN',
'roles': {'realm': [{'name': 'atlas-space-admin'}]},
'clients': [{
'clientId': 'atlas-admin',
@@ -93,13 +100,13 @@ def realm(values):
'realmRoles': roles,
'credentials': [{
'type': 'password',
- 'value': values[username],
+ 'value': password,
'temporary': False,
}],
}
- for username, roles in (
- ('preview-admin', ['atlas-space-admin']),
- ('preview-viewer', []),
+ for username, password, roles in (
+ ('dongjf', admin_password, ['atlas-space-admin']),
+ ('preview-viewer', values['preview-viewer'], []),
)
],
}
@@ -108,5 +115,7 @@ def realm(values):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('directory', type=Path, help='Private directory outside the Git worktree')
+ parser.add_argument('--admin-password-file', required=True, type=Path, help='File with the dongjf administrator password')
os.umask(0o077)
- prepare(parser.parse_args().directory)
+ args = parser.parse_args()
+ prepare(args.directory, args.admin_password_file)
diff --git a/deploy/admin-preview/web.yaml b/deploy/admin-preview/web.yaml
index 11673aa..72802af 100644
--- a/deploy/admin-preview/web.yaml
+++ b/deploy/admin-preview/web.yaml
@@ -42,7 +42,7 @@ spec:
automountServiceAccountToken: false
containers:
- name: nginx
- image: item-atlas-admin:admin-preview-0.1.3
+ image: item-atlas-admin:admin-preview-0.1.4
imagePullPolicy: Never
env:
- {name: ATLAS_GATEWAY_URL, value: 'http://atlas-admin-gateway:8080'}