Skip to content

Commit 2af4851

Browse files
committed
feat: Retrieve the pagination list of resource relationships
1 parent c362b4e commit 2af4851

File tree

13 files changed

+363
-3
lines changed

13 files changed

+363
-3
lines changed

apps/locales/en_US/LC_MESSAGES/django.po

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8886,4 +8886,10 @@ msgid "Role IDs cannot be empty"
88868886
msgstr ""
88878887

88888888
msgid "Some roles do not exist"
8889+
msgstr ""
8890+
8891+
msgid "Authorized pagination list for obtaining resources"
8892+
msgstr ""
8893+
8894+
msgid "Resources mapping"
88898895
msgstr ""

apps/locales/zh_CN/LC_MESSAGES/django.po

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9013,3 +9013,9 @@ msgstr "角色 ID 不能为空"
90139013

90149014
msgid "Some roles do not exist"
90159015
msgstr "部分角色不存在"
9016+
9017+
msgid "Authorized pagination list for obtaining resources"
9018+
msgstr "获取资源的关系分页列表"
9019+
9020+
msgid "Resources mapping"
9021+
msgstr "资源映射"

apps/locales/zh_Hant/LC_MESSAGES/django.po

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9013,3 +9013,9 @@ msgstr "角色 ID 不能为空"
90139013

90149014
msgid "Some roles do not exist"
90159015
msgstr "部分角色不存在"
9016+
9017+
msgid "Authorized pagination list for obtaining resources"
9018+
msgstr "獲取資源的關係分頁清單"
9019+
9020+
msgid "Resources mapping"
9021+
msgstr "資源映射"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎虎
5+
@file: resource_mapping.py
6+
@date:2025/12/26 14:07
7+
@desc:
8+
"""
9+
from django.utils.translation import gettext_lazy as _
10+
from drf_spectacular.types import OpenApiTypes
11+
from drf_spectacular.utils import OpenApiParameter
12+
from rest_framework import serializers
13+
14+
from common.mixins.api_mixin import APIMixin
15+
16+
17+
class ResourceMappingResponse(serializers.Serializer):
18+
id = serializers.UUIDField(required=True, label="主键id")
19+
target_id = serializers.CharField(required=True, label="被关联资源名称")
20+
target_type = serializers.CharField(required=True, label="被关联资源类型")
21+
source_id = serializers.CharField(required=True, label="关联资源Id")
22+
source_type = serializers.CharField(required=True, label="关联资源类型")
23+
name = serializers.CharField(required=True, label="名称")
24+
desc = serializers.CharField(required=False, label="描述")
25+
user_id = serializers.UUIDField(required=True, label="主键id")
26+
27+
28+
class ResourceMappingAPI(APIMixin):
29+
30+
@staticmethod
31+
def get_parameters():
32+
return [
33+
OpenApiParameter(
34+
name="workspace_id",
35+
description="工作空间id",
36+
type=OpenApiTypes.STR,
37+
location='path',
38+
required=True,
39+
),
40+
OpenApiParameter(
41+
name="source",
42+
description="资源类型",
43+
type=OpenApiTypes.STR,
44+
location='path',
45+
required=True,
46+
),
47+
OpenApiParameter(
48+
name="source_id",
49+
description="资源id",
50+
type=OpenApiTypes.STR,
51+
location='path',
52+
required=True,
53+
),
54+
OpenApiParameter(
55+
name="current_page",
56+
description=_("Current page"),
57+
type=OpenApiTypes.INT,
58+
location='path',
59+
required=True,
60+
),
61+
OpenApiParameter(
62+
name="page_size",
63+
description=_("Page size"),
64+
type=OpenApiTypes.INT,
65+
location='path',
66+
required=True,
67+
),
68+
OpenApiParameter(
69+
name="resource_name",
70+
description="名称",
71+
type=OpenApiTypes.STR,
72+
location='query',
73+
required=False
74+
),
75+
76+
]
77+
78+
@staticmethod
79+
def get_response():
80+
return ResourceMappingResponse(many=True)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎虎
5+
@file: workspace_user_resource_permission.py
6+
@date:2025/4/28 17:17
7+
@desc:
8+
"""
9+
import os
10+
11+
from django.db import models
12+
from django.db.models import QuerySet
13+
from django.utils.translation import gettext_lazy as _
14+
from rest_framework import serializers
15+
16+
from common.db.search import native_page_search, get_dynamics_model
17+
from common.utils.common import get_file_content
18+
from maxkb.conf import PROJECT_DIR
19+
20+
21+
class ResourceMappingSerializer(serializers.Serializer):
22+
resource = serializers.CharField(required=True, label=_('resource'))
23+
resource_id = serializers.UUIDField(required=True, label=_('resource Id'))
24+
resource_name = serializers.CharField(required=False, allow_null=True, allow_blank=True, label=_('resource'))
25+
26+
def get_query_set(self):
27+
queryset = QuerySet(model=get_dynamics_model({
28+
'name': models.CharField(),
29+
'target_id': models.CharField(),
30+
"target_type": models.CharField()
31+
}))
32+
33+
queryset = queryset.filter(target_id=self.data.get('resource_id'),
34+
target_type=self.data.get('resource'))
35+
36+
if self.data.get('resource_name'):
37+
queryset = queryset.filter(name__icontains=self.data.get('resource_name'))
38+
39+
return queryset
40+
41+
def page(self, current_page, page_size):
42+
return native_page_search(current_page, page_size, self.get_query_set(), get_file_content(
43+
os.path.join(PROJECT_DIR, "apps", "system_manage",
44+
'sql', 'list_resource_mapping.sql')), with_table_name=False)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
WITH source_data_cte AS (
2+
SELECT 'APPLICATION' as source_type, id, "name", "desc","user_id"
3+
FROM application
4+
UNION ALL
5+
SELECT 'KNOWLEDGE' as source_type, id, "name", "desc","user_id"
6+
FROM knowledge)
7+
SELECT rm.*,
8+
sdc.*
9+
FROM resource_mapping rm
10+
LEFT JOIN source_data_cte sdc
11+
ON rm.source_type = sdc.source_type
12+
AND rm.source_id::uuid = sdc.id

