Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/524pull/529/head
@@ -52,6 +52,7 @@ require ( | |||||
github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28 | github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28 | ||||
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 | github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 | ||||
github.com/golang/protobuf v1.4.1 // indirect | github.com/golang/protobuf v1.4.1 // indirect | ||||
github.com/gomodule/redigo v2.0.0+incompatible | |||||
github.com/google/go-github/v24 v24.0.1 | github.com/google/go-github/v24 v24.0.1 | ||||
github.com/gorilla/context v1.1.1 | github.com/gorilla/context v1.1.1 | ||||
github.com/hashicorp/go-retryablehttp v0.6.6 // indirect | github.com/hashicorp/go-retryablehttp v0.6.6 // indirect | ||||
@@ -5,11 +5,12 @@ import ( | |||||
"fmt" | "fmt" | ||||
"strings" | "strings" | ||||
"time" | "time" | ||||
"xorm.io/builder" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
"code.gitea.io/gitea/modules/log" | |||||
"code.gitea.io/gitea/modules/setting" | "code.gitea.io/gitea/modules/setting" | ||||
"code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
"xorm.io/builder" | |||||
) | ) | ||||
type CloudbrainStatus string | type CloudbrainStatus string | ||||
@@ -59,6 +60,7 @@ type Cloudbrain struct { | |||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | ||||
DeletedAt time.Time `xorm:"deleted"` | DeletedAt time.Time `xorm:"deleted"` | ||||
CanDebug bool `xorm:"-"` | CanDebug bool `xorm:"-"` | ||||
CanDel bool `xorm:"-"` | |||||
Type int `xorm:"INDEX DEFAULT 0"` | Type int `xorm:"INDEX DEFAULT 0"` | ||||
User *User `xorm:"-"` | User *User `xorm:"-"` | ||||
@@ -67,7 +69,7 @@ type Cloudbrain struct { | |||||
type CloudbrainInfo struct { | type CloudbrainInfo struct { | ||||
Cloudbrain `xorm:"extends"` | Cloudbrain `xorm:"extends"` | ||||
User `xorm:"extends"` | |||||
User `xorm:"extends"` | |||||
} | } | ||||
type CloudBrainLoginResult struct { | type CloudBrainLoginResult struct { | ||||
@@ -669,3 +671,24 @@ func GetCloudbrainByName(jobName string) (*Cloudbrain, error) { | |||||
cb := &Cloudbrain{JobName: jobName} | cb := &Cloudbrain{JobName: jobName} | ||||
return getRepoCloudBrain(cb) | return getRepoCloudBrain(cb) | ||||
} | } | ||||
func CanDelJob(isSigned bool, user *User, job *CloudbrainInfo) bool { | |||||
if !isSigned || job.Status != string(JobStopped) { | |||||
return false | |||||
} | |||||
repo, err := GetRepositoryByID(job.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 == job.UserID || user.IsAdmin || permission.AccessMode >= AccessModeAdmin { | |||||
return true | |||||
} | |||||
return false | |||||
} |
@@ -69,12 +69,13 @@ func CloudBrainIndex(ctx *context.Context) { | |||||
timestamp := time.Now().Unix() | timestamp := time.Now().Unix() | ||||
for i, task := range ciTasks { | for i, task := range ciTasks { | ||||
log.Info("", task.User.Name) | |||||
if task.Status == string(models.JobRunning) && (timestamp-int64(task.Cloudbrain.CreatedUnix) > 10) { | if task.Status == string(models.JobRunning) && (timestamp-int64(task.Cloudbrain.CreatedUnix) > 10) { | ||||
ciTasks[i].CanDebug = true | ciTasks[i].CanDebug = true | ||||
} else { | } else { | ||||
ciTasks[i].CanDebug = false | ciTasks[i].CanDebug = false | ||||
} | } | ||||
ciTasks[i].CanDel = models.CanDelJob(ctx.IsSigned, ctx.User, task) | |||||
} | } | ||||
pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) | pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) | ||||
@@ -353,9 +353,9 @@ | |||||
</div> | </div> | ||||
<!-- 删除镜像 --> | <!-- 删除镜像 --> | ||||
<form class="ui compact buttons" id="delForm-{{.JobID}}" action="{{if ne .Status "STOPPED"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/del{{end}}" method="post"> | |||||
<form class="ui compact buttons" id="delForm-{{.JobID}}" action="{{if not .CanDel}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/del{{end}}" method="post"> | |||||
{{$.CsrfTokenHtml}} | {{$.CsrfTokenHtml}} | ||||
<a class="ui compact {{if ne .Status "STOPPED"}}disabled {{else}}red {{end}}button" onclick="assertDelete(this)" style="border-radius: .28571429rem;"> | |||||
<a class="ui compact {{if not .CanDel}}disabled {{else}}red {{end}}button" onclick="assertDelete(this)" style="border-radius: .28571429rem;"> | |||||
删除 | 删除 | ||||
</a> | </a> | ||||
</form> | </form> | ||||