From a046f3edcaeeee2393f18c9ee1a84f20d172fcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=8D=E5=B7=9D?= <87689005+dingguangyi0@users.noreply.github.com> Date: Tue, 14 Sep 2021 16:52:05 +0800 Subject: [PATCH] fix: the problem of incorrect query posts when accessing the category with a password (#1471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #1470 目录加密-目录输入密码访问-看不见文章 * status - > statuses --- .../app/controller/content/model/CategoryModel.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/run/halo/app/controller/content/model/CategoryModel.java b/src/main/java/run/halo/app/controller/content/model/CategoryModel.java index a31f6cdb5..43146b3a0 100644 --- a/src/main/java/run/halo/app/controller/content/model/CategoryModel.java +++ b/src/main/java/run/halo/app/controller/content/model/CategoryModel.java @@ -5,6 +5,7 @@ import static run.halo.app.model.support.HaloConst.POST_PASSWORD_TEMPLATE; import static run.halo.app.model.support.HaloConst.SUFFIX_FTL; import com.google.common.collect.Sets; +import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -77,8 +78,8 @@ public class CategoryModel { * List category posts. * * @param model model - * @param slug slug - * @param page current page + * @param slug slug + * @param page current page * @return template name */ public String listPost(Model model, String slug, Integer page) { @@ -95,14 +96,18 @@ public class CategoryModel { return "common/template/" + POST_PASSWORD_TEMPLATE; } + Set statuses = Sets.immutableEnumSet(PostStatus.PUBLISHED); + if (StringUtils.isNotBlank(category.getPassword())) { + statuses = Sets.immutableEnumSet(PostStatus.INTIMATE); + } + CategoryDTO categoryDTO = categoryService.convertTo(category); final Pageable pageable = PageRequest.of(page - 1, optionService.getArchivesPageSize(), Sort.by(DESC, "topPriority", "createTime")); Page postPage = - postCategoryService.pagePostBy(category.getId(), Sets - .immutableEnumSet(PostStatus.PUBLISHED), pageable); + postCategoryService.pagePostBy(category.getId(), statuses, pageable); Page posts = postService.convertToListVo(postPage); // Generate meta description.