apps/system_manage/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
path('workspace/<str:workspace_id>/user_resource_permission/user/<str:user_id>/resource/<str:resource>/<int:current_page>/<int:page_size>', views.WorkSpaceUserResourcePermissionView.Page.as_view()),
1010
path('workspace/<str:workspace_id>/resource_user_permission/resource/<str:target>/resource/<str:resource>', views.WorkspaceResourceUserPermissionView.as_view()),
1111
path('workspace/<str:workspace_id>/resource_user_permission/resource/<str:target>/resource/<str:resource>/<int:current_page>/<int:page_size>', views.WorkspaceResourceUserPermissionView.Page.as_view()),
12+
path('workspace/<str:workspace_id>/resource_mapping/<str:resource>/<str:resource_id>/<int:current_page>/<int:page_size>', views.ResourceMappingView.as_view()),
1213
path('email_setting', views.SystemSetting.Email.as_view()),
1314
path('profile', views.SystemProfile.as_view()),
1415
path('valid/<str:valid_type>/<int:valid_count>', views.Valid.as_view())

apps/system_manage/views/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
from .email_setting import *
1111
from .system_profile import *
1212
from .valid import *
13+
from .resource_mapping import *
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎虎
5+
@file: resource_mapping.py
6+
@date:2025/12/25 15:28
7+
@desc:
8+
"""
9+
10+
from django.utils.translation import gettext_lazy as _
11+
from drf_spectacular.utils import extend_schema
12+
from rest_framework.request import Request
13+
from rest_framework.views import APIView
14+
15+
from common import result
16+
from common.auth import TokenAuth
17+
from system_manage.api.resource_mapping import ResourceMappingAPI
18+
from system_manage.serializers.resource_mapping_serializers import ResourceMappingSerializer
19+
20+
21+
class ResourceMappingView(APIView):
22+
authentication_classes = [TokenAuth]
23+
24+
@extend_schema(
25+
methods=['GET'],
26+
description=_('Retrieve the pagination list of resource relationships'),
27+
operation_id=_('Retrieve the pagination list of resource relationships'), # type: ignore
28+
responses=ResourceMappingAPI.get_response(),
29+
parameters=ResourceMappingAPI.get_parameters(),
30+
tags=[_('Resources mapping')] # type: ignore
31+
)
32+
def get(self, request: Request, workspace_id: str, resource: str, resource_id: str, current_page, page_size):
33+
return result.success(ResourceMappingSerializer({
34+
'resource': resource,
35+
'resource_id': resource_id,
36+
'resource_name': request.query_params.get('resource_name')
37+
}).page(current_page, page_size))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Result } from '@/request/Result'
2+
import { get, put, post, del } from '@/request/index'
3+
import type { Ref } from 'vue'
4+
import type { pageRequest } from '@/api/type/common'
5+
const prefix = '/workspace'
6+
7+
/**
8+
* 工作空间下各个资源的映射关系
9+
* @query 参数
10+
*/
11+
const getResourceMapping: (
12+
workspace_id: string,
13+
resource: string,
14+
resource_id: string,
15+
page: pageRequest,
16+
params?: any,
17+
loading?: Ref<boolean>,
18+
) => Promise<Result<any>> = (workspace_id, resource, resource_id, page, params, loading) => {
19+
return get(
20+
`${prefix}/${workspace_id}/resource_mapping/${resource}/${resource_id}/${page.current_page}/${page.page_size}`,
21+
params,
22+
loading,
23+
)
24+
}
25+
26+
export default {
27+
getResourceMapping,
28+
}

0 commit comments

Comments
 (0)