|
|
@@ -141,6 +141,28 @@ func DeleteAttachment(ctx *context.Context) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func DownloadUserIsOrg(ctx *context.Context, attach *models.Attachment) bool { |
|
|
|
dataset, err := models.GetDatasetByID(attach.DatasetID) |
|
|
|
if err != nil { |
|
|
|
log.Info("query dataset error") |
|
|
|
} else { |
|
|
|
repo, err := models.GetRepositoryByID(dataset.RepoID) |
|
|
|
if err != nil { |
|
|
|
log.Info("query repo error.") |
|
|
|
} else { |
|
|
|
repo.GetOwner() |
|
|
|
if repo.Owner.IsOrganization() { |
|
|
|
log.Info("ower is org.") |
|
|
|
if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { |
|
|
|
log.Info("user may be visit the attach.") |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
// GetAttachment serve attachements |
|
|
|
func GetAttachment(ctx *context.Context) { |
|
|
|
typeCloudBrain := ctx.QueryInt("type") |
|
|
@@ -167,11 +189,14 @@ func GetAttachment(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
if repository == nil { //If not linked |
|
|
|
if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate { //We block if not the uploader |
|
|
|
//if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate { //We block if not the uploader |
|
|
|
if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && DownloadUserIsOrg(ctx, attach) { //We block if not the uploader |
|
|
|
ctx.Error(http.StatusNotFound) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
} else { //If we have the repository we check access |
|
|
|
|
|
|
|
perm, err := models.GetUserRepoPermission(repository, ctx.User) |
|
|
|
if err != nil { |
|
|
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error()) |
|
|
@@ -205,7 +230,7 @@ func GetAttachment(ctx *context.Context) { |
|
|
|
if setting.Attachment.StoreType == storage.MinioStorageType { |
|
|
|
url := "" |
|
|
|
if typeCloudBrain == models.TypeCloudBrainOne { |
|
|
|
url, err = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath + attach.RelativePath(), attach.Name) |
|
|
|
url, err = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath+attach.RelativePath(), attach.Name) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("PresignedGetURL", err) |
|
|
|
return |
|
|
|