diff --git a/models/attachment.go b/models/attachment.go index 4f2c8d09a..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 { @@ -378,7 +379,7 @@ func GetUnDecompressAttachments() ([]*Attachment, error) { func getUnDecompressAttachments(e Engine) ([]*Attachment, error) { attachments := make([]*Attachment, 0, 10) - return attachments, e.Where("decompress_state = ? and dataset_id != 0 and attachment.type = ? and name like '%.zip'", DecompressStateInit, TypeCloudBrainOne).Find(&attachments) + return attachments, e.Where("decompress_state = ? and dataset_id != 0 and attachment.type = ? and (name like '%.zip' or name like '%.tar.gz' or name like '%.tgz')", DecompressStateInit, TypeCloudBrainOne).Find(&attachments) } func GetAllPublicAttachments() ([]*AttachmentUsername, error) { @@ -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/cloudbrain.go b/models/cloudbrain.go index 0a6936851..edd5f102a 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -3,6 +3,7 @@ package models import ( "encoding/json" "fmt" + "strings" "time" "xorm.io/xorm" @@ -176,6 +177,10 @@ func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) { err := json.Unmarshal(data, &taskPod) taskPod.TaskStatuses[0].StartTime = time.Unix(taskPod.TaskStatuses[0].StartAt.Unix()+8*3600, 0).UTC().Format("2006-01-02 15:04:05") taskPod.TaskStatuses[0].FinishedTime = time.Unix(taskPod.TaskStatuses[0].FinishedAt.Unix()+8*3600, 0).UTC().Format("2006-01-02 15:04:05") + //if the task is not finished or stopped,the cloudbrain renturns 0001-01-01 08:00:00, the finishedTime shows with - + if strings.HasPrefix(taskPod.TaskStatuses[0].FinishedTime, "0001") { + taskPod.TaskStatuses[0].FinishedTime = "-" + } return taskPod, err } 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/modules/repository/create.go b/modules/repository/create.go index 5c0aae30d..d740c58b1 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -47,7 +47,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (_ *m // No need for init mirror. if !opts.IsMirror { repoPath := models.RepoPath(u.Name, repo.Name) - if err = initRepository(ctx, repoPath, u, repo, opts); err != nil { + if err = initRepository(ctx, repoPath, doer, u, repo, opts); err != nil { if err2 := os.RemoveAll(repoPath); err2 != nil { log.Error("initRepository: %v", err) return fmt.Errorf( diff --git a/modules/repository/init.go b/modules/repository/init.go index f468ca043..3d1c663c8 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -176,7 +176,7 @@ func checkInitRepository(repoPath string) (err error) { } // InitRepository initializes README and .gitignore if needed. -func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { +func initRepository(ctx models.DBContext, repoPath string, doer *models.User, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { if err = checkInitRepository(repoPath); err != nil { return err } @@ -195,8 +195,14 @@ func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo } // Apply changes and commit. - if err = initRepoCommit(tmpDir, repo, u, opts.DefaultBranch); err != nil { - return fmt.Errorf("initRepoCommit: %v", err) + if u.IsOrganization() { + if err = initRepoCommit(tmpDir, repo, doer, opts.DefaultBranch); err != nil { + return fmt.Errorf("initRepoCommit: %v", err) + } + } else { + if err = initRepoCommit(tmpDir, repo, u, opts.DefaultBranch); err != nil { + return fmt.Errorf("initRepoCommit: %v", err) + } } } diff --git a/modules/worker/task.go b/modules/worker/task.go index 073b16b92..c2d9467dc 100755 --- a/modules/worker/task.go +++ b/modules/worker/task.go @@ -13,8 +13,8 @@ const ( DecompressTaskName = "Decompress" ) -func SendDecompressTask(ctx context.Context, uuid string) error { - args := []tasks.Arg{{Name: "uuid", Type: "string", Value: uuid}} +func SendDecompressTask(ctx context.Context, uuid string, name string) error { + args := []tasks.Arg{{Name: "uuid", Type: "string", Value: uuid}, {Name: "name", Type: "string", Value: name}} task, err := tasks.NewSignature(DecompressTaskName, args) if err != nil { log.Error("NewSignature failed:", err.Error()) diff --git a/public/self/js/Director/detection.js b/public/self/js/Director/detection.js index 5f40e73c3..c822d7515 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(){ @@ -1640,22 +1650,31 @@ function showfilelist(){ var htmlstr=""; for (var i=0;i 70){ + var tmpIndex = labeltastresult[i].pic_image_field.indexOf("/",70); + console.log(tmpIndex) + if(tmpIndex != -1){ + fname = labeltastresult[i].pic_image_field.substring(tmpIndex + 1); + fname = fname.substring(fname.indexOf('/')+1); + } + } + var isfinished = labeltastresult[i].label_status; - if(isVerified()){ - isfinished = labeltastresult[i].verify_status - 1; - } + if(isVerified()){ + isfinished = labeltastresult[i].verify_status - 1; + } var lablebg=" style=\"cursor:pointer\""; var classStr = "style=\"color:#FF6200;background: transparent;border: 0;\""; var finish="未完成"; if (isfinished=="0"){finish="已完成";classStr = "style=\"color:#27c24c;background: transparent;border: 0;\"";} if (i==fileindex){lablebg=" style=\"color:#fff;cursor:pointer;\"";classStr = "style=\"color:#04B3E5;background: transparent;border: 0;\"";finish="标注中"} - if(isVerified()){ - htmlstr = htmlstr+" "+""+finish +""+""+ fname+ ""; - }else{ - htmlstr = htmlstr+""+fname+""+""+""; - } + if(isVerified()){ + htmlstr = htmlstr+" "+""+finish +""+""+ fname+ ""; + }else{ + htmlstr = htmlstr+""+fname+""+""+""; + } - }; + } document.getElementById("filelist").innerHTML=htmlstr; } @@ -2834,8 +2853,8 @@ 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; diff --git a/public/self/labelTaskPage.js b/public/self/labelTaskPage.js index 98813dd08..4ce48407a 100644 --- a/public/self/labelTaskPage.js +++ b/public/self/labelTaskPage.js @@ -318,7 +318,7 @@ function label_task_create(task_name, relate_task_id, taskType,assign_user_id,la success:function(res){ console.log(res); if(res.code == 0){ - alert("人工校验任务创建成功!"); + alert("人工标注任务创建成功!"); createsucced = true; } else{ diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index cfbbc73a4..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{ @@ -384,9 +386,9 @@ func AddAttachment(ctx *context.Context) { } if attachment.DatasetID != 0 { - if strings.HasSuffix(attachment.Name, ".zip") { + if isCanDecompress(attachment.Name) { if typeCloudBrain == models.TypeCloudBrainOne { - err = worker.SendDecompressTask(contexExt.Background(), uuid) + err = worker.SendDecompressTask(contexExt.Background(), uuid, attachment.Name) if err != nil { log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error()) } else { @@ -406,6 +408,13 @@ func AddAttachment(ctx *context.Context) { }) } +func isCanDecompress(name string) bool { + if strings.HasSuffix(name, ".zip") || strings.HasSuffix(name, ".tar.gz") || strings.HasSuffix(name, ".tgz") { + return true + } + return false +} + func UpdateAttachmentDecompressState(ctx *context.Context) { uuid := ctx.Query("uuid") result := ctx.Query("result") @@ -766,9 +775,9 @@ func CompleteMultipart(ctx *context.Context) { } if attachment.DatasetID != 0 { - if strings.HasSuffix(attachment.Name, ".zip") { + if isCanDecompress(attachment.Name) { if typeCloudBrain == models.TypeCloudBrainOne { - err = worker.SendDecompressTask(contexExt.Background(), uuid) + err = worker.SendDecompressTask(contexExt.Background(), uuid, attachment.Name) if err != nil { log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error()) } else { @@ -838,7 +847,7 @@ func HandleUnDecompressAttachment() { } for _, attach := range attachs { - err = worker.SendDecompressTask(contexExt.Background(), attach.UUID) + err = worker.SendDecompressTask(contexExt.Background(), attach.UUID, attach.Name) if err != nil { log.Error("SendDecompressTask(%s) failed:%s", attach.UUID, err.Error()) } else { diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 2e5e3d2e3..deac7b312 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -67,7 +67,7 @@ func CloudBrainIndex(ctx *context.Context) { timestamp := time.Now().Unix() for i, task := range ciTasks { - if task.Status == string(models.JobRunning) && (timestamp-int64(task.CreatedUnix) > 30) { + if task.Status == string(models.JobRunning) && (timestamp-int64(task.CreatedUnix) > 10) { ciTasks[i].CanDebug = true } else { ciTasks[i].CanDebug = false @@ -267,6 +267,7 @@ func CloudBrainShow(ctx *context.Context) { if result != nil { jobRes, _ := models.ConvertToJobResultPayload(result.Payload) + jobRes.Resource.Memory = strings.ReplaceAll(jobRes.Resource.Memory, "Mi", "MB") ctx.Data["result"] = jobRes taskRoles := jobRes.TaskRoles taskRes, _ := models.ConvertToTaskPod(taskRoles[cloudbrain.SubTaskName].(map[string]interface{})) 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/routers/repo/dir.go b/routers/repo/dir.go index ea46af7fc..612019d46 100755 --- a/routers/repo/dir.go +++ b/routers/repo/dir.go @@ -39,7 +39,8 @@ func DeleteAllUnzipFile(attachment *models.Attachment, parentDir string) { uuid := attachment.UUID dirArray := strings.Split(parentDir, "/") - if !strings.HasSuffix(attachment.Name, ".zip") { + //if !strings.HasSuffix(attachment.Name, ".zip") { + if !isCanDecompress(attachment.Name) { log.Error("The file is not zip file, can not query the dir") return } else if attachment.DecompressState != models.DecompressStateDone { @@ -69,7 +70,7 @@ func DeleteAllUnzipFile(attachment *models.Attachment, parentDir string) { log.Info("fileName=" + fileInfo.FileName) log.Info("parentDir=" + fileInfo.ParenDir) if fileInfo.IsDir { - DeleteAllUnzipFile(attachment, fileInfo.FileName) + DeleteAllUnzipFile(attachment, fileInfo.ParenDir) } else { absolutepath := path.Join(attachment.RelativePath()+attachment.UUID, fileInfo.ParenDir) log.Info("absolutepath=" + absolutepath) @@ -127,7 +128,8 @@ func DirIndex(ctx *context.Context) { return } - if !strings.HasSuffix(attachment.Name, ".zip") { + //if !strings.HasSuffix(attachment.Name, ".zip") { + if !isCanDecompress(attachment.Name) { log.Error("The file is not zip file, can not query the dir") ctx.ServerError("The file is not zip file, can not query the dir", errors.New("The file is not zip file, can not query the dir")) return diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index 227aa5d88..450adf2a5 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -2,6 +2,13 @@ {{template "base/head" .}}