diff --git a/invites.go b/invites.go new file mode 100644 index 0000000..1804915 --- /dev/null +++ b/invites.go @@ -0,0 +1,93 @@ +/* + * 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/. + */ +// Package main contains the high-level Amsterdam logic. +package main + +import ( + "fmt" + "net/http" + + "git.erbosoft.com/amy/amsterdam/database" + "git.erbosoft.com/amy/amsterdam/ui" +) + +/* InviteToCommunity displays the community invitation form. + * 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 InviteToCommunity(ctxt ui.AmContext) (string, any, error) { + if ctxt.CurrentUser().IsAnon { + ctxt.SetRC(http.StatusForbidden) + return ui.ErrorPage(ctxt, ENOPERM) + } + comm := ctxt.CurrentCommunity() + + ctxt.VarMap().Set("amsterdam_pageTitle", "Send Invitation") + ctxt.VarMap().Set("title", "Send Community Invitation") + ctxt.VarMap().Set("subtitle", comm.Name) + ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/profile", comm.Alias)) + ctxt.VarMap().Set("cid", fmt.Sprintf("%d", comm.Id)) + return "framed_template", "invite.jet", nil +} + +/* InviteToConference displays the conference invitation form. + * 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 InviteToConference(ctxt ui.AmContext) (string, any, error) { + if ctxt.CurrentUser().IsAnon { + ctxt.SetRC(http.StatusForbidden) + return ui.ErrorPage(ctxt, ENOPERM) + } + comm := ctxt.CurrentCommunity() + conf := ctxt.GetScratch("currentConference").(*database.Conference) + + ctxt.VarMap().Set("amsterdam_pageTitle", "Send Invitation") + ctxt.VarMap().Set("title", "Send Conference Invitation") + ctxt.VarMap().Set("subtitle", conf.Name) + ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.GetScratch("currentAlias"))) + ctxt.VarMap().Set("cid", fmt.Sprintf("%d", comm.Id)) + ctxt.VarMap().Set("confid", fmt.Sprintf("%d", conf.ConfId)) + return "framed_template", "invite.jet", nil +} + +/* InviteToTopic displays the topic invitation form. + * 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 InviteToTopic(ctxt ui.AmContext) (string, any, error) { + if ctxt.CurrentUser().IsAnon { + ctxt.SetRC(http.StatusForbidden) + return ui.ErrorPage(ctxt, ENOPERM) + } + comm := ctxt.CurrentCommunity() + conf := ctxt.GetScratch("currentConference").(*database.Conference) + topic := ctxt.GetScratch("currentTopic").(*database.Topic) + + ctxt.VarMap().Set("amsterdam_pageTitle", "Send Invitation") + ctxt.VarMap().Set("title", "Send Topic Invitation") + ctxt.VarMap().Set("subtitle", topic.Name) + ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/conf/%s/r/%d", comm.Alias, ctxt.GetScratch("currentAlias"), topic.Number)) + ctxt.VarMap().Set("cid", fmt.Sprintf("%d", comm.Id)) + ctxt.VarMap().Set("confid", fmt.Sprintf("%d", conf.ConfId)) + ctxt.VarMap().Set("topicid", fmt.Sprintf("%d", topic.TopicId)) + return "framed_template", "invite.jet", nil +} diff --git a/main.go b/main.go index a77f800..fcccce0 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,7 @@ func setupEcho() *echo.Echo { commGroup.POST("/unjoin", ui.AmWrap(UnjoinCommunityConfirm)) commGroup.GET("/members", ui.AmWrap(MemberList)) commGroup.POST("/members", ui.AmWrap(MemberSearch)) + commGroup.GET("/invite", ui.AmWrap(InviteToCommunity)) commGroup.GET("/admin", ui.AmWrap(CommunityAdminMenu)) commGroup.GET("/admin/profile", ui.AmWrap(CommunityProfileForm)) commGroup.POST("/admin/profile", ui.AmWrap(EditCommunityProfile)) @@ -103,6 +104,7 @@ func setupEcho() *echo.Echo { confGroup.POST("/new_topic", ui.AmWrap(NewTopic)) confGroup.GET("/manage", ui.AmWrap(ConfManage)) confGroup.GET("/hotlist", ui.AmWrap(AddToHotlist)) + confGroup.GET("/invite", ui.AmWrap(InviteToConference)) confGroup.GET("/r/:topic", ui.AmWrap(ReadPosts), ui.SetTopic) confGroup.POST("/r/:topic", ui.AmWrap(PostInTopic), ui.SetTopic) opsGroup := confGroup.Group("/op/:topic", ui.SetTopic) @@ -117,6 +119,7 @@ func setupEcho() *echo.Echo { opsGroup.POST("/move/:msg", ui.AmWrap(MoveMessage)) opsGroup.GET("/manage", ui.AmWrap(TopicManage)) opsGroup.GET("/subscribe", ui.AmWrap(TopicSetSubscribe)) + opsGroup.GET("/invite", ui.AmWrap(InviteToTopic)) opsGroup.GET("/rmbozo/:uid", ui.AmWrap(TopicRemoveBozo)) return e diff --git a/ui/views/comprofile.jet b/ui/views/comprofile.jet index 07cbce9..41c0019 100644 --- a/ui/views/comprofile.jet +++ b/ui/views/comprofile.jet @@ -41,7 +41,7 @@ {{ end }} {{ if isset(canInvite) }}