|
|
@@ -5,11 +5,12 @@ import ( |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"xorm.io/builder" |
|
|
|
"xorm.io/xorm" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
"xorm.io/builder" |
|
|
|
) |
|
|
|
|
|
|
|
type CloudbrainStatus string |
|
|
@@ -59,6 +60,7 @@ type Cloudbrain struct { |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` |
|
|
|
DeletedAt time.Time `xorm:"deleted"` |
|
|
|
CanDebug bool `xorm:"-"` |
|
|
|
CanDel bool `xorm:"-"` |
|
|
|
Type int `xorm:"INDEX DEFAULT 0"` |
|
|
|
|
|
|
|
User *User `xorm:"-"` |
|
|
@@ -67,7 +69,7 @@ type Cloudbrain struct { |
|
|
|
|
|
|
|
type CloudbrainInfo struct { |
|
|
|
Cloudbrain `xorm:"extends"` |
|
|
|
User `xorm:"extends"` |
|
|
|
User `xorm:"extends"` |
|
|
|
} |
|
|
|
|
|
|
|
type CloudBrainLoginResult struct { |
|
|
@@ -669,3 +671,24 @@ func GetCloudbrainByName(jobName string) (*Cloudbrain, error) { |
|
|
|
cb := &Cloudbrain{JobName: jobName} |
|
|
|
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 |
|
|
|
} |