fix(17): WR-04 resolve journal-post only for published posts
journal-post resolved any post by id, so a menu entry or sitemap row pointing at a draft or future post published its title and slug on the anonymous menu API and in sitemap.xml. resolvePost now applies the published filter; the reference list still offers drafts so editors can wire a menu before the post goes live.
This commit is contained in:
@@ -65,7 +65,11 @@ var (
|
||||
// - all-journal-categories: a list without a URL of its own whose items are
|
||||
// every category ordered by name.
|
||||
// - journal-post: one post picked by id (References lists every post by
|
||||
// title); it resolves to the post's URL without a published filter.
|
||||
// title, drafts included, so a menu can be wired before the post goes
|
||||
// live); it resolves to the post's URL only while the post is published
|
||||
// with a past publish date, else to nothing. PHP resolved any post, but
|
||||
// its result now reaches the anonymous menu API and sitemap.xml, so a
|
||||
// draft's title and slug would leak.
|
||||
// - all-journal-posts: a list whose items are the published posts ordered
|
||||
// by title.
|
||||
// - category-journal-posts: a list whose items are the published posts of
|
||||
@@ -185,7 +189,8 @@ func (m menuTypes) postReferences(ctx context.Context) ([]pact.MenuItemReference
|
||||
}
|
||||
|
||||
// resolvePost resolves one journal-post item. An unknown or missing
|
||||
// reference resolves to nothing, as PHP returned null.
|
||||
// reference resolves to nothing, as PHP returned null, and so does a post
|
||||
// that is not published (publishedPosts).
|
||||
func (m menuTypes) resolvePost(ctx context.Context, in pact.MenuItemResolve) (*pact.ResolvedMenuItem, error) {
|
||||
id, ok := menuReferenceID(in.Reference)
|
||||
if !ok {
|
||||
@@ -196,7 +201,7 @@ func (m menuTypes) resolvePost(ctx context.Context, in pact.MenuItemResolve) (*p
|
||||
return nil, err
|
||||
}
|
||||
var posts []models.Post
|
||||
if err := db.Where("id = ?", id).Limit(1).Find(&posts).Error; err != nil {
|
||||
if err := publishedPosts(db).Where("id = ?", id).Limit(1).Find(&posts).Error; err != nil {
|
||||
return nil, fmt.Errorf("golem15.journal: menu item post %d: %w", id, err)
|
||||
}
|
||||
if len(posts) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user