From 3ac22385f2cb2256db718e47f5ae3c6d13353b70 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 5 Jun 2022 15:14:34 -0700 Subject: added janny managment for admin board pages --- route/routes/admin.go | 89 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 2 deletions(-) (limited to 'route/routes') diff --git a/route/routes/admin.go b/route/routes/admin.go index c092b84..4571955 100644 --- a/route/routes/admin.go +++ b/route/routes/admin.go @@ -3,6 +3,7 @@ package routes import ( "bytes" "encoding/json" + "errors" "io/ioutil" "net/http" "time" @@ -206,8 +207,22 @@ func AdminAddBoard(ctx *fiber.Ctx) error { } func AdminActorIndex(ctx *fiber.Ctx) error { + var data route.AdminPage + + id, pass := util.GetPasswordFromSession(ctx) actor, _ := webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/") + if actor.Id == "" { + actor, _ = activitypub.GetActorByNameFromDB(config.Domain) + } + + var hasAuth bool + hasAuth, data.Board.ModCred = util.HasAuth(pass, actor.Id) + + if !hasAuth || (id != actor.Id && id != config.Domain) { + return ctx.Render("verify", fiber.Map{}) + } + reqActivity := activitypub.Activity{Id: actor.Following} follow, _ := reqActivity.GetCollection() @@ -225,7 +240,6 @@ func AdminActorIndex(ctx *fiber.Ctx) error { followers = append(followers, e.Id) } - var data route.AdminPage data.Following = following data.Followers = followers data.Reported, _ = db.GetLocalReport(actor.Name) @@ -243,6 +257,12 @@ func AdminActorIndex(ctx *fiber.Ctx) error { data.AutoSubscribe, _ = actor.GetAutoSubscribe() + jannies, err := actor.GetJanitors() + + if err != nil { + return util.MakeError(err, "AdminActorIndex") + } + data.Themes = &config.Themes data.RecentPosts, _ = actor.GetRecentPosts() @@ -252,6 +272,71 @@ func AdminActorIndex(ctx *fiber.Ctx) error { } return ctx.Render("manage", fiber.Map{ - "page": data, + "page": data, + "jannies": jannies, }) } + +func AdminAddJanny(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"), "AdminJanny") + } + + var verify util.Verify + verify.Type = "janitor" + verify.Identifier = actor.Id + verify.Label = ctx.FormValue("label") + + if err := actor.CreateVerification(verify); err != nil { + return util.MakeError(err, "CreateNewBoardDB") + } + + var redirect string + actor, _ = webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/") + + 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+"/") + + 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"), "AdminJanny") + } + + var verify util.Verify + verify.Code = ctx.Query("code") + + if err := actor.DeleteVerification(verify); err != nil { + return util.MakeError(err, "AdminDeleteJanny") + } + + var redirect string + actor, _ = webfinger.GetActorFromPath(ctx.Path(), "/"+config.Key+"/") + + if actor.Name != "main" { + redirect = actor.Name + } + + return ctx.Redirect("/"+config.Key+"/"+redirect, http.StatusSeeOther) +} -- cgit v1.2.3