diff --git a/communityadmin.go b/communityadmin.go index 9c94c49..a1e1a9f 100644 --- a/communityadmin.go +++ b/communityadmin.go @@ -347,6 +347,80 @@ func EditCommunityLogo(ctxt ui.AmContext) (string, any) { return "error", EBUTTON } +/* CommunityAudit handles displaying the community audit records. + * Parameters: + * ctxt - The AmContext for the request. + * Returns: + * Command string dictating what to be rendered. + * Data as a parameter for the command string. + * Standard Go error status. + */ +func CommunityAudit(ctxt ui.AmContext) (string, any) { + comm := ctxt.CurrentCommunity() + if !comm.TestPermission("Community.Delete", ctxt.EffectiveLevel()) && !comm.TestPermission("Community.Write", ctxt.EffectiveLevel()) && !comm.TestPermission("Community.Create", ctxt.EffectiveLevel()) { + return "error", ENOACCESS + } + ofs := 0 + maxRecs := ctxt.Globals().NumAuditPage + if ctxt.Verb() == "POST" { + if ctxt.FormFieldIsSet("prev") { + ofs = min(0, ofs-int(maxRecs)) + } else if ctxt.FormFieldIsSet("next") { + ofs += int(maxRecs) + } + } + + auditRecs, total, err := database.AmListAuditRecords(ctxt.Ctx(), comm, ofs, int(maxRecs)) + if err != nil { + return "error", err + } + + descr := make([]string, len(auditRecs)) + userName := make([]string, len(auditRecs)) + communityName := make([]string, len(auditRecs)) + for i, ar := range auditRecs { + descr[i] = database.AmAuditText(int(ar.Event)) + if ar.Uid > 0 { + user, err := database.AmGetUser(ctxt.Ctx(), ar.Uid) + if err != nil { + userName[i] = fmt.Sprintf("<<%v>>", err) + } else { + userName[i] = user.Username + } + } else { + userName[i] = "" + } + if ar.CommId > 0 { + comm, err := database.AmGetCommunity(ctxt.Ctx(), ar.CommId) + if err != nil { + communityName[i] = fmt.Sprintf("<<%v>>", err) + } else { + communityName[i] = comm.Name + } + } else { + communityName[i] = "" + } + } + + ctxt.VarMap().Set("commName", comm.Name) + ctxt.VarMap().Set("backLink", fmt.Sprintf("/comm/%s/admin", comm.Alias)) + ctxt.VarMap().Set("selfLink", fmt.Sprintf("/comm/%s/admin/audit", comm.Alias)) + ctxt.VarMap().Set("total", total) + ctxt.VarMap().Set("ofs", ofs) + ctxt.VarMap().Set("auditRecords", auditRecs) + ctxt.VarMap().Set("descr", descr) + ctxt.VarMap().Set("user", userName) + ctxt.VarMap().Set("community", communityName) + if ofs > 0 { + ctxt.VarMap().Set("showPrev", true) + } + if ofs+int(maxRecs) < total { + ctxt.VarMap().Set("showNext", true) + } + ctxt.SetFrameTitle(fmt.Sprintf("Audit Records for Community \"%s\"", comm.Name)) + return "framed", "audit.jet" +} + /* CreateCommunityForm renders the form for creating a new community. * Parameters: * ctxt - The AmContext for the request. diff --git a/docs/MISSINGFUNCS.md b/docs/MISSINGFUNCS.md index af98a18..2008fdd 100644 --- a/docs/MISSINGFUNCS.md +++ b/docs/MISSINGFUNCS.md @@ -27,7 +27,7 @@ _(italicized items can be deferred)_ - Set Community Category - Membership Control - E-Mail to All Members - - Display Audit Records + - ~~Display Audit Records~~ - Delete Community - ~~Community Profile: Invite~~ - _Help link atop page headers_ diff --git a/main.go b/main.go index 80091c8..bfc079f 100644 --- a/main.go +++ b/main.go @@ -115,6 +115,7 @@ func setupEcho() *echo.Echo { commGroup.POST("/admin/profile", ui.AmWrap(EditCommunityProfile)) commGroup.GET("/admin/logo", ui.AmWrap(CommunityLogoForm)) commGroup.POST("/admin/logo", ui.AmWrap(EditCommunityLogo)) + commGroup.Match(GetAndPost, "/admin/audit", ui.AmWrap(CommunityAudit)) // conference group commGroup.GET("/create_conf", ui.AmWrap(CreateConferenceForm)) diff --git a/sysadmin.go b/sysadmin.go index 85cf50f..bc22617 100644 --- a/sysadmin.go +++ b/sysadmin.go @@ -731,6 +731,8 @@ func SystemAudit(ctxt ui.AmContext) (string, any) { } } + ctxt.VarMap().Set("backLink", "/sysadmin") + ctxt.VarMap().Set("selfLink", "/sysadmin/audit") ctxt.VarMap().Set("total", total) ctxt.VarMap().Set("ofs", ofs) ctxt.VarMap().Set("auditRecords", auditRecs) diff --git a/ui/menudefs.yaml b/ui/menudefs.yaml index 08c9134..3cd71e5 100644 --- a/ui/menudefs.yaml +++ b/ui/menudefs.yaml @@ -78,7 +78,7 @@ menudefs: link: "/TODO/comm/[CID]/admin/massmail" permission: "Community.MassMail" - text: "Display Audit Records" - link: "/TODO/comm/[CID]/admin/audit" + link: "/comm/[CID]/admin/audit" permission: "Community.ShowAdmin" - text: "Delete Community" link: "/TODO/comm/[CID]/admin/delete" diff --git a/ui/views/audit.jet b/ui/views/audit.jet index 0d4d96e..edc64d6 100644 --- a/ui/views/audit.jet +++ b/ui/views/audit.jet @@ -9,15 +9,25 @@