landed display of community audit records

This commit is contained in:
2026-02-21 23:18:11 -07:00
parent f9978918d8
commit 8dcfa79983
6 changed files with 93 additions and 6 deletions
+74
View File
@@ -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.
+1 -1
View File
@@ -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_
+1
View File
@@ -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))
+2
View File
@@ -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)
+1 -1
View File
@@ -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"
+14 -4
View File
@@ -9,15 +9,25 @@
<div class="p-4">
<!-- Page Title -->
<div class="mb-6">
<h1 class="text-blue-800 text-4xl font-bold mb-2">System Audit Records</h1>
<h1 class="text-blue-800 text-4xl font-bold mb-2">
{{ if isset(commName) }}
Audit Records for Community "{{ commName }}"
{{ else }}
System Audit Records
{{ end }}
</h1>
<hr class="border-2 border-gray-400 w-4/5 mb-6">
</div>
<!-- Backlink -->
<div class="mb-4">
<a class="text-blue-700 hover:text-blue-900 text-sm flex items-center gap-2 w-fit" href="/sysadmin">
<a class="text-blue-700 hover:text-blue-900 text-sm flex items-center gap-2 w-fit" href="{{ backLink }}">
<span>←</span>
Return to System Administration Menu
{{ if isset(commName) }}
Return to Community Administration Menu
{{ else }}
Return to System Administration Menu
{{ end }}
</a>
</div>
@@ -62,7 +72,7 @@
{{ if isset(showPrev) || isset(showNext) }}
<!-- Bottom Navigation -->
<div class="flex justify-end mt-6">
<form method="POST" action="/sysadmin/audit">
<form method="POST" action="{{ selfLink }}">
<input type="hidden" name="ofs" value="{{ ofs }}"/>
{{ if isset(showPrev) }}
<button type="submit" name="prev"