Browse Source

opt

tags/vopendata0.1.2
e 5 years ago
parent
commit
f69babbba4
3 changed files with 13 additions and 16 deletions
  1. +4
    -10
      models/dataset_permission.go
  2. +7
    -2
      modules/storage/storage.go
  3. +2
    -4
      routers/repo/attachment.go

+ 4
- 10
models/dataset_permission.go View File

@@ -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 // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.


@@ -8,24 +8,18 @@ import (
"code.gitea.io/gitea/modules/log" "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 // GetUserDataSetPermission returns the user permissions to the data_set
func GetUserDataSetPermission(dataSet *Dataset, user *User) (isPermit bool, err error) { func GetUserDataSetPermission(dataSet *Dataset, user *User) (isPermit bool, err error) {
isPermit = false isPermit = false


switch dataSet.Status { switch dataSet.Status {
case STATUS_DELETED:
case DatasetStatusDeleted:
log.Error("the data_set has been deleted") log.Error("the data_set has been deleted")
case STATUS_PRIVATE:
case DatasetStatusPrivate:
if !user.IsAdmin && user.ID != dataSet.UserID { if !user.IsAdmin && user.ID != dataSet.UserID {
log.Error("the user is not admin nor the owner of the data_set") log.Error("the user is not admin nor the owner of the data_set")
} }
case STATUS_PUBLIC:
case DatasetStatusPublic:
isPermit = true isPermit = true
default: default:
log.Error("the status of data_set is wrong") log.Error("the status of data_set is wrong")


+ 7
- 2
modules/storage/storage.go View File

@@ -11,6 +11,11 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
) )


const (
MinioStorageType = "minio"
LocalStorageType = "local"
)

// ObjectStorage represents an object storage to handle a bucket and files // ObjectStorage represents an object storage to handle a bucket and files
type ObjectStorage interface { type ObjectStorage interface {
Save(path string, r io.Reader) (int64, error) Save(path string, r io.Reader) (int64, error)
@@ -39,9 +44,9 @@ var (
func Init() error { func Init() error {
var err error var err error
switch setting.Attachment.StoreType { switch setting.Attachment.StoreType {
case "local":
case LocalStorageType:
Attachments, err = NewLocalStorage(setting.Attachment.Path) Attachments, err = NewLocalStorage(setting.Attachment.Path)
case "minio":
case MinioStorageType:
minio := setting.Attachment.Minio minio := setting.Attachment.Minio
Attachments, err = NewMinioStorage( Attachments, err = NewMinioStorage(
minio.Endpoint, minio.Endpoint,


+ 2
- 4
routers/repo/attachment.go View File

@@ -5,7 +5,6 @@
package repo package repo


import ( import (
"code.gitea.io/gitea/modules/storage"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
@@ -14,11 +13,10 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/modules/upload"
) )


const MINIO_STORAGE_TYPE = "minio"

func RenderAttachmentSettings(ctx *context.Context) { func RenderAttachmentSettings(ctx *context.Context) {
renderAttachmentSettings(ctx) renderAttachmentSettings(ctx)
} }
@@ -148,7 +146,7 @@ func GetAttachment(ctx *context.Context) {
} }


//If we have matched and access to release or issue //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) url, err := storage.Attachments.PresignedGetURL(attach.RelativePath(), attach.Name)
if err != nil { if err != nil {
ctx.ServerError("PresignedGetURL", err) ctx.ServerError("PresignedGetURL", err)


Loading…
Cancel
Save