#5345 fix-5131 repoOwner can download log

Merged
ychao_1983 merged 2 commits from fix-5131 into V20240402 1 month ago
  1. +13
    -0
      modules/cloudbrain/cloudbrain.go
  2. +3
    -3
      routers/ai_task/ai_task.go
  3. +0
    -1
      services/ai_task_service/cluster/cloudbrain_one.go

+ 13
- 0
modules/cloudbrain/cloudbrain.go View File

@@ -91,6 +91,19 @@ func GetCloudbrainDebugCommand() string {
return command
}

func IsAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool {
if !ctx.IsSigned {
return false
}
if err != nil {

return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin()
} else {
return ctx.IsUserRepoOwner() || ctx.IsUserSiteAdmin() || ctx.User.ID == job.UserID
}

}

func isAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool {
if !ctx.IsSigned {
return false


+ 3
- 3
routers/ai_task/ai_task.go View File

@@ -80,13 +80,13 @@ func GetAITaskLog(ctx *context.Context) {
order := ctx.Query("order")
nodeId := ctx.QueryInt("node_id")
logFileName := ctx.Query("file_name")
cloudbrain, bizErr := models.GetCloudbrainByCloudbrainID(id)
job, bizErr := models.GetCloudbrainByCloudbrainID(id)
if bizErr != nil {
log.Error("GetAITaskLog GetCloudbrainByCloudbrainID err.%v", bizErr)
ctx.JSON(http.StatusOK, response.OuterTrBizError(response.AI_TASK_NOT_EXISTS, ctx))
return
}
t, err := task.GetAITaskTemplateFromCloudbrain(cloudbrain)
t, err := task.GetAITaskTemplateFromCloudbrain(job)
if err != nil {
log.Error("param error")
ctx.JSON(http.StatusOK, response.OuterTrBizError(err, ctx))
@@ -105,7 +105,7 @@ func GetAITaskLog(ctx *context.Context) {
ctx.JSON(http.StatusOK, response.OuterTrBizError(err, ctx))
return
}
if res.Content != "" && cloudbrain.IsUserHasRight(ctx.User) {
if res.Content != "" && cloudbrain.IsAdminOrOwnerOrJobCreater(ctx, job, nil) {
res.CanLogDownload = true
}
ctx.JSON(http.StatusOK, response.OuterSuccessWithData(res))


+ 0
- 1
services/ai_task_service/cluster/cloudbrain_one.go View File

@@ -1,6 +1,5 @@
package cluster

import "C"
import (
"encoding/json"
"errors"


Loading…
Cancel
Save