resolve bugs in community profile display

This commit is contained in:
2025-10-17 11:53:30 -06:00
parent 65c739dc57
commit 137bf35a8b
9 changed files with 40 additions and 17 deletions
+10 -1
View File
@@ -43,6 +43,7 @@ type AmContext interface {
Globals() *database.Globals
GlobalFlags() *util.OptionSet
IsMember() bool
IsMemberLocked() bool
LeftMenu() string
RC() int
OutputType() string
@@ -79,6 +80,7 @@ type amContext struct {
effectiveLevel uint16
community *database.Community
isMember bool
isMemberLocked bool
}
// ClearLoginCookie overwrites and removes the login cookie.
@@ -186,6 +188,11 @@ func (c *amContext) IsMember() bool {
return c.isMember
}
// IsMemberLocked returns true if the user is a "locked" member of the currentr community (cannot unjoin).
func (c *amContext) IsMemberLocked() bool {
return c.isMemberLocked
}
// LeftMenu returns the current left menu selector.
func (c *amContext) LeftMenu() string {
return c.session.Values["leftMenu"].(string)
@@ -272,12 +279,13 @@ func (c *amContext) SetCommunityContext(param string) error {
if err != nil {
return err
}
mbr, _, level, err := comm.Membership(c.CurrentUser())
mbr, lock, level, err := comm.Membership(c.CurrentUser())
if err != nil {
return err
}
c.community = comm
c.isMember = mbr
c.isMemberLocked = lock
if level > c.effectiveLevel {
c.effectiveLevel = level
}
@@ -454,6 +462,7 @@ func contextRecycler(incoming chan *amContext, done chan bool) {
c.effectiveLevel = 0
c.community = nil
c.isMember = false
c.isMemberLocked = false
freeContext.Put(c)
}
done <- true
+4
View File
@@ -14,6 +14,7 @@ import (
"bytes"
"embed"
"errors"
"fmt"
"image"
"image/gif"
"image/jpeg"
@@ -85,6 +86,9 @@ func AmServeImage(ctxt AmContext) (string, any, error) {
}
}
ctxt.SetRC(http.StatusNotFound)
if err == nil {
err = fmt.Errorf("image not found: %s", ctxt.URLPath())
}
return ErrorPage(ctxt, err)
}
+8 -7
View File
@@ -135,10 +135,18 @@ func AmBuildCommunityMenu(comm *database.Community) (*MenuDefinition, error) {
return a.LinkSequence - b.LinkSequence
})
mia := make([]MenuItem, len(sdef))
md := MenuDefinition{
ID: "community",
Title: comm.Name,
PermSet: "community",
Tag: "community",
Items: mia,
}
for i, sd := range sdef {
mia[i].Text = sd.Title
mia[i].Link = strings.ReplaceAll(sd.Link, "[CID]", comm.Alias)
mia[i].Disabled = false
mia[i].P = &md
if sd.RequirePermission == "" {
if sd.RequireRole == "" {
mia[i].Permission = ""
@@ -156,13 +164,6 @@ func AmBuildCommunityMenu(comm *database.Community) (*MenuDefinition, error) {
mia[i].Permission = fmt.Sprintf("%d", v1)
}
}
md := MenuDefinition{
ID: "community",
Title: comm.Name,
PermSet: "community",
Items: mia,
Tag: "community",
}
menuCache.Add(comm.Id, &md)
return &md, nil
}
+3
View File
@@ -69,6 +69,9 @@ func sendPageData(ctxt echo.Context, amctxt AmContext, command string, data any)
* Standard Go error status.
*/
func ErrorPage(ctxt AmContext, input_err error) (string, any, error) {
if input_err == nil {
log.Error("ErrorPage called with nil input error, WTF?")
}
ctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error")
ctxt.VarMap().Set("error", input_err.Error())
return "framed_template", "error.jet", nil
+2 -2
View File
@@ -19,7 +19,7 @@
<!-- Left Column: Image and Metadata -->
<div class="flex-shrink-0 w-32">
<div class="border-2 border-gray-300 rounded mb-4">
<img src="/img/static/default-community.jpg"
<img src="/img/builtin/default-community.jpg"
alt="{{ commName}} community logo" class="w-full h-auto">
</div>
<div class="text-xs text-gray-700 space-y-2 mb-4">
@@ -79,7 +79,7 @@
<!-- Host -->
<div>
<strong>Host:</strong>
<a href="/users/{{ hostName }}" class="text-blue-700 hover:text-blue-900">{{ hostName }}</a>
<a href="/user/{{ hostName }}" class="text-blue-700 hover:text-blue-900">{{ hostName }}</a>
</div>
<!-- Location -->
+4 -4
View File
@@ -20,12 +20,12 @@
{{ if .Disabled }}
<div class="text-gray-500 mb-1">{{ .Text }}</div>
{{ else }}
<a href="{{ .Link }}" class="text-blue-700 hover:text-blue-900">{{ .Text }}</a>
<div class="mb-1"><a href="{{ .Link }}" class="text-blue-700 hover:text-blue-900">{{ .Text }}</a></div>
{{ end }}
{{ end }}
{{ end }}
{{ if .IsMember() }}
<div class="mb-1">&nbsp;</div>
<div class="mb-1"><a href="/TODO/comm/{{ comm.Alias }}/unjoin">Unjoin</a></div>
{{ 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>
{{ end }}
</div>