landed display of community audit records
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user