-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Knowledge Base Workflow Execution Record #4435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,14 +56,15 @@ class KnowledgeWorkflowUploadDocumentView(APIView): | |
| ) | ||
| def post(self, request: Request, workspace_id: str, knowledge_id: str): | ||
| return result.success(KnowledgeWorkflowActionSerializer( | ||
| data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}).upload_document(request.data, True)) | ||
| data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}).upload_document(request.data, | ||
| request.user, True)) | ||
|
|
||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested changes: class KnowledgeWorkflowUploadDocumentView(APIView):
...
def post(self, request: Request, workspace_id: str, knowledge_id: str) -> Response:
return result.success(KnowledgeWorkflowActionSerializer(
data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}).upload_document(request.data,
request.user))
class KnowledgeWorkflowActionView(APIView):
...
def post(self, request: Request, workspace_id: str, knowledge_id: str) -> Response:
return result.success(KnowledgeWorkflowActionSerializer(data=request.data).action(request.data, request.user))The remaining changes need to be adapted based on the actual implementation of |
||
| class KnowledgeWorkflowActionView(APIView): | ||
| authentication_classes = [TokenAuth] | ||
|
|
||
| @extend_schema( | ||
| methods=['GET'], | ||
| methods=['POST'], | ||
| description=_('Knowledge workflow debug'), | ||
| summary=_('Knowledge workflow debug'), | ||
| operation_id=_('Knowledge workflow debug'), # type: ignore | ||
|
|
@@ -84,7 +85,35 @@ class KnowledgeWorkflowActionView(APIView): | |
| ) | ||
| def post(self, request: Request, workspace_id: str, knowledge_id: str): | ||
| return result.success(KnowledgeWorkflowActionSerializer( | ||
| data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}).action(request.data, True)) | ||
| data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}).action(request.data, request.user, True)) | ||
|
|
||
| class Page(APIView): | ||
| authentication_classes = [TokenAuth] | ||
|
|
||
| @extend_schema( | ||
| methods=['GET'], | ||
| description=_('Page Knowledge workflow action'), | ||
| summary=_('Page Knowledge workflow action'), | ||
| operation_id=_('Page Knowledge workflow action'), # type: ignore | ||
| parameters=KnowledgeWorkflowActionApi.get_parameters(), | ||
| request=KnowledgeWorkflowActionApi.get_request(), | ||
| responses=KnowledgeWorkflowActionApi.get_response(), | ||
| tags=[_('Knowledge Base')] # type: ignore | ||
| ) | ||
| @has_permissions( | ||
| PermissionConstants.KNOWLEDGE_DOCUMENT_CREATE.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_DOCUMENT_CREATE.get_workspace_permission_workspace_manage_role(), | ||
| RoleConstants.WORKSPACE_MANAGE.get_workspace_role(), | ||
| ViewPermission( | ||
| [RoleConstants.USER.get_workspace_role()], | ||
| [PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()], | ||
| CompareConstants.AND | ||
| ), | ||
| ) | ||
| def get(self, request: Request, workspace_id: str, knowledge_id: str, current_page: int, page_size: int): | ||
| return result.success( | ||
| KnowledgeWorkflowActionSerializer(data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id}) | ||
| .page(current_page, page_size, request.data)) | ||
|
|
||
| class Operate(APIView): | ||
| authentication_classes = [TokenAuth] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <template> | ||
| <el-drawer v-model="drawer" title="执行记录" direction="rtl" size="800px" :before-close="close"> | ||
| <el-table v-if="active == 'list'" :data="data" style="width: 100%"> | ||
| <el-table-column prop="meta" label="发起人" width="180"> | ||
| <template #default="{ row }"> | ||
| {{ row.meta.user_name }} | ||
| </template> | ||
| </el-table-column> | ||
| <el-table-column prop="sate" label="状态" width="180"> | ||
| <template #default="{ row }"> | ||
| {{ row.state }} | ||
| </template> | ||
| </el-table-column> | ||
| <el-table-column prop="run_time" label="运行时间"> | ||
| <template #default="{ row }"> | ||
| {{ row.run_time }} | ||
| </template> | ||
| </el-table-column> | ||
| <el-table-column label="操作"> | ||
| <template #default="{ row }"> | ||
| <span @click="details(row)">执行详情</span> | ||
| </template> | ||
| </el-table-column> | ||
| </el-table> | ||
| <Result | ||
| v-if="active == 'details'" | ||
| :id="active_action_id" | ||
| :knowledge_id="active_knowledge_id" | ||
| ></Result> | ||
| </el-drawer> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import { loadSharedApi } from '@/utils/dynamics-api/shared-api' | ||
| import { computed, ref, reactive } from 'vue' | ||
| import Result from '../action/Result.vue' | ||
| import { useRoute, useRouter } from 'vue-router' | ||
| const drawer = ref<boolean>(false) | ||
| const active_knowledge_id = ref<string>() | ||
| const active_action_id = ref<string>() | ||
| const active = ref<'list' | 'details'>('list') | ||
| const route = useRoute() | ||
| const details = (row: any) => { | ||
| active_action_id.value = row.id | ||
| active.value = 'details' | ||
| } | ||
| const apiType = computed(() => { | ||
| if (route.path.includes('shared')) { | ||
| return 'systemShare' | ||
| } else if (route.path.includes('resource-management')) { | ||
| return 'systemManage' | ||
| } else { | ||
| return 'workspace' | ||
| } | ||
| }) | ||
| const paginationConfig = reactive({ | ||
| current_page: 1, | ||
| page_size: 30, | ||
| total: 0, | ||
| }) | ||
| const query = ref<any>({ | ||
| user_name: '', | ||
| }) | ||
| const data = ref<Array<any>>([]) | ||
| const page = () => { | ||
| loadSharedApi({ type: 'knowledge', systemType: apiType.value }) | ||
| .pageWorkflowAction(active_knowledge_id.value, paginationConfig, query) | ||
| .then((ok: any) => { | ||
| paginationConfig.total = ok.data?.total | ||
| data.value = ok.data.records | ||
| }) | ||
| } | ||
| const open = (knowledge_id: string) => { | ||
| drawer.value = true | ||
| active_knowledge_id.value = knowledge_id | ||
| page() | ||
| } | ||
| const close = () => { | ||
| drawer.value = false | ||
| } | ||
| defineExpose({ open, close }) | ||
| </script> | ||
| <style lang="scss" scoped></style> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code looks mostly correct, but there are a few suggestions and improvements:
By applying these improvements, you will make the code more robust, efficient, and easier to maintain. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code looks generally correct and well-structured. However, there are a few suggestions for improvement:
Import Statement: Ensure that all necessary imports are present without any duplicates. In this case,
common.db.searchis already imported at the beginning.Variable Naming: Use meaningful variable names to improve readability. For example,
query_setinstead ofa.Documentation Comments: Add comments to explain important parts of the code, especially logic blocks or function purposes.
Type Hinting: Consider using type hints to improve code clarity and maintainability. Although not strictly required for Python 3.6+, it's recommended for better IDE support and static analysis tools.
Here’s an improved version of the code with these considerations:
Key Points:
knowledge_id._get_user_filtermethod to handle optional filtering based onuseranduser_name.with_valid=True).These changes enhance both the functionality and readability of the code while maintaining its integrity.