From e08ca22f57d3d92941fd2ba7ef5cd7b7d157198d Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Mon, 13 Oct 2025 21:44:14 -0600 Subject: [PATCH] landed the sysadmin menu page, and the code to render menus as full-page --- main.go | 1 + sysadmin.go | 39 +++++++++++++++++++++++++++++++++++++++ ui/menudefs.yaml | 28 +++++++++++++++++++++++++++- ui/menus.go | 2 ++ ui/views/menu.jet | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 sysadmin.go create mode 100644 ui/views/menu.jet diff --git a/main.go b/main.go index 7fcff4b..8b6647c 100644 --- a/main.go +++ b/main.go @@ -58,6 +58,7 @@ func setupEcho() *echo.Echo { e.POST("/profile_photo", ui.AmWrap(ProfilePhoto)) e.GET("/user/:uname", ui.AmWrap(ShowProfile)) e.POST("/quick_email", ui.AmWrap(QuickEMail)) + e.GET("/sysadmin", ui.AmWrap(SysAdminMenu)) return e } diff --git a/sysadmin.go b/sysadmin.go new file mode 100644 index 0000000..5269a9f --- /dev/null +++ b/sysadmin.go @@ -0,0 +1,39 @@ +/* + * 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" +) + +/* SysAdminMenu renders the system 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 SysAdminMenu(ctxt ui.AmContext) (string, any, error) { + u := ctxt.CurrentUser() + if !database.AmTestPermission("Global.SysAdminAccess", u.BaseLevel) { + ctxt.SetRC(http.StatusForbidden) + return ui.ErrorPage(ctxt, errors.New("you are not authorized access to this page")) + } + menu := ui.AmMenu("sysadmin") + ctxt.VarMap().Set("menu", menu) + ctxt.VarMap().Set("amsterdam_pageTitle", menu.Title) + return "framed_template", "menu.jet", nil +} diff --git a/ui/menudefs.yaml b/ui/menudefs.yaml index 659b203..15adb0a 100644 --- a/ui/menudefs.yaml +++ b/ui/menudefs.yaml @@ -27,5 +27,31 @@ menudefs: - text: "About Amsterdam" link: "/about" - text: "System Administration" - link: "/TODO/sysadmin" + link: "/sysadmin" + permission: "Global.SysAdminAccess" + - id: "sysadmin" + title: "System Administration" + permSet: "user" + warning: > + Note: These tools provide access to sensitive system administration functions. + Use with care and review all changes before applying them to the system. + items: + - text: "Edit Global Properties" + link: "/TODO/sysadmin/global" + permission: "Global.SysAdminAccess" + - text: "View/Edit IP Address Bans" + link: "/TODO/sysadmin/ip_bans" + permission: "Global.SysAdminAccess" + - text: "View/Edit Banned Users" + link: "/TODO/sysadmin/user_bans" + disabled: true + permission: "Global.SysAdminAccess" + - text: "User Account Management" + link: "/TODO/sysadmin/find_user" + permission: "Global.SysAdminAccess" + - text: "System Audit Logs" + link: "/TODO/sysadmin/audit" + permission: "Global.SysAdminAccess" + - text: "Import User Accounts" + link: "/TODO/sysadmin/import" permission: "Global.SysAdminAccess" diff --git a/ui/menus.go b/ui/menus.go index e04b185..8cc1aa0 100644 --- a/ui/menus.go +++ b/ui/menus.go @@ -25,6 +25,7 @@ type MenuItem struct { P *MenuDefinition } +// Show checks permissions to see if we can display the menu item. func (mi *MenuItem) Show(ctxt AmContext) bool { if mi.Permission == "" { return true @@ -45,6 +46,7 @@ type MenuDefinition struct { ID string `yaml:"id"` Title string `yaml:"title"` PermSet string `yaml:"permSet"` + Warning string `yaml:"warning"` Items []MenuItem `yaml:"items"` } diff --git a/ui/views/menu.jet b/ui/views/menu.jet new file mode 100644 index 0000000..a8794f9 --- /dev/null +++ b/ui/views/menu.jet @@ -0,0 +1,42 @@ +{* + * 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/. + *} +
+ +
+

{{ menu.Title }}

+
+
+ + +
+
+ +
+ + {{ if menu.Warning != "" }} +
+

{{ menu.Warning | raw }}

+
+ {{ end }} +
+