feat: add support for refreshing search engine indexes (#3475)

#### What type of PR is this?

/kind feature

#### What this PR does / why we need it:

在 Console 端仪表盘的快捷访问中添加刷新搜索引擎索引的入口。

![2023-03-07 13 48 52](https://user-images.githubusercontent.com/21301288/223332020-6d4e143e-e024-46ce-a84c-96ea3813cec0.gif)

#### Special notes for your reviewer:

1. 测试仪表盘快捷访问中的刷新搜索引擎操作是否可以正常调用接口即可。
2. 分配一个不包含文章管理权限的角色给某个用户,检查是否可以看到这个刷新的入口。

#### Does this PR introduce a user-facing change?

```release-note
Console 端仪表盘的快捷访问中添加刷新搜索引擎索引的入口。
```
pull/3441/head^2
Ryan Wang 2023-03-08 17:32:11 +08:00 committed by GitHub
parent 80a3fa803f
commit 4ba3cfb64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -8,12 +8,16 @@ import {
IconUserSettings,
IconPalette,
IconWindowLine,
IconSearch,
VCard,
IconUserLine,
Dialog,
Toast,
} from "@halo-dev/components";
import { markRaw, ref, type Component } from "vue";
import { useRouter } from "vue-router";
import ThemePreviewModal from "@/modules/interface/themes/components/preview/ThemePreviewModal.vue";
import { apiClient } from "@/utils/api-client";
interface Action {
icon: Component;
@ -111,6 +115,21 @@ const actions: Action[] = [
},
permissions: ["system:users:manage"],
},
{
icon: markRaw(IconSearch),
title: "刷新搜索引擎",
action: () => {
Dialog.warning({
title: "确定要刷新搜索引擎索引吗?",
description: "此操作会对所有已发布的文章重新创建搜索引擎索引。",
onConfirm: async () => {
await apiClient.indices.buildPostIndices();
Toast.success("刷新成功");
},
});
},
permissions: ["system:posts:manage"],
},
];
</script>
<template>

View File

@ -8,6 +8,7 @@ import {
ApiConsoleHaloRunV1alpha1ReplyApi,
ApiConsoleHaloRunV1alpha1StatsApi,
ApiConsoleHaloRunV1alpha1AttachmentApi,
ApiConsoleHaloRunV1alpha1IndicesApi,
ContentHaloRunV1alpha1CategoryApi,
ContentHaloRunV1alpha1CommentApi,
ContentHaloRunV1alpha1PostApi,
@ -183,6 +184,7 @@ function setupApiClient(axios: AxiosInstance) {
baseURL,
axios
),
indices: new ApiConsoleHaloRunV1alpha1IndicesApi(undefined, baseURL, axios),
};
}

View File

@ -16,7 +16,7 @@ rules:
resources: [ "posts" ]
verbs: [ "*" ]
- apiGroups: [ "api.console.halo.run" ]
resources: [ "posts", "posts/publish", "posts/unpublish", "posts/recycle", "posts/content" ]
resources: [ "posts", "posts/publish", "posts/unpublish", "posts/recycle", "posts/content", "indices/post" ]
verbs: [ "create", "patch", "update", "delete", "deletecollection" ]
---
apiVersion: v1alpha1