增加网站管理功能
This commit is contained in:
@@ -287,6 +287,34 @@ type platformRenameCateBody struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// protectedFileCateNames 受保护的文件分组名称(平台端)。
|
||||
//
|
||||
// 这些分组由功能模块按「名称」定位,删除或改名都会导致模块找不到分组:
|
||||
// - 删除:素材被分散到未分类,且模块会重新补建一个空分组;
|
||||
// - 改名:模块按名称找不到旧分组,会新建一个同名分组,历史文件被遗留在旧分组里。
|
||||
// 因此统一禁止删除/重命名,需要调整时走 SQL 人工处理。
|
||||
//
|
||||
// 官网素材 官网管理(platform/src/views/website)所有上传的归属分组
|
||||
// (见 platform/src/utils/websiteUpload.js)
|
||||
// appsupgrade 软件升级安装包分组(见 platform/src/views/platform/softwareupgrade)
|
||||
// 图片 平台预留的图片分组,作为官网/后台配图的固定归档位
|
||||
var protectedFileCateNames = []string{
|
||||
"官网素材",
|
||||
"appsupgrade",
|
||||
"图片",
|
||||
}
|
||||
|
||||
// isProtectedFileCate 判断分组是否为受保护的系统默认分组
|
||||
func isProtectedFileCate(name string) bool {
|
||||
name = strings.TrimSpace(name)
|
||||
for _, n := range protectedFileCateNames {
|
||||
if n == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RenameFileCate POST /platform/renamefilecate/:id
|
||||
func (c *PlatformFileController) RenameFileCate() {
|
||||
claims, err := c.platformClaims()
|
||||
@@ -316,6 +344,22 @@ func (c *PlatformFileController) RenameFileCate() {
|
||||
c.jsonErr(400, 400, "分组名称不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
// 受保护分组禁止改名:功能模块按名称定位该分组
|
||||
var existCate models.SystemFilesCategory
|
||||
if err = models.Orm.QueryTable(new(models.SystemFilesCategory)).
|
||||
Filter("id", id).
|
||||
Filter("tid", tid).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&existCate); err != nil {
|
||||
c.jsonErr(404, 404, "分组不存在")
|
||||
return
|
||||
}
|
||||
if isProtectedFileCate(existCate.Name) {
|
||||
c.jsonErr(400, 400, fmt.Sprintf("「%s」为系统默认分组,不可重命名", existCate.Name))
|
||||
return
|
||||
}
|
||||
|
||||
n, err := models.Orm.QueryTable(new(models.SystemFilesCategory)).
|
||||
Filter("id", id).
|
||||
Filter("tid", tid).
|
||||
@@ -347,6 +391,21 @@ func (c *PlatformFileController) DeleteFileCate() {
|
||||
c.jsonErr(400, 400, "无效的分组ID")
|
||||
return
|
||||
}
|
||||
// 受保护分组禁止删除(先取出分组,便于给出明确提示)
|
||||
var existCate models.SystemFilesCategory
|
||||
if err = models.Orm.QueryTable(new(models.SystemFilesCategory)).
|
||||
Filter("id", id).
|
||||
Filter("tid", tid).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&existCate); err != nil {
|
||||
c.jsonErr(404, 404, "分组不存在")
|
||||
return
|
||||
}
|
||||
if isProtectedFileCate(existCate.Name) {
|
||||
c.jsonErr(400, 400, fmt.Sprintf("「%s」为系统默认分组,不可删除", existCate.Name))
|
||||
return
|
||||
}
|
||||
|
||||
cnt, err := models.Orm.QueryTable(new(models.SystemFile)).
|
||||
Filter("cate", id).
|
||||
Filter("tid", tid).
|
||||
|
||||
Reference in New Issue
Block a user