From 7e1372b0b473b6b74041a9b8109749b7796c603e Mon Sep 17 00:00:00 2001 From: Azareal Date: Fri, 8 Nov 2019 20:08:37 +1000 Subject: [PATCH] Adminlogs: Forum Manager Actions. Shave off a few bytes in the templates. Add forum_unknown phrase. Add panel_logs_administration_action_forum_reorder phrase. Add panel_logs_administration_action_forum_create phrase. Add panel_logs_administration_action_forum_delete phrase. Add panel_logs_administration_action_forum_edit phrase. --- langs/english.json | 5 +++++ routes/panel/forums.go | 30 +++++++++++++++++++++++++++--- routes/panel/logs.go | 10 ++++++++++ templates/panel_forum_edit.html | 4 ++-- templates/panel_forums.html | 4 ++-- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/langs/english.json b/langs/english.json index c4ea46e8..6ae0b5a4 100644 --- a/langs/english.json +++ b/langs/english.json @@ -1020,6 +1020,7 @@ "user_unknown":"Unknown", "topic_unknown":"Unknown", "group_unknown":"Unknown", + "forum_unknown":"Unknown", "panel_logs_administration_head":"Admin Action Logs", "panel_logs_administration_action_user_edit":"User %s was modified by %s", @@ -1027,6 +1028,10 @@ "panel_logs_administration_action_group_edit":"Group %s was modified by %s", "panel_logs_administration_action_group_promotion_create":"A group promotion was created by %s", "panel_logs_administration_action_group_promotion_delete":"A group promotion was deleted by %s", + "panel_logs_administration_action_forum_reorder":"Forums were reordered by %s", + "panel_logs_administration_action_forum_create":"Forum %s was created by %s", + "panel_logs_administration_action_forum_delete":"Forum %s was deleted by %s", + "panel_logs_administration_action_forum_edit":"Forum %s was modified by %s", "panel_logs_administration_action_unknown":"Unknown action '%s' on elementType '%s' by %s", "panel_logs_administration_no_logs":"There aren't any events logged.", diff --git a/routes/panel/forums.go b/routes/panel/forums.go index 8618d0a6..000c88d8 100644 --- a/routes/panel/forums.go +++ b/routes/panel/forums.go @@ -67,7 +67,11 @@ func ForumsCreateSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.R factive := r.PostFormValue("active") active := (factive == "on" || factive == "1") - _, err := c.Forums.Create(fname, fdesc, active, fpreset) + fid, err := c.Forums.Create(fname, fdesc, active, fpreset) + if err != nil { + return c.InternalError(err, w, r) + } + err = c.AdminLogs.Create("create", fid, "forum", user.LastIP, user.ID) if err != nil { return c.InternalError(err, w, r) } @@ -90,7 +94,6 @@ func ForumsDelete(w http.ResponseWriter, r *http.Request, user c.User, sfid stri if err != nil { return c.LocalError("The provided Forum ID is not a valid number.", w, r, user) } - forum, err := c.Forums.Get(fid) if err == sql.ErrNoRows { return c.LocalError("The forum you're trying to delete doesn't exist.", w, r, user) @@ -127,6 +130,10 @@ func ForumsDeleteSubmit(w http.ResponseWriter, r *http.Request, user c.User, sfi } else if err != nil { return c.InternalError(err, w, r) } + err = c.AdminLogs.Create("delete", fid, "forum", user.LastIP, user.ID) + if err != nil { + return c.InternalError(err, w, r) + } http.Redirect(w, r, "/panel/forums/?deleted=1", http.StatusSeeOther) return nil @@ -154,6 +161,11 @@ func ForumsOrderSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.Ro } c.Forums.UpdateOrder(updateMap) + err := c.AdminLogs.Create("reorder", 0, "forum", user.LastIP, user.ID) + if err != nil { + return c.InternalErrorJSQ(err, w, r, js) + } + return successRedirect("/panel/forums/", w, r, js) } @@ -224,7 +236,6 @@ func ForumsEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, sfid if err != nil { return c.LocalErrorJSQ("The provided Forum ID is not a valid number.", w, r, user, js) } - forum, err := c.Forums.Get(fid) if err == sql.ErrNoRows { return c.LocalErrorJSQ("The forum you're trying to edit doesn't exist.", w, r, user, js) @@ -248,6 +259,11 @@ func ForumsEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, sfid if err != nil { return c.InternalErrorJSQ(err, w, r, js) } + err = c.AdminLogs.Create("edit", fid, "forum", user.LastIP, user.ID) + if err != nil { + return c.InternalError(err, w, r) + } + // ? Should we redirect to the forum editor instead? return successRedirect("/panel/forums/", w, r, js) } @@ -284,6 +300,10 @@ func ForumsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user c.User, if err != nil { return c.LocalErrorJSQ(err.Error(), w, r, user, js) } + err = c.AdminLogs.Create("edit", fid, "forum", user.LastIP, user.ID) + if err != nil { + return c.InternalError(err, w, r) + } return successRedirect("/panel/forums/edit/"+strconv.Itoa(fid)+"?updated=1", w, r, js) } @@ -418,6 +438,10 @@ func ForumsEditPermsAdvanceSubmit(w http.ResponseWriter, r *http.Request, user c if err != nil { return c.LocalErrorJSQ(err.Error(), w, r, user, js) } + err = c.AdminLogs.Create("edit", fid, "forum", user.LastIP, user.ID) + if err != nil { + return c.InternalError(err, w, r) + } return successRedirect("/panel/forums/edit/perms/"+strconv.Itoa(fid)+"-"+strconv.Itoa(gid)+"?updated=1", w, r, js) } diff --git a/routes/panel/logs.go b/routes/panel/logs.go index c8003ab9..bf1c7333 100644 --- a/routes/panel/logs.go +++ b/routes/panel/logs.go @@ -114,6 +114,16 @@ func adminlogsElementType(action string, elementType string, elementID int, acto out = p.GetTmplPhrasef("panel_logs_administration_action_group_"+action, "/panel/groups/edit/"+strconv.Itoa(g.ID), g.Name, actor.Link, actor.Name) case "group_promotion": out = p.GetTmplPhrasef("panel_logs_administration_action_group_promotion_"+action, actor.Link, actor.Name) + case "forum": + f, err := c.Forums.Get(elementID) + if err != nil { + f = &c.Forum{Name: p.GetTmplPhrase("forum_unknown")} + } + if action == "reorder" { + out = p.GetTmplPhrasef("panel_logs_administration_action_forum_reorder", actor.Link, actor.Name) + } else { + out = p.GetTmplPhrasef("panel_logs_administration_action_forum_"+action, "/panel/forums/edit/"+strconv.Itoa(f.ID), f.Name, actor.Link, actor.Name) + } } if out == "" { out = p.GetTmplPhrasef("panel_logs_administration_action_unknown", action, elementType, actor.Link, actor.Name) diff --git a/templates/panel_forum_edit.html b/templates/panel_forum_edit.html index 83ed51ee..9c27d7e8 100644 --- a/templates/panel_forum_edit.html +++ b/templates/panel_forum_edit.html @@ -14,8 +14,8 @@
diff --git a/templates/panel_forums.html b/templates/panel_forums.html index bd73c23b..5b5313da 100644 --- a/templates/panel_forums.html +++ b/templates/panel_forums.html @@ -46,8 +46,8 @@