implemented the community admin menu and necessary tweaks to the menu system

This commit is contained in:
2025-10-17 15:57:12 -06:00
parent 7a755aac77
commit 8e80176022
9 changed files with 131 additions and 11 deletions
+50
View File
@@ -0,0 +1,50 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
// Package main contains the high-level Amsterdam logic.
package main
import (
"errors"
"net/http"
"git.erbosoft.com/amy/amsterdam/database"
"git.erbosoft.com/amy/amsterdam/ui"
)
/* CommunityAdminMenu renders the community administration menu.
* 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 CommunityAdminMenu(ctxt ui.AmContext) (string, any, error) {
err := ctxt.SetCommunityContext(ctxt.URLParam("cid"))
if err != nil {
ctxt.SetRC(http.StatusNotFound)
return ui.ErrorPage(ctxt, err)
}
comm := ctxt.CurrentCommunity()
if !comm.TestPermission("Community.ShowAdmin", ctxt.EffectiveLevel()) {
ctxt.SetRC(http.StatusForbidden)
return ui.ErrorPage(ctxt, errors.New("you are not permitted to access this page"))
}
menu := ui.AmMenu("communityadmin")
defs := make(map[string]bool)
if !ctxt.GlobalFlags().Get(database.GlobalFlagNoCategories) {
defs["USECAT"] = true
}
ctxt.SetLeftMenu("community")
ctxt.VarMap().Set("menu", menu.FilterCommunity(comm))
ctxt.VarMap().Set("defs", defs)
ctxt.VarMap().Set("amsterdam_pageTitle", menu.Title+" - "+comm.Name)
return "framed_template", "menu.jet", nil
}
+2
View File
@@ -184,3 +184,5 @@ permissions:
role: "Community.AnyAdmin"
- name: "Community.MassMail"
role: "Community.AnyAdmin"
- name: "Community.Destroy"
role: "Community.Host"
+1 -1
View File
@@ -25,7 +25,7 @@ domains:
requirePermission: "Community.Read"
requireRole: "Community.AnyAdmin"
linkSequence: 5000
link: "/TODO/comm/[CID]/admin"
link: "/comm/[CID]/admin"
title: "Administration"
- id: "SysAdmin"
index: 2
+1
View File
@@ -65,6 +65,7 @@ func setupEcho() *echo.Echo {
e.POST("/quick_email", ui.AmWrap(QuickEMail))
e.GET("/sysadmin", ui.AmWrap(SysAdminMenu))
e.GET("/comm/:cid/profile", ui.AmWrap(ShowCommunity))
e.GET("/comm/:cid/admin", ui.AmWrap(CommunityAdminMenu))
return e
}
+1
View File
@@ -34,6 +34,7 @@ func SysAdminMenu(ctxt ui.AmContext) (string, any, error) {
}
menu := ui.AmMenu("sysadmin")
ctxt.VarMap().Set("menu", menu)
ctxt.VarMap().Set("defs", make(map[string]bool))
ctxt.VarMap().Set("amsterdam_pageTitle", menu.Title)
return "framed_template", "menu.jet", nil
}
+32
View File
@@ -52,3 +52,35 @@ menudefs:
- text: "Import User Accounts"
link: "/TODO/sysadmin/import"
permission: "Global.SysAdminAccess"
- id: "communityadmin"
title: "Community Administration"
subtitle: "[CNAME]"
permSet: "community"
warning: >
<strong>Note:</strong> These tools provide access to sensitive administrative features for the
community. Use with care and review all changes before applying them to the community.
items:
- text: "Community Profile"
link: "/TODO/comm/[CID]/admin/profile"
permission: "Community.ShowAdmin"
- text: "Set Community Category"
link: "/TODO/comm/[CID]/admin/category"
permission: "Community.ShowAdmin"
ifdef: "USECAT"
- text: "Set Community Services"
link: "/TODO/comm/[CID]/admin/services"
permission: "Community.ShowAdmin"
disabled: true
- text: "Membership Control"
link: "/TODO/comm/[CID]/admin/members"
permission: "Community.ShowAdmin"
- text: "E-Mail to All Members"
link: "/TODO/comm/[CID]/admin/massmail"
permission: "Community.MassMail"
- text: "Display Audit Records"
link: "/TODO/comm/[CID]/admin/audit"
permission: "Community.ShowAdmin"
- text: "Delete Community"
link: "/TODO/comm/[CID]/admin/delete"
permission: "Community.Destroy"
hazard: true
+32 -6
View File
@@ -28,7 +28,9 @@ type MenuItem struct {
Text string `yaml:"text"`
Link string `yaml:"link"`
Disabled bool `yaml:"disabled"`
Hazard bool `yaml:"hazard"`
Permission string `yaml:"permission"`
Ifdef string `yaml:"ifdef"`
P *MenuDefinition
}
@@ -63,12 +65,36 @@ func (mi *MenuItem) Show(ctxt AmContext) bool {
// MenuDefinition represents a full menu definition.
type MenuDefinition struct {
ID string `yaml:"id"`
Title string `yaml:"title"`
PermSet string `yaml:"permSet"`
Warning string `yaml:"warning"`
Items []MenuItem `yaml:"items"`
Tag string
ID string `yaml:"id"`
Title string `yaml:"title"`
Subtitle string `yaml:"subtitle"`
PermSet string `yaml:"permSet"`
Warning string `yaml:"warning"`
Items []MenuItem `yaml:"items"`
Tag string
}
// FilterCommunity creates a copy of this menu filtered to the specified community.
func (mdef *MenuDefinition) FilterCommunity(comm *database.Community) *MenuDefinition {
newmd := MenuDefinition{
ID: mdef.ID,
Title: mdef.Title,
Subtitle: strings.ReplaceAll(mdef.Subtitle, "[CNAME]", comm.Name),
PermSet: mdef.PermSet,
Warning: mdef.Warning,
Items: make([]MenuItem, len(mdef.Items)),
Tag: mdef.Tag,
}
for i, it := range mdef.Items {
newmd.Items[i].Text = it.Text
newmd.Items[i].Link = strings.ReplaceAll(it.Link, "[CID]", comm.Alias)
newmd.Items[i].Disabled = it.Disabled
newmd.Items[i].Hazard = it.Hazard
newmd.Items[i].Permission = it.Permission
newmd.Items[i].Ifdef = it.Ifdef
newmd.Items[i].P = &newmd
}
return &newmd
}
// MenuDefs represents the set of all menu definitions.
+11 -2
View File
@@ -10,6 +10,9 @@
<!-- Page Title -->
<div class="mb-6">
<h1 class="text-blue-800 text-4xl font-bold mb-2">{{ menu.Title }}</h1>
{{ if menu.Subtitle != "" }}
<span class="text-blue-800 text-2xl font-bold ml-2">{{ menu.Subtitle }}</span>
{{ end }}
<hr class="border-2 border-gray-400 w-4/5 mb-4">
</div>
@@ -19,13 +22,19 @@
<nav class="space-y-3">
{{ ctxt := . }}
{{ range menu.Items }}
{{ if .Show(ctxt) }}
{{ vis := true }}
{{ if .Ifdef != "" && !defs[.Ifdef] }}{{ vis = false }}{{ end }}
{{ if vis && .Show(ctxt) }}
<div class="flex items-start gap-3">
<span class="text-lg pt-0.5">🟣</span>
{{ if .Disabled }}
<span class="text-gray-500 font-medium">{{ .Text }}</span>
{{ else }}
<a href="{{ .Link }}" class="text-blue-700 hover:text-blue-900 font-medium">{{ .Text }}</a>
{{ if .Hazard }}
<a href="{{ .Link }}" class="text-red-700 hover:text-red-900 font-medium">⚠️ {{ .Text }}</a>
{{ else }}
<a href="{{ .Link }}" class="text-blue-700 hover:text-blue-900 font-medium">{{ .Text }}</a>
{{ end }}
{{ end }}
</div>
{{ end }}
+1 -2
View File
@@ -25,7 +25,6 @@
{{ end }}
{{ end }}
{{ if .IsMember() && !.IsMemberLocked() }}
<div class="mb-1">&nbsp;</div>
<div class="mb-1"><a href="/TODO/comm/{{ comm.Alias }}/unjoin" class="text-blue-700 hover:text-blue-900">Unjoin</a></div>
<div class="mb-1"><a href="/TODO/comm/{{ comm.Alias }}/unjoin" class="text-red-700 hover:text-red-900">⚠️ Unjoin</a></div>
{{ end }}
</div>