mirror of https://github.com/halo-dev/halo
fix: the problem of incorrect query posts when accessing the category with a password (#1471)
* #1470 目录加密-目录输入密码访问-看不见文章 * status - > statusespull/1479/head
parent
ca8bfd9eea
commit
a046f3edca
|
@ -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 static run.halo.app.model.support.HaloConst.SUFFIX_FTL;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import java.util.Set;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
@ -77,8 +78,8 @@ public class CategoryModel {
|
||||||
* List category posts.
|
* List category posts.
|
||||||
*
|
*
|
||||||
* @param model model
|
* @param model model
|
||||||
* @param slug slug
|
* @param slug slug
|
||||||
* @param page current page
|
* @param page current page
|
||||||
* @return template name
|
* @return template name
|
||||||
*/
|
*/
|
||||||
public String listPost(Model model, String slug, Integer page) {
|
public String listPost(Model model, String slug, Integer page) {
|
||||||
|
@ -95,14 +96,18 @@ public class CategoryModel {
|
||||||
return "common/template/" + POST_PASSWORD_TEMPLATE;
|
return "common/template/" + POST_PASSWORD_TEMPLATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<PostStatus> statuses = Sets.immutableEnumSet(PostStatus.PUBLISHED);
|
||||||
|
if (StringUtils.isNotBlank(category.getPassword())) {
|
||||||
|
statuses = Sets.immutableEnumSet(PostStatus.INTIMATE);
|
||||||
|
}
|
||||||
|
|
||||||
CategoryDTO categoryDTO = categoryService.convertTo(category);
|
CategoryDTO categoryDTO = categoryService.convertTo(category);
|
||||||
|
|
||||||
final Pageable pageable = PageRequest.of(page - 1,
|
final Pageable pageable = PageRequest.of(page - 1,
|
||||||
optionService.getArchivesPageSize(),
|
optionService.getArchivesPageSize(),
|
||||||
Sort.by(DESC, "topPriority", "createTime"));
|
Sort.by(DESC, "topPriority", "createTime"));
|
||||||
Page<Post> postPage =
|
Page<Post> postPage =
|
||||||
postCategoryService.pagePostBy(category.getId(), Sets
|
postCategoryService.pagePostBy(category.getId(), statuses, pageable);
|
||||||
.immutableEnumSet(PostStatus.PUBLISHED), pageable);
|
|
||||||
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||||
|
|
||||||
// Generate meta description.
|
// Generate meta description.
|
||||||
|
|
Loading…
Reference in New Issue