aboutsummaryrefslogtreecommitdiff
path: root/route
diff options
context:
space:
mode:
authorFChannel <>2022-06-05 15:14:34 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit3ac22385f2cb2256db718e47f5ae3c6d13353b70 (patch)
tree49f12c0cc52661f1fd6661baf2f77fbd5c7f71de /route
parent0359d9d410b9ab597ed4a067d767ab59472b0c03 (diff)
added janny managment for admin board pages
Diffstat (limited to 'route')
-rw-r--r--route/routes/admin.go89
1 files changed, 87 insertions, 2 deletions
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)
+}