landed "manage communities" list on sidebox
This commit is contained in:
+67
-16
@@ -224,30 +224,77 @@ func JoinCommunityWithKey(ctxt ui.AmContext) (string, any) {
|
||||
return "redirect", fmt.Sprintf("/comm/%s/profile", comm.Alias)
|
||||
}
|
||||
|
||||
/* UnjoinCommunity starts the process of unjoining a community.
|
||||
/* ManageCommunities displays the current list of communities with unjoin buttons.
|
||||
* Parameters:
|
||||
* ctxt - The AmContext for the request.
|
||||
* Returns:
|
||||
* Command string dictating what to be rendered.
|
||||
* Data as a parameter for the command string.
|
||||
*/
|
||||
func UnjoinCommunity(ctxt ui.AmContext) (string, any) {
|
||||
me := ctxt.CurrentUser()
|
||||
comm := ctxt.CurrentCommunity() // set by middleware
|
||||
mbr, lock, _, err := comm.Membership(ctxt.Ctx(), me)
|
||||
func ManageCommunities(ctxt ui.AmContext) (string, any) {
|
||||
if ctxt.CurrentUser().IsAnon {
|
||||
return "redirect", "/"
|
||||
}
|
||||
|
||||
comms, err := database.AmGetCommunitiesForUser(ctxt.Ctx(), ctxt.CurrentUserId())
|
||||
if err != nil {
|
||||
return "error", err
|
||||
}
|
||||
if !mbr {
|
||||
// not a member, just redirect to profile
|
||||
return "redirect", fmt.Sprintf("/comm/%s/profile", comm.Alias)
|
||||
|
||||
canUnjoin := make([]bool, len(comms))
|
||||
for i, c := range comms {
|
||||
_, lock, _, err := c.Membership(ctxt.Ctx(), ctxt.CurrentUser())
|
||||
if err != nil {
|
||||
return "error", err
|
||||
}
|
||||
canUnjoin[i] = !lock
|
||||
}
|
||||
if lock {
|
||||
return "error", ENOUNJOIN
|
||||
|
||||
ctxt.VarMap().Set("communities", comms)
|
||||
ctxt.VarMap().Set("canUnjoin", canUnjoin)
|
||||
ctxt.SetFrameTitle("Your Communities")
|
||||
ctxt.SetLeftMenu("top")
|
||||
return "framed", "comlist.jet"
|
||||
}
|
||||
|
||||
/* UnjoinCommunity starts the process of unjoining a community. This is a meta-function which sets the return URL
|
||||
* based on its parameter.
|
||||
* Parameters:
|
||||
* uctx - Use context for the function:
|
||||
* prof - Return URL is to the community profile page.
|
||||
* manage - Return URL is to the "manage communities" page.
|
||||
* Returns:
|
||||
* Page function for unjoining a community.
|
||||
*/
|
||||
func UnjoinCommunity(uctx string) ui.AmPageFunc {
|
||||
var returnTemplate string
|
||||
switch uctx {
|
||||
case "prof":
|
||||
returnTemplate = "/comm/[A]/profile"
|
||||
case "manage":
|
||||
returnTemplate = "/manage_comm"
|
||||
default:
|
||||
panic(fmt.Sprintf("config error! uctx = %s", uctx))
|
||||
}
|
||||
return func(ctxt ui.AmContext) (string, any) {
|
||||
comm := ctxt.CurrentCommunity()
|
||||
returnURL := strings.ReplaceAll(returnTemplate, "[A]", comm.Alias)
|
||||
mbr, lock, _, err := comm.Membership(ctxt.Ctx(), ctxt.CurrentUser())
|
||||
if err != nil {
|
||||
return "error", err
|
||||
}
|
||||
if !mbr {
|
||||
// not a member, just redirect to profile
|
||||
return "redirect", returnURL
|
||||
}
|
||||
if lock {
|
||||
return "error", ENOUNJOIN
|
||||
}
|
||||
ctxt.VarMap().Set("comm", comm)
|
||||
ctxt.VarMap().Set("returnURL", returnURL)
|
||||
ctxt.SetFrameTitle("Unjoin Community")
|
||||
return "framed", "unjoin.jet"
|
||||
}
|
||||
ctxt.VarMap().Set("comm", comm)
|
||||
ctxt.SetFrameTitle("Unjoin Community")
|
||||
return "framed", "unjoin.jet"
|
||||
}
|
||||
|
||||
/* UnjoinCommunityConfirm finishes the process of unjoining a community.
|
||||
@@ -260,19 +307,23 @@ func UnjoinCommunity(ctxt ui.AmContext) (string, any) {
|
||||
func UnjoinCommunityConfirm(ctxt ui.AmContext) (string, any) {
|
||||
me := ctxt.CurrentUser()
|
||||
comm := ctxt.CurrentCommunity() // set by middleware
|
||||
returnURL := ctxt.FormField("returnURL")
|
||||
if returnURL == "" {
|
||||
returnURL = fmt.Sprintf("/comm/%s/profile", comm.Alias)
|
||||
}
|
||||
mbr, lock, _, err := comm.Membership(ctxt.Ctx(), me)
|
||||
if err != nil {
|
||||
return "error", err
|
||||
}
|
||||
if !mbr {
|
||||
// not a member, just redirect to profile
|
||||
return "redirect", fmt.Sprintf("/comm/%s/profile", comm.Alias)
|
||||
return "redirect", returnURL
|
||||
}
|
||||
if lock {
|
||||
return "error", ENOUNJOIN
|
||||
}
|
||||
if ctxt.FormFieldIsSet("cancel") {
|
||||
return "redirect", fmt.Sprintf("/comm/%s/profile", comm.Alias)
|
||||
return "redirect", returnURL
|
||||
}
|
||||
if ctxt.FormFieldIsSet("unjoin") {
|
||||
err = comm.SetMembership(ctxt.Ctx(), me, 0, false, me.Uid, ctxt.RemoteIP())
|
||||
@@ -280,7 +331,7 @@ func UnjoinCommunityConfirm(ctxt ui.AmContext) (string, any) {
|
||||
return "error", err
|
||||
}
|
||||
ctxt.ClearCommunityContext()
|
||||
return "redirect", fmt.Sprintf("/comm/%s/profile", comm.Alias)
|
||||
return "redirect", returnURL
|
||||
}
|
||||
return "error", EBUTTON
|
||||
}
|
||||
|
||||
@@ -199,10 +199,6 @@ func (c *Community) Membership(ctx context.Context, u *User) (bool, bool, uint16
|
||||
m := mbr.(*memberCacheData)
|
||||
return m.isMember, m.locked, m.level, nil
|
||||
}
|
||||
if AmTestPermission("Community.NoJoinRequired", u.BaseLevel) {
|
||||
// "no join required" - they are effectively a member, but don't cache that
|
||||
return true, false, u.BaseLevel, nil
|
||||
}
|
||||
row := amdb.QueryRowContext(ctx, "SELECT locked, granted_lvl FROM commmember WHERE commid = ? AND uid = ?", c.Id, u.Uid)
|
||||
var locked bool
|
||||
var level uint16
|
||||
@@ -212,6 +208,10 @@ func (c *Community) Membership(ctx context.Context, u *User) (bool, bool, uint16
|
||||
return true, locked, level, nil
|
||||
}
|
||||
if err == sql.ErrNoRows {
|
||||
if AmTestPermission("Community.NoJoinRequired", u.BaseLevel) {
|
||||
// "no join required" - they are effectively a member, but don't cache that
|
||||
return true, false, u.BaseLevel, nil
|
||||
}
|
||||
err = nil
|
||||
memberCache.Add(key, &memberCacheData{isMember: false, locked: false, level: uint16(0)})
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ _(italicized items can be deferred)_
|
||||
- ~~Post Filter User~~
|
||||
- ~~Post Move~~
|
||||
- ~~Post Publish~~
|
||||
- Manage Communities on communities sidebox
|
||||
- ~~Manage Communities on communities sidebox~~
|
||||
- ~~Conference Hotlist sidebox~~
|
||||
- ~~"New" flag on Conference Hotlist sidebox~~
|
||||
- ~~Manage on Conference Hotlist sidebox~~
|
||||
|
||||
@@ -75,6 +75,7 @@ func setupEcho() *echo.Echo {
|
||||
e.GET("/sysadmin", ui.AmWrap(SysAdminMenu))
|
||||
e.GET("/create_comm", ui.AmWrap(CreateCommunityForm))
|
||||
e.POST("/create_comm", ui.AmWrap(CreateCommunity))
|
||||
e.GET("/manage_comm", ui.AmWrap(ManageCommunities))
|
||||
e.POST("/attachment_upload", ui.AmWrap(AttachmentUpload))
|
||||
e.GET("/attachment/:post", ui.AmWrap(AttachmentSend))
|
||||
e.POST("/__invite_send", ui.AmWrap(InviteSend))
|
||||
@@ -86,7 +87,8 @@ func setupEcho() *echo.Echo {
|
||||
commGroup.GET("/profile", fn)
|
||||
commGroup.GET("/join", ui.AmWrap(JoinCommunity))
|
||||
commGroup.POST("/join", ui.AmWrap(JoinCommunityWithKey))
|
||||
commGroup.GET("/unjoin", ui.AmWrap(UnjoinCommunity))
|
||||
commGroup.GET("/unjoin", ui.AmWrap(UnjoinCommunity("prof")))
|
||||
commGroup.GET("/unj", ui.AmWrap(UnjoinCommunity("manage")))
|
||||
commGroup.POST("/unjoin", ui.AmWrap(UnjoinCommunityConfirm))
|
||||
commGroup.GET("/members", ui.AmWrap(MemberList))
|
||||
commGroup.POST("/members", ui.AmWrap(MemberSearch))
|
||||
|
||||
+3
-2
@@ -136,7 +136,8 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
||||
// expireTime is the expiration time sent in the dynamic headers.
|
||||
var expireTime string = lctime.Strftime("%c", time.Unix(1, 0))
|
||||
|
||||
type PageFunc func(AmContext) (string, any)
|
||||
// AmPageFunc is the definition for an Amsterdam "page function" that handles most of the work and defers to the wrapper for rendering.
|
||||
type AmPageFunc func(AmContext) (string, any)
|
||||
|
||||
/* AmWrap wraps the Amsterdam handler function in a wrapper that implements the spec for
|
||||
* Echo handler functions.
|
||||
@@ -145,7 +146,7 @@ type PageFunc func(AmContext) (string, any)
|
||||
* Returns:
|
||||
* The wrapped function.
|
||||
*/
|
||||
func AmWrap(myfunc PageFunc) echo.HandlerFunc {
|
||||
func AmWrap(myfunc AmPageFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
ctxt := AmContextFromEchoContext(c)
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
{*
|
||||
* Amsterdam Web Communities System
|
||||
* Copyright (c) 2025-2026 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/.
|
||||
*}
|
||||
<div class="p-4">
|
||||
<!-- Page Title -->
|
||||
<div class="mb-6">
|
||||
<h1 class="text-blue-800 text-4xl font-bold">Your Communities</h1>
|
||||
<hr class="border-2 border-gray-400 w-4/5 mt-2 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="/">
|
||||
<span>←</span>
|
||||
Return to Front Page
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-1 gap-1 mb-6">
|
||||
{{ range i, c := communities }}
|
||||
<div class="flex items-start gap-1">
|
||||
<span class="text-sm pt-0.5">🟣</span>
|
||||
<a href="/comm/{{ c.Alias }}/profile" class="text-blue-700 hover:text-blue-900">{{ c.Name }}</a>
|
||||
{{ if canUnjoin[i] }}
|
||||
<a href="/comm/{{ c.Alias }}/unj" class="hover:scale-125 inline-block transition-transform" title="Unjoin">🗙</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
<!-- Information Note -->
|
||||
<div class="mt-6 p-4 bg-blue-50 border-l-4 border-blue-400">
|
||||
<p class="text-sm text-gray-700">
|
||||
<strong>Note:</strong> Click on the 🗙 symbol to unjoin a community. You will lose access to that
|
||||
community's resources and discussions.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -31,7 +31,7 @@
|
||||
<span class="text-black text-xs font-bold">
|
||||
[
|
||||
{{ if sb.Flags["canManage"] }}
|
||||
<a href="/TODO/manage_comms" class="text-blue-700 hover:text-blue-900">Manage</a>
|
||||
<a href="/manage_comm" class="text-blue-700 hover:text-blue-900">Manage</a>
|
||||
{{ if sb.Flags["canCreate"] }}|{{ end }}
|
||||
{{ end }}
|
||||
{{ if sb.Flags["canCreate"] }}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<!-- Action Buttons -->
|
||||
<div class="flex gap-4 justify-center">
|
||||
<form method="POST" action="/comm/{{ comm.Alias }}/unjoin">
|
||||
<input type="hidden" name="returnURL" value="{{ returnURL }}">
|
||||
<button type="submit" name="cancel"
|
||||
class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded font-medium transition-colors">✗ Cancel</button>
|
||||
<button type="submit" name="unjoin"
|
||||
|
||||
Reference in New Issue
Block a user