From 53845bf6b1f7164c81e02f0cf66b046cc84efff6 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Fri, 30 Jan 2026 15:09:19 -0700 Subject: [PATCH] landed publishing post to front page --- conference_ops.go | 32 ++++++++++++++++++++++++++++++++ database/post.go | 41 +++++++++++++++++++++++++++++++++++++++++ docs/MISSINGFUNCS.md | 2 +- main.go | 1 + ui/views/posts.jet | 2 +- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/conference_ops.go b/conference_ops.go index 140529b..05dbb6f 100644 --- a/conference_ops.go +++ b/conference_ops.go @@ -466,6 +466,38 @@ func MoveMessageForm(ctxt ui.AmContext) (string, any, error) { return "framed_template", "move_message.jet", nil } +/* PublishMessage publishes a message to the front page. + * 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 PublishMessage(ctxt ui.AmContext) (string, any, error) { + if !ctxt.TestPermission("Global.PublishFP") { + ctxt.SetRC(http.StatusForbidden) + return ui.ErrorPage(ctxt, ENOPERM) + } + comm := ctxt.CurrentCommunity() + topic := ctxt.GetScratch("currentTopic").(*database.Topic) + msgNum, err := strconv.Atoi(ctxt.URLParam("msg")) + if err != nil { + return ui.ErrorPage(ctxt, err) + } + hdrs, err := database.AmGetPostRange(ctxt.Ctx(), topic, int32(msgNum), int32(msgNum)) + if err != nil { + return ui.ErrorPage(ctxt, err) + } else if len(hdrs) != 1 { + return ui.ErrorPage(ctxt, errors.New("internal error getting post reference")) + } + + if err = hdrs[0].Publish(ctxt.Ctx(), comm, ctxt.CurrentUser(), ctxt.RemoteIP()); err != nil { + return ui.ErrorPage(ctxt, err) + } + return "redirect", fmt.Sprintf("/comm/%s/conf/%s/r/%d?r=%d&ac=1", ctxt.CurrentCommunity().Alias, ctxt.GetScratch("currentAlias"), topic.Number, hdrs[0].Num), nil +} + /* MoveMessage moves a message to a different topic. * Parameters: * ctxt - The AmContext for the request. diff --git a/database/post.go b/database/post.go index 455275f..50c8277 100644 --- a/database/post.go +++ b/database/post.go @@ -410,6 +410,47 @@ func (p *PostHeader) Nuke(ctx context.Context, u *User, ipaddr string) error { return nil } +// Publish publishes this message to the front page. +func (p *PostHeader) Publish(ctx context.Context, comm *Community, publisher *User, ipaddr string) error { + if p.ScribbleDate != nil && p.ScribbleUid != nil { + return errors.New("cannot publish scribbled post") + } + + var ar *AuditRecord = nil + defer func() { + AmStoreAudit(ar) + }() + success := false + tx := amdb.MustBegin() + defer func() { + if !success { + tx.Rollback() + } + }() + + // Check if we were already published. + row := tx.QueryRowContext(ctx, "SELECT by_uid FROM postpublish WHERE postid = ?", p.PostId) + var tmp int32 + err := row.Scan(&tmp) + if err == nil { + return errors.New("post already published") + } else if err != sql.ErrNoRows { + return err + } + + // Publish it! + if _, err = tx.ExecContext(ctx, "INSERT INTO postpublish (commid, postid, by_uid, on_date) VALUES (?, ?, ?, NOW())", + comm.Id, p.PostId, publisher.Uid); err != nil { + return err + } + if err = tx.Commit(); err != nil { + return err + } + success = true + ar = AmNewAudit(AuditPublishToFrontPage, publisher.Uid, ipaddr, fmt.Sprintf("comm=%d,post=%d", comm.Id, p.PostId)) + return nil +} + // MoveTo moves this message to a new topic. func (p *PostHeader) MoveTo(ctx context.Context, target *Topic, u *User, ipaddr string) error { if target.TopicId == p.TopicId { diff --git a/docs/MISSINGFUNCS.md b/docs/MISSINGFUNCS.md index dcdf17c..c987559 100644 --- a/docs/MISSINGFUNCS.md +++ b/docs/MISSINGFUNCS.md @@ -44,7 +44,7 @@ _(italicized items can be deferred)_ - ~~Post Nuke~~ - ~~Post Filter User~~ - ~~Post Move~~ - - Post Publish + - ~~Post Publish~~ - Manage Communities on communities sidebox - ~~Conference Hotlist sidebox~~ - ~~"New" flag on Conference Hotlist sidebox~~ diff --git a/main.go b/main.go index add5605..cb2896a 100644 --- a/main.go +++ b/main.go @@ -116,6 +116,7 @@ func setupEcho() *echo.Echo { opsGroup.GET("/hide/:msg", ui.AmWrap(HideMessage)) opsGroup.GET("/scribble/:msg", ui.AmWrap(ScribbleMessage)) opsGroup.GET("/nuke/:msg", ui.AmWrap(NukeMessage)) + opsGroup.GET("/publish/:msg", ui.AmWrap(PublishMessage)) opsGroup.GET("/move/:msg", ui.AmWrap(MoveMessageForm)) opsGroup.POST("/move/:msg", ui.AmWrap(MoveMessage)) opsGroup.GET("/manage", ui.AmWrap(TopicManage)) diff --git a/ui/views/posts.jet b/ui/views/posts.jet index a0f185a..f4e4c37 100644 --- a/ui/views/posts.jet +++ b/ui/views/posts.jet @@ -144,7 +144,7 @@ class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Move {{ end }} {{ if canPublish }} - Publish {{ end }}