feat: 支持编辑运维项目显示名称
- 管理员可持久化修改项目名称 - 迁移三个舌吻项目的旧默认名称
This commit is contained in:
@@ -179,3 +179,5 @@ Jenkins 自动同步器每分钟顺序检查各纳管 job 的最新 1 次构建
|
||||
### 发布历史的后续成功关联
|
||||
|
||||
`src/deploy-runs/deploy-run-recovery.ts` 根据同项目、同环境和完成时间关联历史失败与后续成功。读取接口返回 `supersededBy` / `recoveredFrom`,保留原状态;回滚、跨环境和时间不明确的记录不推断恢复。成功通知及 outbox 重试内容包含历史失败摘要;不能修改已经送出的旧群消息。关联查询失败不影响原发布状态推进。本地测试不会发送真实通知。
|
||||
|
||||
超级管理员可通过 `PATCH /projects/:key/name` 更新项目显示名称。项目键继续用于权限和发布记录。
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
UPDATE `projects` SET `name` = '舌吻 · API', `updatedAt` = CURRENT_TIMESTAMP(3) WHERE `key` = 'access-manage' AND `name` = 'access-manage';
|
||||
UPDATE `projects` SET `name` = '舌吻 · 运营后台', `updatedAt` = CURRENT_TIMESTAMP(3) WHERE `key` = 'role-admin' AND `name` = 'role-admin';
|
||||
UPDATE `projects` SET `name` = '舌吻 · H5', `updatedAt` = CURRENT_TIMESTAMP(3) WHERE `key` = 'role-user' AND `name` = 'role-user';
|
||||
@@ -36,7 +36,6 @@ async function main() {
|
||||
},
|
||||
},
|
||||
update: {
|
||||
name: project.name,
|
||||
repositoryUrl: project.repositoryUrl,
|
||||
defaultBranch: project.defaultBranch,
|
||||
status:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { AppError } from '../common/errors/app-error';
|
||||
import { ProjectStatus } from '@prisma/client';
|
||||
import { EnvConfig } from '../config/env.schema';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
@@ -55,6 +56,18 @@ export class ProjectRepository {
|
||||
return projects.find((project) => project.key === key) ?? null;
|
||||
}
|
||||
|
||||
async renameByKey(key: string, name: string): Promise<{ name: string }> {
|
||||
if (!this.useDatabaseReads()) {
|
||||
throw new AppError('CONFLICT', '项目名称编辑需要启用数据库', 409);
|
||||
}
|
||||
|
||||
const result = await this.prisma.project.updateMany({ where: { key }, data: { name } });
|
||||
if (result.count === 0) {
|
||||
throw new AppError('RESOURCE_NOT_FOUND', '项目不存在', 404);
|
||||
}
|
||||
return { name };
|
||||
}
|
||||
|
||||
private useDatabaseReads(): boolean {
|
||||
return (
|
||||
this.config.get('USE_DATABASE_READS', { infer: true }) &&
|
||||
|
||||
@@ -4,7 +4,7 @@ export const seedProjects: ProjectSummary[] = [
|
||||
{
|
||||
id: 'project_access_manage',
|
||||
key: 'access-manage',
|
||||
name: 'access-manage',
|
||||
name: '舌吻 · API',
|
||||
repositoryUrl: 'https://gitea.ops.mrzhan.top/my-project/access-manage.git',
|
||||
defaultBranch: 'develop',
|
||||
status: 'active',
|
||||
@@ -28,7 +28,7 @@ export const seedProjects: ProjectSummary[] = [
|
||||
{
|
||||
id: 'project_role_admin',
|
||||
key: 'role-admin',
|
||||
name: 'role-admin',
|
||||
name: '舌吻 · 运营后台',
|
||||
repositoryUrl: 'https://gitea.ops.mrzhan.top/my-project/role-admin.git',
|
||||
defaultBranch: 'develop',
|
||||
status: 'active',
|
||||
@@ -52,7 +52,7 @@ export const seedProjects: ProjectSummary[] = [
|
||||
{
|
||||
id: 'project_role_user',
|
||||
key: 'role-user',
|
||||
name: 'role-user',
|
||||
name: '舌吻 · H5',
|
||||
repositoryUrl: 'https://gitea.ops.mrzhan.top/my-project/role-user.git',
|
||||
defaultBranch: 'develop',
|
||||
status: 'active',
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/**
|
||||
* 项目接口聚合项目配置、Gitea refs 和 Jenkins/Gitea 诊断结果。
|
||||
*/
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Param, Patch, UseGuards } from '@nestjs/common';
|
||||
import { z } from 'zod';
|
||||
import { ZodValidationPipe } from '../common/pipes/zod-validation.pipe';
|
||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '../auth/auth.guard';
|
||||
import { AuthenticatedUser } from '../auth/auth.types';
|
||||
@@ -54,6 +56,17 @@ export class ProjectsController {
|
||||
return this.projectsService.getProject(key, user);
|
||||
}
|
||||
|
||||
@Patch(':key/name')
|
||||
@ApiOkResponse({ description: '更新项目显示名称。' })
|
||||
async renameProject(
|
||||
@Param('key') key: string,
|
||||
@Body(new ZodValidationPipe(z.object({ name: z.string().trim().min(1).max(100) })))
|
||||
body: { name: string },
|
||||
@CurrentUser() user: AuthenticatedUser,
|
||||
): Promise<{ name: string }> {
|
||||
return this.projectsService.renameProject(key, body.name, user);
|
||||
}
|
||||
|
||||
@Get(':key/refs')
|
||||
@ApiOkResponse({ description: '查询项目分支和标签。' })
|
||||
async listProjectRefs(
|
||||
|
||||
@@ -73,6 +73,17 @@ export class ProjectsService {
|
||||
);
|
||||
}
|
||||
|
||||
async renameProject(
|
||||
key: string,
|
||||
name: string,
|
||||
user: AuthenticatedUser,
|
||||
): Promise<{ name: string }> {
|
||||
if (user.role !== 'super_admin') {
|
||||
throw new AppError('FORBIDDEN', '仅超级管理员可以修改项目名称', 403);
|
||||
}
|
||||
return this.projectRepository.renameByKey(key, name);
|
||||
}
|
||||
|
||||
async getProject(
|
||||
key: string,
|
||||
user?: AuthenticatedUser,
|
||||
|
||||
Reference in New Issue
Block a user