From 1a3e43a12f5a9559571108f9a88aae172b4c1a83 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 22 Dec 2024 23:44:51 +0800 Subject: [PATCH] :bug: Fix editing post got rejected --- pkg/internal/http/api/articles_api.go | 4 +++- pkg/internal/http/api/stories_api.go | 4 +++- pkg/internal/services/posts.go | 3 --- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/internal/http/api/articles_api.go b/pkg/internal/http/api/articles_api.go index 8beab65..fd77a39 100644 --- a/pkg/internal/http/api/articles_api.go +++ b/pkg/internal/http/api/articles_api.go @@ -179,13 +179,15 @@ func editArticle(c *fiber.Ctx) error { item.Categories = data.Categories item.IsDraft = data.IsDraft item.PublishedUntil = data.PublishedUntil - item.PublishedAt = data.PublishedAt item.VisibleUsers = data.VisibleUsers item.InvisibleUsers = data.InvisibleUsers // Preload publisher data item.Publisher = publisher + if item.PublishedAt == nil { + item.PublishedAt = data.PublishedAt + } if data.Visibility != nil { item.Visibility = *data.Visibility } diff --git a/pkg/internal/http/api/stories_api.go b/pkg/internal/http/api/stories_api.go index a873f2f..158d5c9 100644 --- a/pkg/internal/http/api/stories_api.go +++ b/pkg/internal/http/api/stories_api.go @@ -202,7 +202,6 @@ func editStory(c *fiber.Ctx) error { item.Tags = data.Tags item.Categories = data.Categories item.IsDraft = data.IsDraft - item.PublishedAt = data.PublishedAt item.PublishedUntil = data.PublishedUntil item.VisibleUsers = data.VisibleUsers item.InvisibleUsers = data.InvisibleUsers @@ -210,6 +209,9 @@ func editStory(c *fiber.Ctx) error { // Preload publisher data item.Publisher = publisher + if item.PublishedAt == nil { + item.PublishedAt = data.PublishedAt + } if data.Visibility != nil { item.Visibility = *data.Visibility } diff --git a/pkg/internal/services/posts.go b/pkg/internal/services/posts.go index 9bb43ff..d35c535 100644 --- a/pkg/internal/services/posts.go +++ b/pkg/internal/services/posts.go @@ -460,9 +460,6 @@ func EditPost(item models.Post) (models.Post, error) { if item.Alias != nil && len(*item.Alias) == 0 { item.Alias = nil } - if item.PublishedAt != nil && item.PublishedAt.UTC().Unix() < item.CreatedAt.UTC().Unix() { - return item, fmt.Errorf("post cannot be published before it is created") - } if item.Alias != nil { re := regexp.MustCompile(`^[a-z0-9.-]+$`)