diff --git a/models/attachment.go b/models/attachment.go index fdd26b8ab..418d7c881 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -46,6 +46,7 @@ type Attachment struct { CreatedUnix timeutil.TimeStamp `xorm:"created"` FileChunk *FileChunk `xorm:"-"` + CanDel bool `xorm:"-"` } type AttachmentUsername struct { @@ -437,3 +438,29 @@ func getModelArtsUserAttachments(e Engine, userID int64) ([]*AttachmentUsername, func GetModelArtsUserAttachments(userID int64) ([]*AttachmentUsername, error) { return getModelArtsUserAttachments(x, userID) } + +func CanDelAttachment(isSigned bool, user *User, attach *Attachment) bool { + if !isSigned { + return false + } + dataset, err := GetDatasetByID(attach.DatasetID) + if err != nil { + log.Error("GetDatasetByID failed:%v", err.Error()) + return false + } + repo, _ := GetRepositoryByID(dataset.RepoID) + if err != nil { + log.Error("GetRepositoryByID failed:%v", err.Error()) + return false + } + permission, _ := GetUserRepoPermission(repo, user) + if err != nil { + log.Error("GetUserRepoPermission failed:%v", err.Error()) + return false + } + + if user.ID == attach.UploaderID || user.IsAdmin || permission.AccessMode >= AccessModeAdmin { + return true + } + return false +} diff --git a/models/dataset.go b/models/dataset.go index f4713d77b..e7160006d 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -196,11 +196,11 @@ func (s datasetMetaSearch) Less(i, j int) bool { return s.ID[i] < s.ID[j] } -func GetDatasetAttachments(typeCloudBrain int, rels ...*Dataset) (err error) { - return getDatasetAttachments(x, typeCloudBrain, rels...) +func GetDatasetAttachments(typeCloudBrain int, isSigned bool, user *User, rels ...*Dataset) (err error) { + return getDatasetAttachments(x, typeCloudBrain, isSigned, user, rels...) } -func getDatasetAttachments(e Engine, typeCloudBrain int, rels ...*Dataset) (err error) { +func getDatasetAttachments(e Engine, typeCloudBrain int, isSigned bool, user *User, rels ...*Dataset) (err error) { if len(rels) == 0 { return } @@ -243,6 +243,7 @@ func getDatasetAttachments(e Engine, typeCloudBrain int, rels ...*Dataset) (err return err } attachment.FileChunk = fileChunks[0] + attachment.CanDel = CanDelAttachment(isSigned, user, attachment) sortedRels.Rel[currentIndex].Attachments = append(sortedRels.Rel[currentIndex].Attachments, attachment) } diff --git a/public/self/js/Director/detection.js b/public/self/js/Director/detection.js index 8b63ef854..a853cd076 100644 --- a/public/self/js/Director/detection.js +++ b/public/self/js/Director/detection.js @@ -712,7 +712,17 @@ function loadimg(){ reset_var(); var picturePath = labeltastresult[fileindex].pic_image_field; img.src = ip + "/getgiteaimage?filename=" + picturePath; - var html = picturePath.substring(picturePath.lastIndexOf("/") + 1) + " "+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")" + + var picIndex = picturePath.indexOf("/",70); + + if(picIndex != -1){ + float_text_name = picturePath.substring(picIndex + 1); + float_text_name = float_text_name.substring(float_text_name.indexOf('/')+1); + }else{ + float_text_name = picturePath.substring(picturePath.lastIndexOf("/") + 1) + } + + var html = float_text_name + " "+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")" document.getElementById("float_text").innerHTML = html; } function save(){ @@ -2666,7 +2676,7 @@ function setPage(pageData,pageSize){ canvas = document.getElementById("myCanvas"); context = canvas.getContext("2d"); - maxWidth = document.getElementById("showPic").offsetWidth; + maxWidth = document.getElementById("showPic").offsetWidth-56; maxHeight = document.getElementById("showPic").offsetHeight-100; canvas.width = maxWidth; canvas.height = maxHeight; @@ -2843,14 +2853,20 @@ function isJSON(str) { img.onload = function(){ loadFinished = false; // 初始设置画布大小,最大值宽和高 - canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth; - canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720; + canvas.width = img.width;// maxWidth document.getElementById("tool0").offsetWidth; + canvas.height =img.height;//maxHeight document.getElementById("tool0").offsetWidth/1280*720; //调整画布大小 - if ((img.width/img.height)<(canvas.width/canvas.height)){ - canvas.width=canvas.height * img.width / img.height; + // if ((img.width/img.height)>(maxWidth/maxWidth)){ + // canvas.width=canvas.height * img.width / img.height; + // } + // else{ + // canvas.height=canvas.width * img.height / img.width; + // } + if(canvas.width>maxWidth){ + canvas.width = maxWidth } - else{ - canvas.height=canvas.width * img.height / img.width; + if(canvas.height>maxHeight){ + canvas.height=maxHeight } maxIdNum=0; diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index c62a7b215..a8b2c8fbe 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -128,7 +128,9 @@ func DeleteAttachment(ctx *context.Context) { ctx.Error(400, err.Error()) return } - if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) { + + //issue 214: mod del-dataset permission + if !models.CanDelAttachment(ctx.IsSigned, ctx.User, attach) { ctx.Error(403) return } @@ -146,7 +148,7 @@ func DeleteAttachment(ctx *context.Context) { _, err = models.DeleteFileChunkById(attach.UUID) if err != nil { - ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err)) + ctx.Error(500, fmt.Sprintf("DeleteFileChunkById: %v", err)) return } ctx.JSON(200, map[string]string{ diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 7ada76d88..7d59ab486 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -76,7 +76,7 @@ func QueryDataSet(ctx *context.Context) []*models.Attachment { ctx.NotFound("type error", nil) return nil } - err = models.GetDatasetAttachments(ctx.QueryInt("type"), dataset) + err = models.GetDatasetAttachments(ctx.QueryInt("type"), ctx.IsSigned, ctx.User, dataset) if err != nil { ctx.ServerError("GetDatasetAttachments", err) return nil @@ -120,7 +120,7 @@ func DatasetIndex(ctx *context.Context) { ctx.NotFound("type error", nil) return } - err = models.GetDatasetAttachments(ctx.QueryInt("type"), dataset) + err = models.GetDatasetAttachments(ctx.QueryInt("type"), ctx.IsSigned, ctx.User, dataset) if err != nil { ctx.ServerError("GetDatasetAttachments", err) return diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index decce4fbe..a9eaaaccf 100755 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -39,6 +39,7 @@