Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
working-directory: backend
env:
ISLET_CDN_TEST_DSN: root:islet-ci-database@tcp(127.0.0.1:3306)/islet_cdn_jobs_test?charset=utf8mb4&parseTime=true&loc=Local
- run: npm ci && npm run type-check && npm run build
- run: npm ci && npm test && npm run type-check && npm run build
working-directory: frontend/admin
- run: docker compose --env-file deploy/.env.example -f deploy/docker-compose.yml config --quiet
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Islet/
2. **状态同步**:每次开始和结束工作,更新 `workspace/status.md`
3. **workspace 保洁**:临时文件用完即删,不留垃圾文件
4. **不允许边写边设计**:不清楚的需求先在 workspace 草稿,确认后才写入 Docs
5. **问题交付**:严格遵循 Issue → 分支 → 验收 → PR → Release。先登记问题再创建对应分支,完成测试与实际页面验收后才创建 PR;发布版本关联合并后的源码、验收记录及部署恢复信息。

## 开发纪律

Expand Down
2 changes: 2 additions & 0 deletions Docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
| 文档 | 内容 |
|------|------|
| [product-design.md](product-design.md) | 产品目标、信息架构、交互规范与验收计划 |
| [admin-editing.md](admin-editing.md) | 分组、存储策略编辑流程与弹层验收要求 |
| [acceptance-admin-editing-2026-11-01.md](acceptance-admin-editing-2026-11-01.md) | 管理端编辑、草稿与配置保存验收 |
| [image-workspace.md](image-workspace.md) | 上传取链、相册封面与客户端连接交互 |
| [acceptance-image-workspace-2026-10-31.md](acceptance-image-workspace-2026-10-31.md) | 图片工作台交互、布局及上线验收 |
| [acceptance-orientation-2026-11-01.md](acceptance-orientation-2026-11-01.md) | 照片方向、缩略图重建及上线验收 |
Expand Down
30 changes: 30 additions & 0 deletions Docs/acceptance-admin-editing-2026-11-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 管理端编辑验收

