landed publishing post to front page
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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~~
|
||||
|
||||
@@ -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))
|
||||
|
||||
+1
-1
@@ -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</a>
|
||||
{{ end }}
|
||||
{{ if canPublish }}
|
||||
<a href="/TODO"
|
||||
<a href="{{ topicListLink }}/op/{{ topicNum }}/publish/{{ p.Num }}"
|
||||
class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium transition-colors whitespace-nowrap">Publish</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user