feat(runner): finish org runners ui

This commit is contained in:
fuxiaohei
2022-11-25 17:48:46 +08:00
committed by Jason Song
parent 82c6fc2217
commit 888b4c8313
10 changed files with 125 additions and 163 deletions
+13 -2
View File
@@ -1,6 +1,7 @@
package common
import (
"errors"
"net/http"
"strings"
@@ -60,7 +61,7 @@ func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.Fin
ctx.HTML(http.StatusOK, tplName)
}
func RunnerDetails(ctx *context.Context, tplName base.TplName, runnerID int64) {
func RunnerDetails(ctx *context.Context, tplName base.TplName, runnerID int64, ownerID int64, repoID int64) {
runner, err := bots_model.GetRunnerByID(runnerID)
if err != nil {
ctx.ServerError("GetRunnerByID", err)
@@ -70,6 +71,11 @@ func RunnerDetails(ctx *context.Context, tplName base.TplName, runnerID int64) {
ctx.ServerError("LoadAttributes", err)
return
}
if !runner.Editable(ownerID, repoID) {
err = errors.New("no permission to edit this runner")
ctx.NotFound("RunnerDetails", err)
return
}
ctx.Data["Runner"] = runner
@@ -79,13 +85,18 @@ func RunnerDetails(ctx *context.Context, tplName base.TplName, runnerID int64) {
}
// RunnerDetailsEditPost response for edit runner details
func RunnerDetailsEditPost(ctx *context.Context, runnerID int64, redirectTo string) {
func RunnerDetailsEditPost(ctx *context.Context, runnerID int64, ownerID int64, repoID int64, redirectTo string) {
runner, err := bots_model.GetRunnerByID(runnerID)
if err != nil {
log.Warn("RunnerDetailsEditPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL)
ctx.ServerError("RunnerDetailsEditPost.GetRunnerByID", err)
return
}
if !runner.Editable(ownerID, repoID) {
err = errors.New("no permission to edit this runner")
ctx.NotFound("RunnerDetailsEditPost.Editable", err)
return
}
form := web.GetForm(ctx).(*forms.EditRunnerForm)
runner.Description = form.Description