Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Jun 1, 2021
1 parent 9451029 commit 638bd29
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/main/java/run/halo/app/service/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public interface CategoryService extends CrudService<Category, Integer> {
@NonNull
List<Category> listAll(Sort sort, boolean queryEncryptCategory);

/**
* List all category not encrypt.
*
* @param queryEncryptCategory whether to query encryption category
* @return list of category.
*/
List<Category> listAll(boolean queryEncryptCategory);

/**
* List all by ids
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public BackupDTO exportData() {
data.put("version", HaloConst.HALO_VERSION);
data.put("export_date", DateUtil.now());
data.put("attachments", attachmentService.listAll());
data.put("categories", categoryService.listAll());
data.put("categories", categoryService.listAll(true));
data.put("comment_black_list", commentBlackListService.listAll());
data.put("journals", journalService.listAll());
data.put("journal_comments", journalCommentService.listAll());
Expand Down
47 changes: 28 additions & 19 deletions src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>

private PostService postService;

private AuthenticationService authenticationService;
private final AuthenticationService authenticationService;

public CategoryServiceImpl(CategoryRepository categoryRepository,
PostCategoryService postCategoryService,
Expand Down Expand Up @@ -146,7 +146,7 @@ public List<CategoryVO> listAsTree(Sort sort) {
*
* @param parentCategory parent category vo must not be null
* @param categories a list of category
* @param fillPassword whether to fill in the password
* @param fillPassword whether to fill in the password
*/
private void concreteTree(
CategoryVO parentCategory,
Expand Down Expand Up @@ -240,8 +240,8 @@ public Category getBySlug(String slug) {
public Category getBySlugOfNonNull(String slug) {

Category category = categoryRepository
.getBySlug(slug)
.orElseThrow(() -> new NotFoundException("查询不到该分类的信息").setErrorData(slug));
.getBySlug(slug)
.orElseThrow(() -> new NotFoundException("查询不到该分类的信息").setErrorData(slug));

if (authenticationService.categoryAuthentication(category.getId(), null)) {
return category;
Expand Down Expand Up @@ -291,7 +291,7 @@ public void removeCategoryAndPostCategoryBy(Integer categoryId) {
removeById(categoryId);
// Remove post categories
List<Integer> affectedPostIdList = postCategoryService.removeByCategoryId(categoryId)
.stream().map(PostCategory::getPostId).collect(Collectors.toList());
.stream().map(PostCategory::getPostId).collect(Collectors.toList());

refreshPostStatus(affectedPostIdList);
}
Expand All @@ -311,10 +311,10 @@ public void refreshPostStatus(List<Integer> affectedPostIdList) {
post.setStatus(PostStatus.INTIMATE);
} else {
postCategoryService.listByPostId(postId)
.stream().map(PostCategory::getCategoryId)
.filter(this::categoryHasEncrypt)
.findAny()
.ifPresent(id -> post.setStatus(PostStatus.INTIMATE));
.stream().map(PostCategory::getCategoryId)
.filter(this::categoryHasEncrypt)
.findAny()
.ifPresent(id -> post.setStatus(PostStatus.INTIMATE));
}

if (post.getStatus() == null) {
Expand Down Expand Up @@ -417,12 +417,12 @@ private void doFilterEncryptCategory(List<CategoryVO> categoryList) {
* Collect all child from tree
*
* @param collectorList collector
* @param childrenList contains categories of children
* @param childrenList contains categories of children
* @param doNotCollectEncryptedCategory true is not collect, false is collect
*/
private void collectAllChild(List<Category> collectorList,
List<CategoryVO> childrenList,
Boolean doNotCollectEncryptedCategory) {
List<CategoryVO> childrenList,
Boolean doNotCollectEncryptedCategory) {
if (CollectionUtil.isEmpty(childrenList)) {
return;
}
Expand Down Expand Up @@ -451,14 +451,14 @@ private void collectAllChild(List<Category> collectorList,
* Collect sub-categories under the specified category.
*
* @param collectorList collector
* @param childrenList contains categories of children
* @param categoryId category id
* @param childrenList contains categories of children
* @param categoryId category id
* @param doNotCollectEncryptedCategory true is not collect, false is collect
*/
private void collectAllChildByCategoryId(List<Category> collectorList,
List<CategoryVO> childrenList,
Integer categoryId,
Boolean doNotCollectEncryptedCategory) {
List<CategoryVO> childrenList,
Integer categoryId,
Boolean doNotCollectEncryptedCategory) {
if (CollectionUtil.isEmpty(childrenList)) {
return;
}
Expand All @@ -481,6 +481,15 @@ public List<Category> listAll(Sort sort, boolean queryEncryptCategory) {
}
}

@Override
public List<Category> listAll(boolean queryEncryptCategory) {
if (queryEncryptCategory) {
return super.listAll();
} else {
return this.listAll();
}
}

@Override
public List<Category> listAll() {
return filterEncryptCategory(super.listAll());
Expand Down Expand Up @@ -578,7 +587,7 @@ private void doDecryptPost(Category category) {
List<Category> allCategoryList = super.listAll();

Map<Integer, Category> idToCategoryMap = allCategoryList.stream().collect(
Collectors.toMap(Category::getId, Function.identity()));
Collectors.toMap(Category::getId, Function.identity()));

if (doCategoryHasEncrypt(idToCategoryMap, category.getParentId())) {
// If the parent category is encrypted, there is no need to update the encryption status
Expand Down Expand Up @@ -622,7 +631,7 @@ public Boolean categoryHasEncrypt(Integer categoryId) {
List<Category> allCategoryList = super.listAll();

Map<Integer, Category> idToCategoryMap = allCategoryList.stream().collect(
Collectors.toMap(Category::getId, Function.identity()));
Collectors.toMap(Category::getId, Function.identity()));

return doCategoryHasEncrypt(idToCategoryMap, categoryId);
}
Expand Down

0 comments on commit 638bd29

Please sign in to comment.