浏览代码

fix-464

tags/v1.21.12.1
lewis 4 年前
父节点
当前提交
4dca969c69
共有 4 个文件被更改,包括 29 次插入4 次删除
  1. +1
    -0
      go.mod
  2. +24
    -1
      models/cloudbrain.go
  3. +2
    -1
      routers/repo/cloudbrain.go
  4. +2
    -2
      templates/repo/cloudbrain/index.tmpl

+ 1
- 0
go.mod 查看文件

@@ -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


+ 24
- 1
models/cloudbrain.go 查看文件

@@ -1,6 +1,7 @@
package models package models


import ( import (
"code.gitea.io/gitea/modules/log"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
@@ -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
}

+ 2
- 1
routers/repo/cloudbrain.go 查看文件

@@ -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)


+ 2
- 2
templates/repo/cloudbrain/index.tmpl 查看文件

@@ -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>


正在加载...
取消
保存