🐛 Fix user cannot get draft posts
This commit is contained in:
		@@ -68,7 +68,13 @@ func getPost(c *fiber.Ctx) error {
 | 
				
			|||||||
	var item models.Post
 | 
						var item models.Post
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx := services.FilterPostDraft(database.C)
 | 
						tx := database.C
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if user, authenticated := c.Locals("user").(authm.Account); authenticated {
 | 
				
			||||||
 | 
							tx = services.FilterPostDraftWithAuthor(database.C, user.ID)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							tx = services.FilterPostDraft(database.C)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if user, authenticated := c.Locals("user").(authm.Account); authenticated {
 | 
						if user, authenticated := c.Locals("user").(authm.Account); authenticated {
 | 
				
			||||||
		tx = services.FilterPostWithUserContext(c, tx, &user)
 | 
							tx = services.FilterPostWithUserContext(c, tx, &user)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -290,6 +290,20 @@ func FilterPostDraft(tx *gorm.DB) *gorm.DB {
 | 
				
			|||||||
	return tx.Where("is_draft = ? OR is_draft IS NULL", false)
 | 
						return tx.Where("is_draft = ? OR is_draft IS NULL", false)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func FilterPostDraftWithAuthor(tx *gorm.DB, uid uint) *gorm.DB {
 | 
				
			||||||
 | 
						var publishers []models.Publisher
 | 
				
			||||||
 | 
						if err := database.C.Where("account_id = ?", uid).Find(&publishers).Error; err != nil {
 | 
				
			||||||
 | 
							return FilterPostDraft(tx)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(publishers) == 0 {
 | 
				
			||||||
 | 
							return FilterPostDraft(tx)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						idSet := lo.Map(publishers, func(item models.Publisher, index int) uint {
 | 
				
			||||||
 | 
							return item.ID
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						return tx.Where("(is_draft = ? OR is_draft IS NULL) OR publisher_id IN ?", false, idSet)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func FilterPostWithFuzzySearch(tx *gorm.DB, probe string) *gorm.DB {
 | 
					func FilterPostWithFuzzySearch(tx *gorm.DB, probe string) *gorm.DB {
 | 
				
			||||||
	if len(probe) == 0 {
 | 
						if len(probe) == 0 {
 | 
				
			||||||
		return tx
 | 
							return tx
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user