From f69babbba41e6df79327190134963d1b86dd26f4 Mon Sep 17 00:00:00 2001 From: e <747342561@qq.com> Date: Tue, 26 May 2020 11:47:17 +0800 Subject: [PATCH] opt --- models/dataset_permission.go | 14 ++++---------- modules/storage/storage.go | 9 +++++++-- routers/repo/attachment.go | 6 ++---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/models/dataset_permission.go b/models/dataset_permission.go index 620a42c1a..b03d1b069 100644 --- a/models/dataset_permission.go +++ b/models/dataset_permission.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -8,24 +8,18 @@ import ( "code.gitea.io/gitea/modules/log" ) -const ( - STATUS_PRIVATE = 0 - STATUS_PUBLIC = 1 - STATUS_DELETED = 2 -) - // GetUserDataSetPermission returns the user permissions to the data_set func GetUserDataSetPermission(dataSet *Dataset, user *User) (isPermit bool, err error) { isPermit = false switch dataSet.Status { - case STATUS_DELETED: + case DatasetStatusDeleted: log.Error("the data_set has been deleted") - case STATUS_PRIVATE: + case DatasetStatusPrivate: if !user.IsAdmin && user.ID != dataSet.UserID { log.Error("the user is not admin nor the owner of the data_set") } - case STATUS_PUBLIC: + case DatasetStatusPublic: isPermit = true default: log.Error("the status of data_set is wrong") diff --git a/modules/storage/storage.go b/modules/storage/storage.go index aca4a0b9c..912454ac9 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -11,6 +11,11 @@ import ( "code.gitea.io/gitea/modules/setting" ) +const ( + MinioStorageType = "minio" + LocalStorageType = "local" +) + // ObjectStorage represents an object storage to handle a bucket and files type ObjectStorage interface { Save(path string, r io.Reader) (int64, error) @@ -39,9 +44,9 @@ var ( func Init() error { var err error switch setting.Attachment.StoreType { - case "local": + case LocalStorageType: Attachments, err = NewLocalStorage(setting.Attachment.Path) - case "minio": + case MinioStorageType: minio := setting.Attachment.Minio Attachments, err = NewMinioStorage( minio.Endpoint, diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 7fa86e096..512b06728 100644 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -5,7 +5,6 @@ package repo import ( - "code.gitea.io/gitea/modules/storage" "fmt" "net/http" "strings" @@ -14,11 +13,10 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/upload" ) -const MINIO_STORAGE_TYPE = "minio" - func RenderAttachmentSettings(ctx *context.Context) { renderAttachmentSettings(ctx) } @@ -148,7 +146,7 @@ func GetAttachment(ctx *context.Context) { } //If we have matched and access to release or issue - if setting.Attachment.StoreType == MINIO_STORAGE_TYPE { + if setting.Attachment.StoreType == storage.MinioStorageType { url, err := storage.Attachments.PresignedGetURL(attach.RelativePath(), attach.Name) if err != nil { ctx.ServerError("PresignedGetURL", err)