日期:2026-11-01。关联 Issue:[#1](https://github.com/five-plus-one/Islet/issues/1)、[#2](https://github.com/five-plus-one/Islet/issues/2)。

## 已验证行为

| 范围 | 结果 |
| --- | --- |
| 默认分组编辑 | 正式站点复现历史空存储列表异常;候选支持直接打开编辑、刷新、保存与重新读取 |
| 分组限制 | 新建指定本地存储的分组,容量与单张上限为 0、格式留空,保存刷新后指定存储仍保留;空指定范围阻止保存 |
| 输入与失败 | 负数、无效 CDN 域名、重复名称有错误反馈;保存失败保留草稿;分区切换保留输入 |
| 草稿保护 | 取消和侧栏导航显示放弃提示,继续编辑恢复当前草稿,放弃后进入目标页面 |
| 存储配置 | 本地存储创建后回读;对象存储更名保存时密钥留空,随后真实连接测试成功 |
| 布局与键盘 | 390、600、900 和默认 1384 像素窗口;深浅主题;分区方向键、Esc 关闭与焦点路径;窄屏无页面横向溢出,保存取消可达 |
| 弹层审查 | 用户创建 3 字段、相册 2 字段、密钥 2 字段、移动图片 1 字段;图片详情采用全高侧栏,审核确认与 PicList 宽布局可操作 |
| 异常路径 | 不存在的分组提供返回列表;发布候选浏览器没有脚本错误 |

写入验收使用本机隔离应用与数据库,以及独立 S3 测试存储。正式数据不用于写入测试。页面使用已发布的共享表单组件,宿主仅适配内容宽度、滚动容器与业务逻辑。

## 自动验证

- Go 构建与全部测试通过。
- 前端类型检查、正式构建与空数组兼容回归测试通过。
- 完整候选镜像运行 5 组接口验收,全部通过:账户与分组权限、图片编辑与回收、上传密钥与配额、S3 管理访问、图片审核与原图保留。其中包含分组创建与修改重名提示以及失败后原限制保留断言。
- Docker Compose 配置校验通过。
- 浏览器验收使用浏览器工具完成。

## 发布恢复

候选镜像:`islet:production-20261101.04`。恢复镜像:`islet:production-20261101.03`。本次保持数据库结构兼容;发布只切换 Islet 服务。上线前保存原配置及备份,比较账户、图片、分组、存储配置、环境、挂载、网络和其他业务容器,切换后回读正式编辑入口。
32 changes: 32 additions & 0 deletions Docs/admin-editing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 管理端编辑流程

关联问题:[#1](https://github.com/five-plus-one/Islet/issues/1)、[#2](https://github.com/five-plus-one/Islet/issues/2)。

## 页面与表单

用户分组和存储策略使用独立编辑页,支持直接访问与刷新。列表保留管理入口;编辑页明确显示对象名称、返回入口和保存、取消操作。

- 分组:基本信息、容量与上传、可用存储三个分区。
- 存储策略:基本信息、存储连接、图片访问三个分区。本地存储只显示适用选项。
- 复用已发布共享库的 ManagementForm、WorkspaceSection、表单网格、Checkbox、Button 等组件。业务页面处理权限、验证、请求、草稿和保存。
- 分区切换保留草稿。保存时验证全部分区,错误时定位对应分区并保留输入。
- 编辑期间离开页面提示保存状态,可继续编辑或放弃修改。保存中防止重复提交和导航。
- 编辑既有存储时密钥留空表示保留,页面不回显密钥,不在浏览器持久保存草稿。
- 名称重复时显示可理解的重名提示,保存失败保留草稿;服务端分组错误不向页面返回数据库诊断。

## 兼容与含义

历史分组的空存储列表与空格式列表可能返回 null。前端请求边界将 null 归一化为空数组,保留有效限制项。空存储列表代表全部存储,空格式列表代表全部受支持图片格式;界面明确解释这一含义,选择指定存储时必须至少选择一项。容量、单张上限和每小时上传数量为 0 时表示不限,不能显示为 0 B。数值保存前验证非负、有限且字节数和数量为安全整数。

## 弹层使用

仅保留删除确认、创建本地用户、创建相册、上传密钥、移动图片等短任务弹窗。图片详情保留带预览的侧栏;客户端连接使用现有宽布局。逐项检查内容量、焦点、关闭行为和操作位置,避免页面与浮层同时出现无意义的多层滚动。

## 验收

1. 默认分组与自定义分组均可打开、刷新、编辑、保存并重新读取;历史 null 数组不导致异常。
2. 分组限制、存储选择与已有密钥保持正确含义;取消、切换分区和失败重试保留预期草稿。
3. 本地与对象存储完整配置均能编辑,加载失败和目标不存在可恢复。
4. 桌面、分屏、手机连续缩放,深浅色与键盘操作可用;保存取消可达,弹层和提示不遮挡内容。
5. 正式站点仅执行读取、打开与取消;写入测试在隔离验收环境进行。
6. 验收完成后创建 PR,发布版本关联测试结果、线上检查与恢复版本。
19 changes: 16 additions & 3 deletions backend/internal/router/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ func policyError(c *gin.Context, err error) {
}

// registerGroupRoutes 用户分组管理(admin+)。
func groupError(c *gin.Context, err error) {
switch {
case errors.Is(err, service.ErrGroupNotFound):
response.NotFound(c, err.Error())
case errors.Is(err, service.ErrGroupNameInvalid):
response.BadRequest(c, err.Error())
case errors.Is(err, service.ErrGroupNameExists), errors.Is(err, service.ErrGroupBuiltIn), errors.Is(err, service.ErrGroupInUse):
response.Error(c, http.StatusConflict, 4009, err.Error())
default:
response.ServerError(c, "分组操作暂未完成,请稍后重试")
}
}

func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) {
admin.GET("/user-groups", func(c *gin.Context) {
groups, err := deps.Groups.List()
Expand Down Expand Up @@ -151,7 +164,7 @@ func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) {
}
group, err := deps.Groups.Create(in)
if err != nil {
response.Error(c, http.StatusConflict, 4009, err.Error())
groupError(c, err)
return
}
deps.Audit.Record(&user.ID, "group.create", "user_group", strconv.FormatUint(group.ID, 10), nil, clientIP(c))
Expand All @@ -167,7 +180,7 @@ func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) {
}
group, err := deps.Groups.Update(id, in)
if err != nil {
response.Error(c, http.StatusConflict, 4009, err.Error())
groupError(c, err)
return
}
deps.Audit.Record(&user.ID, "group.update", "user_group", c.Param("id"), nil, clientIP(c))
Expand All @@ -177,7 +190,7 @@ func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) {
user, _ := middleware.CurrentUser(c)
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
if err := deps.Groups.Delete(id); err != nil {
response.Error(c, http.StatusConflict, 4009, err.Error())
groupError(c, err)
return
}
deps.Audit.Record(&user.ID, "group.delete", "user_group", c.Param("id"), nil, clientIP(c))
Expand Down
29 changes: 18 additions & 11 deletions backend/internal/service/group_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (
"errors"
"strings"

"github.com/go-sql-driver/mysql"
"gorm.io/gorm"

"islet/backend/internal/model"
)

var (
ErrGroupNotFound = errors.New("用户分组不存在")
ErrGroupNameExists = errors.New("分组名称已存在")
ErrGroupBuiltIn = errors.New("内置分组不可删除")
ErrGroupInUse = errors.New("分组仍有用户,无法删除")
ErrGroupNotFound = errors.New("用户分组不存在")
ErrGroupNameExists = errors.New("分组名称已存在")
ErrGroupBuiltIn = errors.New("内置分组不可删除")
ErrGroupInUse = errors.New("分组仍有用户,无法删除")
ErrGroupNameInvalid = errors.New("分组名称不能为空,最多 64 字")
)

// GroupService 用户分组管理。
Expand Down Expand Up @@ -68,7 +70,7 @@ func (s *GroupService) Get(id uint64) (model.UserGroup, error) {
func (s *GroupService) Create(in GroupInput) (model.UserGroup, error) {
name := strings.TrimSpace(in.Name)
if name == "" || len([]rune(name)) > 64 {
return model.UserGroup{}, errors.New("分组名称不能为空,最多 64 字")
return model.UserGroup{}, ErrGroupNameInvalid
}
group := model.UserGroup{
Name: name, Description: strings.TrimSpace(in.Description),
Expand All @@ -81,10 +83,7 @@ func (s *GroupService) Create(in GroupInput) (model.UserGroup, error) {
group.Status = model.StatusDisabled
}
if err := s.db.Create(&group).Error; err != nil {
if errors.Is(err, gorm.ErrDuplicatedKey) {
return model.UserGroup{}, ErrGroupNameExists
}
return model.UserGroup{}, err
return model.UserGroup{}, groupWriteError(err)
}
return group, nil
}
Expand All @@ -96,7 +95,7 @@ func (s *GroupService) Update(id uint64, in GroupInput) (model.UserGroup, error)
}
name := strings.TrimSpace(in.Name)
if name == "" || len([]rune(name)) > 64 {
return model.UserGroup{}, errors.New("分组名称不能为空,最多 64 字")
return model.UserGroup{}, ErrGroupNameInvalid
}
updates := map[string]any{
"name": name, "description": strings.TrimSpace(in.Description),
Expand All @@ -115,11 +114,19 @@ func (s *GroupService) Update(id uint64, in GroupInput) (model.UserGroup, error)
updates["status"] = in.Status
}
if err := s.db.Model(&group).Updates(updates).Error; err != nil {
return model.UserGroup{}, err
return model.UserGroup{}, groupWriteError(err)
}
return s.Get(id)
}

func groupWriteError(err error) error {
var duplicate *mysql.MySQLError
if errors.Is(err, gorm.ErrDuplicatedKey) || (errors.As(err, &duplicate) && duplicate.Number == 1062) {
return ErrGroupNameExists
}
return err
}

func (s *GroupService) Delete(id uint64) error {
var group model.UserGroup
if err := s.db.First(&group, id).Error; err != nil {
Expand Down
19 changes: 19 additions & 0 deletions frontend/admin/e2e/acceptance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,25 @@ test.describe.serial("Account and storage API acceptance", () => {
policy_ids: [1],
status: "active",
});
const existingName = (
await call(owner, "/api/admin/user-groups")
).items.find((item: any) => item.id === 2).name;
for (const [method, path] of [
["POST", "/api/admin/user-groups"],
["PATCH", `/api/admin/user-groups/${group.ID}`],
]) {
const duplicate = await owner.fetch(path, {
method,
data: { name: existingName },
});
expect(duplicate.status()).toBe(409);
expect((await duplicate.json()).message).toBe("分组名称已存在");
}
const retainedGroup = (
await call(owner, "/api/admin/user-groups")
).items.find((item: any) => item.id === group.ID);
expect(retainedGroup.policy_ids).toEqual([1]);
expect(retainedGroup.allowed_mimes).toEqual(["image/png"]);
const user = await call(owner, "/api/admin/users", "POST", {
username: "member-" + suffix,
password: credentials.password,
Expand Down
4 changes: 2 additions & 2 deletions frontend/admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/admin/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "islet-admin",
"version": "0.2.0",
"version": "0.2.1",
"private": true,
"type": "module",
"scripts": {
"test": "node --experimental-strip-types --test tests/*.test.ts",
"test:e2e": "playwright test",
"dev": "vite --host 127.0.0.1",
"type-check": "tsc --noEmit",
Expand Down
17 changes: 16 additions & 1 deletion frontend/admin/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,22 @@ export const api = {
{ method: "POST" },
),

groups: () => request<{ items: GroupView[] }>("/api/admin/user-groups"),
groups: async () => {
const result = await request<{
items: (Omit<GroupView, "policy_ids" | "allowed_mimes"> & {
policy_ids: number[] | null;
allowed_mimes: string[] | null;
})[];
}>("/api/admin/user-groups");
return {
...result,
items: result.items.map((group) => ({
...group,
policy_ids: group.policy_ids ?? [],
allowed_mimes: group.allowed_mimes ?? [],
})),
};
},
saveGroup: (input: Partial<GroupView> & { name: string }) =>
input.id
? request<GroupView>(`/api/admin/user-groups/${input.id}`, {
Expand Down
43 changes: 40 additions & 3 deletions frontend/admin/src/react/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
import { uploads } from "./uploads";
import { Gallery, UploadPage, Albums, Tokens, Profile } from "./library";
import { AdminPage, Setup } from "./management";
import { GroupEditor, PolicyEditor } from "./admin-editors";
const navigation = [
["/images", "图片库", Images],
["/upload", "上传图片", Upload],
Expand Down Expand Up @@ -372,6 +373,10 @@ function Workspace({ theme }: { theme: React.ReactNode }) {
</main>
);
const admin = me.user.role !== "user";
const activePath =
navigation.find(
([path]) => loc.pathname === path || loc.pathname.startsWith(path + "/"),
)?.[0] || loc.pathname;
const items = navigation
.filter((_, i) => admin || i < 6)
.map(([id, label, Icon]) => ({ id, label, icon: <Icon size={19} /> }));
Expand All @@ -386,7 +391,7 @@ function Workspace({ theme }: { theme: React.ReactNode }) {
<ProductNavigation
variant="sidebar"
items={items.slice(0, 6)}
value={loc.pathname}
value={activePath}
onChange={(path) => {
navigate(path);
setMobile(false);
Expand All @@ -399,7 +404,7 @@ function Workspace({ theme }: { theme: React.ReactNode }) {
variant="sidebar"
label="管理导航"
items={items.slice(6)}
value={loc.pathname}
value={activePath}
onChange={(path) => {
navigate(path);
setMobile(false);
Expand Down Expand Up @@ -438,7 +443,7 @@ function Workspace({ theme }: { theme: React.ReactNode }) {
<Menu size={20} />
</Button>
<span>
{items.find((x) => x.id === loc.pathname)?.label || "图片工作台"}
{items.find((x) => x.id === activePath)?.label || "图片工作台"}
</span>
<div>
{theme}
Expand Down Expand Up @@ -481,6 +486,38 @@ function Workspace({ theme }: { theme: React.ReactNode }) {
<Route path="/albums" element={<Albums />} />
<Route path="/tokens" element={<Tokens />} />
<Route path="/profile" element={<Profile />} />
<Route
path="/groups/new"
element={
admin ? (
<GroupEditor key="new-group" />
) : (
<Navigate to="/images" replace />
)
}
/>
<Route
path="/groups/:id/edit"
element={
admin ? <GroupEditor /> : <Navigate to="/images" replace />
}
/>
<Route
path="/policies/new"
element={
admin ? (
<PolicyEditor key="new-policy" />
) : (
<Navigate to="/images" replace />
)
}
/>
<Route
path="/policies/:id/edit"
element={
admin ? <PolicyEditor /> : <Navigate to="/images" replace />
}
/>
<Route
path="/moderation"
element={
Expand Down
Loading
Loading