Skip to content

Commit af6f88a

Browse files
authored
fix: application knowledge list (#3365)
1 parent 3a91562 commit af6f88a

File tree

6 files changed

+38
-45
lines changed

6 files changed

+38
-45
lines changed

apps/application/serializers/application.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class Query(serializers.Serializer):
295295
workspace_id = serializers.CharField(required=False, label=_('Workspace ID'))
296296
user_id = serializers.UUIDField(required=True, label=_("User ID"))
297297

298-
def get_query_set(self, instance: Dict, workspace_manage: bool, is_x_pack_ee: bool):
298+
def get_query_set(self, instance: Dict, workspace_manage):
299299
folder_query_set = QuerySet(ApplicationFolder)
300300
application_query_set = QuerySet(Application)
301301
workspace_id = self.data.get('workspace_id')
@@ -317,13 +317,8 @@ def get_query_set(self, instance: Dict, workspace_manage: bool, is_x_pack_ee: bo
317317
application_query_set = application_query_set.filter(desc__contains=desc)
318318
application_custom_sql_query_set = application_query_set
319319
application_query_set = application_query_set.order_by("-update_time")
320-
workspace_user_role_mapping_model = DatabaseModelManage.get_model('workspace_user_role_mapping')
321-
322320
return {'folder_query_set': folder_query_set,
323-
'application_query_set': application_query_set,
324-
'user_query_set': QuerySet(
325-
workspace_user_role_mapping_model).filter(
326-
user_id=user_id, workspace_id=workspace_id)} if (not workspace_manage and is_x_pack_ee) else {
321+
'application_query_set': application_query_set} if not workspace_manage else {
327322
'folder_query_set': folder_query_set,
328323
'application_query_set': application_query_set,
329324
'application_custom_sql': application_custom_sql_query_set
@@ -341,12 +336,11 @@ def list(self, instance: Dict):
341336
user_id = self.data.get("user_id")
342337
ApplicationQueryRequest(data=instance).is_valid(raise_exception=True)
343338
workspace_manage = is_workspace_manage(user_id, workspace_id)
344-
is_x_pack_ee = self.is_x_pack_ee()
345-
return native_search(self.get_query_set(instance, workspace_manage, is_x_pack_ee),
339+
return native_search(self.get_query_set(instance, workspace_manage),
346340
select_string=get_file_content(
347341
os.path.join(PROJECT_DIR, "apps", "application", 'sql',
348342
'list_application.sql' if workspace_manage else (
349-
'list_application_user_ee.sql' if is_x_pack_ee else 'list_application_user.sql')
343+
'list_application_user_ee.sql' if self.is_x_pack_ee() else 'list_application_user.sql')
350344
)))
351345

352346
def page(self, current_page: int, page_size: int, instance: Dict):
@@ -355,12 +349,11 @@ def page(self, current_page: int, page_size: int, instance: Dict):
355349
workspace_id = self.data.get('workspace_id')
356350
user_id = self.data.get("user_id")
357351
workspace_manage = is_workspace_manage(user_id, workspace_id)
358-
is_x_pack_ee = self.is_x_pack_ee()
359-
return native_page_search(current_page, page_size, self.get_query_set(instance, workspace_manage, is_x_pack_ee),
352+
return native_page_search(current_page, page_size, self.get_query_set(instance, workspace_manage),
360353
get_file_content(
361354
os.path.join(PROJECT_DIR, "apps", "application", 'sql',
362355
'list_application.sql' if workspace_manage else (
363-
'list_application_user_ee.sql' if is_x_pack_ee else 'list_application_user.sql'))),
356+
'list_application_user_ee.sql' if self.is_x_pack_ee() else 'list_application_user.sql'))),
364357
)
365358

366359

apps/application/sql/list_application_user_ee.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ from (select application."id"::text,
1717
where auth_target_type = 'APPLICATION'
1818
and case
1919
when auth_type = 'ROLE' then
20+
'ROLE' = any (permission_list)
21+
and
2022
'APPLICATION:READ' in (select (case when user_role_relation.role_id = any (array ['USER']) THEN 'APPLICATION:READ' else role_permission.permission_id END)
2123
from role_permission role_permission
2224
right join user_role_relation user_role_relation
2325
on user_role_relation.role_id=role_permission.role_id
24-
${user_query_set})
26+
where user_role_relation.user_id=workspace_user_resource_permission.user_id
27+
and user_role_relation.workspace_id=workspace_user_resource_permission.workspace_id)
2528

2629
else
2730
'VIEW' = any (permission_list)

apps/knowledge/serializers/knowledge.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def is_x_pack_ee():
120120
role_permission_mapping_model = DatabaseModelManage.get_model("role_permission_mapping_model")
121121
return workspace_user_role_mapping_model is not None and role_permission_mapping_model is not None
122122

123-
def get_query_set(self, workspace_manage, is_x_pack_ee):
123+
def get_query_set(self):
124124
workspace_id = self.data.get("workspace_id")
125125
query_set_dict = {}
126126
query_set = QuerySet(model=get_dynamics_model({
@@ -157,10 +157,6 @@ def get_query_set(self, workspace_manage, is_x_pack_ee):
157157
'knowledge.workspace_id': models.CharField(),
158158
})).filter(**{'knowledge.workspace_id': workspace_id})
159159
query_set_dict['folder_query_set'] = folder_query_set
160-
workspace_user_role_mapping_model = DatabaseModelManage.get_model('workspace_user_role_mapping')
161-
if not workspace_manage and is_x_pack_ee:
162-
query_set_dict['user_query_set'] = QuerySet(workspace_user_role_mapping_model).filter(
163-
user_id=self.data.get("user_id"), workspace_id=workspace_id)
164160
return query_set_dict
165161

166162
def page(self, current_page: int, page_size: int):
@@ -171,18 +167,17 @@ def page(self, current_page: int, page_size: int):
171167
if not root:
172168
raise serializers.ValidationError(_('Folder not found'))
173169
workspace_manage = is_workspace_manage(self.data.get('user_id'), self.data.get('workspace_id'))
174-
is_x_pack_ee = self.is_x_pack_ee()
175170
return native_page_search(
176171
current_page,
177172
page_size,
178-
self.get_query_set(workspace_manage, is_x_pack_ee),
173+
self.get_query_set(),
179174
select_string=get_file_content(
180175
os.path.join(
181176
PROJECT_DIR,
182177
"apps",
183178
"knowledge", 'sql',
184179
'list_knowledge.sql' if workspace_manage else (
185-
'list_knowledge_user_ee.sql' if is_x_pack_ee else 'list_knowledge_user.sql'
180+
'list_knowledge_user_ee.sql' if self.is_x_pack_ee() else 'list_knowledge_user.sql'
186181
)
187182
)
188183
),
@@ -196,9 +191,8 @@ def list(self):
196191
if not root:
197192
raise serializers.ValidationError(_('Folder not found'))
198193
workspace_manage = is_workspace_manage(self.data.get('user_id'), self.data.get('workspace_id'))
199-
is_x_pack_ee = self.is_x_pack_ee()
200194
return native_search(
201-
self.get_query_set(workspace_manage, is_x_pack_ee),
195+
self.get_query_set(),
202196
select_string=get_file_content(
203197
os.path.join(
204198
PROJECT_DIR,

apps/knowledge/sql/list_knowledge_user_ee.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ FROM (SELECT "temp_knowledge".id::text, "temp_knowledge".name,
2525
where auth_target_type = 'KNOWLEDGE'
2626
and case
2727
when auth_type = 'ROLE' then
28+
'ROLE' = any (permission_list)
29+
and
2830
'KNOWLEDGE:READ' in (select (case when user_role_relation.role_id = any (array ['USER']) THEN 'KNOWLEDGE:READ' else role_permission.permission_id END)
2931
from role_permission role_permission
3032
right join user_role_relation user_role_relation
3133
on user_role_relation.role_id=role_permission.role_id
32-
${user_query_set})
34+
where user_role_relation.user_id=workspace_user_resource_permission.user_id
35+
and user_role_relation.workspace_id=workspace_user_resource_permission.workspace_id)
3336
else
3437
'VIEW' = any (permission_list)
3538
end

ui/src/views/system/resource-authorization/component/PermissionSetting.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,12 @@ const props = defineProps({
181181
manage: Boolean,
182182
isRole: Boolean,
183183
})
184-
const emit = defineEmits(['update:data', 'refreshData','update:isRole'])
184+
const emit = defineEmits(['update:data', 'refreshData', 'update:isRole'])
185185
const radioRole = computed({
186186
get: () => props.isRole,
187-
set: (v:boolean) => {
187+
set: (v: boolean) => {
188188
emit('update:isRole', v)
189-
190-
}
189+
},
191190
})
192191
const isKnowledge = computed(() => props.type === AuthorizationEnum.KNOWLEDGE)
193192
const isApplication = computed(() => props.type === AuthorizationEnum.APPLICATION)
@@ -214,8 +213,6 @@ const dfsPermission = (arr: any = [], Name: string | number, e: boolean, idArr:
214213
})
215214
}
216215
217-
218-
219216
const filterText = ref('')
220217
221218
const filterData = computed(() =>

ui/src/views/system/resource-authorization/index.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,20 @@ const flotTree = (tree: Array<any>, result: Array<any>) => {
150150
return result
151151
}
152152
function submitPermissions() {
153-
const user_resource_permission_list = settingTags.map((item: any, index: number) => {
154-
return flotTree(item.data, [])
155-
.filter((v: any) => !v.isFolder)
156-
.map((v: any) => {
157-
return {
158-
target_id: v.id,
159-
auth_target_type: item.value,
160-
permission: v.permission,
161-
auth_type: item.isRole ? 'ROLE' : 'RESOURCE_PERMISSION_GROUP',
162-
}
163-
})
164-
165-
}).reduce((pre: any, next: any) => [...pre, ...next], [])
153+
const user_resource_permission_list = settingTags
154+
.map((item: any, index: number) => {
155+
return flotTree(item.data, [])
156+
.filter((v: any) => !v.isFolder)
157+
.map((v: any) => {
158+
return {
159+
target_id: v.id,
160+
auth_target_type: item.value,
161+
permission: v.permission,
162+
auth_type: item.isRole ? 'ROLE' : 'RESOURCE_PERMISSION_GROUP',
163+
}
164+
})
165+
})
166+
.reduce((pre: any, next: any) => [...pre, ...next], [])
166167
167168
AuthorizationApi.putResourceAuthorization(
168169
currentWorkspaceId.value || 'default',
@@ -294,7 +295,9 @@ const getWholeTree = async (user_id: string) => {
294295
let folderIdMap = []
295296
const folderTree = cloneDeep((parentRes as unknown as any).data)
296297
if (Object.keys(childrenRes.data).indexOf(item.value) !== -1) {
297-
item.isRole = childrenRes.data[item.value].length>0 && childrenRes.data[item.value][0].permission.ROLE
298+
item.isRole =
299+
childrenRes.data[item.value].length > 0 &&
300+
childrenRes.data[item.value][0].auth_type == 'ROLE'
298301
folderIdMap = getFolderIdMap(childrenRes.data[item.value])
299302
dfsFolder(folderTree, folderIdMap)
300303
const permissionHalf = {

0 commit comments

Comments
 (0)