From cb9a6cf7fcf379202f2ccfc4776daf4dd1d35b9d Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Mon, 13 Jun 2022 22:23:36 -0700 Subject: admin update board summary form --- route/routes/admin.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'route/routes') diff --git a/route/routes/admin.go b/route/routes/admin.go index a2b4ad5..c198e21 100644 --- a/route/routes/admin.go +++ b/route/routes/admin.go @@ -355,6 +355,36 @@ func AdminAddJanny(ctx *fiber.Ctx) error { return ctx.Redirect("/"+config.Key+"/"+redirect, http.StatusSeeOther) } +func AdminEditSummary(ctx *fiber.Ctx) error { + id, pass := util.GetPasswordFromSession(ctx) + actor, _ := webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/") + + if actor.Id == "" { + actor, _ = activitypub.GetActorByNameFromDB(config.Domain) + } + + hasAuth, _type := util.HasAuth(pass, actor.Id) + + if !hasAuth || _type != "admin" || (id != actor.Id && id != config.Domain) { + return util.MakeError(errors.New("Error"), "AdminEditSummary") + } + + summary := ctx.FormValue("summary") + + query := `update actor set summary=$1 where id=$2` + if _, err := config.DB.Exec(query, summary, actor.Id); err != nil { + return util.MakeError(err, "AdminEditSummary") + } + + var redirect string + if actor.Name != "main" { + redirect = actor.Name + } + + return ctx.Redirect("/"+config.Key+"/"+redirect, http.StatusSeeOther) + +} + func AdminDeleteJanny(ctx *fiber.Ctx) error { id, pass := util.GetPasswordFromSession(ctx) actor, _ := webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/") @@ -377,7 +407,6 @@ func AdminDeleteJanny(ctx *fiber.Ctx) error { } var redirect string - actor, _ = webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/") if actor.Name != "main" { redirect = actor.Name -- cgit v1.2.3