mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 09:46:37 +08:00
文件管理权限控制
This commit is contained in:
@@ -190,22 +190,8 @@ func TestGetDistinctUploadTypes(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %s", resp.ErrorMsg)
|
t.Fatalf("unexpected error: %s", resp.ErrorMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that custom_type_xyz and default types are present
|
// Verify that only custom_type_xyz is present
|
||||||
hasCustom := false
|
if len(resp.Data) != 1 || resp.Data[0] != "custom_type_xyz" {
|
||||||
hasAvatar := false
|
t.Errorf("expected only custom_type_xyz in types list, got: %v", resp.Data)
|
||||||
for _, typeName := range resp.Data {
|
|
||||||
if typeName == "custom_type_xyz" {
|
|
||||||
hasCustom = true
|
|
||||||
}
|
|
||||||
if typeName == "avatar" {
|
|
||||||
hasAvatar = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasCustom {
|
|
||||||
t.Errorf("expected custom_type_xyz to be in types, got: %v", resp.Data)
|
|
||||||
}
|
|
||||||
if !hasAvatar {
|
|
||||||
t.Errorf("expected avatar to be in types, got: %v", resp.Data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -579,12 +579,9 @@ func saveUploadRecord(ctx context.Context, upload *model.Upload, storageDriver,
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultUploadTypes 默认内置的文件业务类型
|
// GetDistinctUploadTypes 获取数据库中所有已存在的文件业务类型
|
||||||
var DefaultUploadTypes = []string{"avatar", "attachment", "doc", "generic"}
|
|
||||||
|
|
||||||
// GetDistinctUploadTypes 获取所有已存在的文件业务类型及默认内置类型
|
|
||||||
// @Summary 获取文件业务类型列表
|
// @Summary 获取文件业务类型列表
|
||||||
// @Description 返回系统中所有已上传文件所拥有的业务类型,并合并默认内置类型(avatar, attachment, doc, generic)
|
// @Description 返回数据库中所有已上传文件实际拥有的业务类型列表
|
||||||
// @Tags admin
|
// @Tags admin
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security SessionCookie
|
// @Security SessionCookie
|
||||||
@@ -595,27 +592,14 @@ var DefaultUploadTypes = []string{"avatar", "attachment", "doc", "generic"}
|
|||||||
// @Router /api/v1/admin/uploads/types [get]
|
// @Router /api/v1/admin/uploads/types [get]
|
||||||
func GetDistinctUploadTypes(c *gin.Context) {
|
func GetDistinctUploadTypes(c *gin.Context) {
|
||||||
var dbTypes []string
|
var dbTypes []string
|
||||||
if err := db.DB(c.Request.Context()).Model(&model.Upload{}).Distinct().Pluck("type", &dbTypes).Error; err != nil {
|
if err := db.DB(c.Request.Context()).Model(&model.Upload{}).
|
||||||
|
Where("type IS NOT NULL AND type != ''").
|
||||||
|
Distinct().
|
||||||
|
Pluck("type", &dbTypes).Error; err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, util.Err(err.Error()))
|
c.JSON(http.StatusInternalServerError, util.Err(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并默认内置类型并去重
|
sort.Strings(dbTypes)
|
||||||
typeMap := make(map[string]bool)
|
c.JSON(http.StatusOK, util.OK(dbTypes))
|
||||||
for _, t := range DefaultUploadTypes {
|
|
||||||
typeMap[t] = true
|
|
||||||
}
|
|
||||||
for _, t := range dbTypes {
|
|
||||||
if t != "" {
|
|
||||||
typeMap[t] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make([]string, 0, len(typeMap))
|
|
||||||
for t := range typeMap {
|
|
||||||
result = append(result, t)
|
|
||||||
}
|
|
||||||
sort.Strings(result)
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, util.OK(result))
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user