Skip to content

Commit 687fd6c

Browse files
feat: resource-authorization
1 parent 1287da6 commit 687fd6c

File tree

5 files changed

+118
-39
lines changed

5 files changed

+118
-39
lines changed

ui/src/api/user/resource-authorization.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import type { pageRequest } from '@/api/type/common'
44
import type { Ref } from 'vue'
55

66
import useStore from '@/stores'
7-
const prefix: any = { _value: '/workspace/' }
8-
Object.defineProperty(prefix, 'value', {
9-
get: function () {
10-
const { user } = useStore()
11-
return this._value + user.getWorkspaceId()
12-
},
13-
})
7+
const prefix = '/workspace'
8+
149
/**
1510
* 获取资源权限
1611
* @query 参数
1712
*/
1813
const getResourceAuthorization: (
14+
workspace_id: string,
1915
user_id: string,
2016
loading?: Ref<boolean>,
21-
) => Promise<Result<any>> = (user_id, loading) => {
22-
return get(`${prefix.value}/user_resource_permission/user/${user_id}`, undefined, loading)
17+
) => Promise<Result<any>> = (workspace_id, user_id, loading) => {
18+
return get(
19+
`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`,
20+
undefined,
21+
loading,
22+
)
2323
}
2424

2525
/**
@@ -41,29 +41,51 @@ const getResourceAuthorization: (
4141
}
4242
*/
4343
const putResourceAuthorization: (
44+
workspace_id: string,
4445
user_id: string,
4546
body: any,
4647
loading?: Ref<boolean>,
47-
) => Promise<Result<any>> = (user_id, body, loading) => {
48-
return put(`${prefix.value}/user_resource_permission/user/${user_id}`, body, loading)
48+
) => Promise<Result<any>> = (workspace_id, user_id, body, loading) => {
49+
return put(`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`, body, loading)
4950
}
5051

51-
5252
/**
5353
* 获取成员列表
5454
* @query 参数
5555
*/
56-
const getUserList: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
57-
return get(`${prefix.value}/user_list`, undefined, loading)
56+
const getUserList: (workspace_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
57+
workspace_id,
58+
loading,
59+
) => {
60+
return get(`${prefix}/${workspace_id}/user_list`, undefined, loading)
61+
}
62+
63+
const getUserMember: (workspace_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
64+
workspace_id,
65+
loading,
66+
) => {
67+
return get(`${prefix}/${workspace_id}/user_member`, undefined, loading)
5868
}
5969

60-
const getUserMember: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
61-
return get(`${prefix.value}/user_member`, undefined, loading)
70+
/**
71+
* 获得系统文件夹列表
72+
* @params 参数
73+
* source : APPLICATION, KNOWLEDGE, TOOL
74+
* data : {name: string}
75+
*/
76+
const getSystemFolder: (
77+
workspace_id: string,
78+
source: string,
79+
data?: any,
80+
loading?: Ref<boolean>,
81+
) => Promise<Result<Array<any>>> = (workspace_id, source, data, loading) => {
82+
return get(`${prefix}/${workspace_id}/${source}/folder`, data, loading)
6283
}
6384

6485
export default {
6586
getResourceAuthorization,
6687
putResourceAuthorization,
6788
getUserList,
6889
getUserMember,
90+
getSystemFolder,
6991
}

ui/src/components/workspace-dropdown/index.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<template #dropdown>
1313
<el-dropdown-menu v-loading="loading">
1414
<el-dropdown-item
15-
v-for="item in user.workspace_list"
15+
v-for="item in data"
1616
:key="item.id"
1717
:class="item.id === currentWorkspace?.id ? 'active' : ''"
1818
@click="changeWorkspace(item)"
@@ -37,19 +37,21 @@
3737
<script setup lang="ts">
3838
import { computed, ref } from 'vue'
3939
import type { WorkspaceItem } from '@/api/type/workspace'
40-
import useStore from '@/stores'
4140
42-
const { user } = useStore()
43-
const loading = ref(false)
44-
45-
const currentWorkspace = computed(() => {
46-
return user.workspace_list.find((w) => w.id == user.workspace_id)
41+
const props = defineProps({
42+
data: {
43+
type: Array,
44+
default: () => [],
45+
},
46+
currentWorkspace: {
47+
type: Object,
48+
default: () => {},
49+
},
4750
})
48-
51+
const loading = ref(false)
52+
const emit = defineEmits(['changeWorkspace'])
4953
function changeWorkspace(item: WorkspaceItem) {
50-
if (item.id === user.workspace_id) return
51-
user.setWorkspaceId(item.id || 'default')
52-
window.location.reload()
54+
emit('changeWorkspace', item)
5355
}
5456
</script>
5557
<style lang="scss" scoped>

ui/src/layout/layout-header/UserHeader.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
direction="vertical"
1414
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
1515
/>
16-
<WorkspaceDropdown v-if="hasPermission(EditionConst.IS_EE, 'OR')" />
16+
<WorkspaceDropdown
17+
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
18+
:data="user.workspace_list"
19+
:currentWorkspace="currentWorkspace"
20+
@changeWorkspace="changeWorkspace"
21+
/>
1722
</div>
1823
<TopMenu></TopMenu>
1924
<TopAbout></TopAbout>
@@ -22,11 +27,24 @@
2227
</div>
2328
</template>
2429
<script setup lang="ts">
30+
import { computed, ref } from 'vue'
2531
import TopMenu from './top-menu/index.vue'
2632
import Avatar from './avatar/index.vue'
2733
import TopAbout from './top-about/index.vue'
2834
import { EditionConst } from '@/utils/permission/data'
2935
import { hasPermission } from '@/utils/permission/index'
36+
import type { WorkspaceItem } from '@/api/type/workspace'
37+
import useStore from '@/stores'
38+
const { user } = useStore()
39+
const currentWorkspace = computed(() => {
40+
return user.workspace_list.find((w) => w.id == user.workspace_id)
41+
})
42+
43+
function changeWorkspace(item: WorkspaceItem) {
44+
if (item.id === user.workspace_id) return
45+
user.setWorkspaceId(item.id || 'default')
46+
window.location.reload()
47+
}
3048
</script>
3149
<style lang="scss" scoped>
3250
.app-top-bar-container {

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

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
direction="vertical"
99
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
1010
/>
11-
<WorkspaceDropdown v-if="hasPermission(EditionConst.IS_EE, 'OR')" />
11+
<WorkspaceDropdown
12+
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
13+
:data="workspaceList"
14+
:currentWorkspace="currentWorkspace"
15+
@changeWorkspace="changeWorkspace"
16+
/>
1217
</div>
1318

1419
<el-card style="--el-card-padding: 0">
@@ -76,7 +81,7 @@
7681
</template>
7782

7883
<script lang="ts" setup>
79-
import { onMounted, ref, reactive, watch } from 'vue'
84+
import { onMounted, ref, reactive, watch, computed } from 'vue'
8085
import AuthorizationApi from '@/api/user/resource-authorization'
8186
import PermissionSetting from './component/PermissionSetting.vue'
8287
import { MsgSuccess, MsgConfirm } from '@/utils/message'
@@ -86,6 +91,8 @@ import useStore from '@/stores'
8691
import { cloneDeep } from 'lodash'
8792
import { EditionConst } from '@/utils/permission/data'
8893
import { hasPermission } from '@/utils/permission/index'
94+
import WorkspaceApi from '@/api/workspace/workspace.ts'
95+
import type { WorkspaceItem } from '@/api/type/workspace'
8996
9097
const loading = ref(false)
9198
const rLoading = ref(false)
@@ -97,7 +104,7 @@ const filterText = ref('')
97104
98105
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
99106
const tableHeight = ref(0)
100-
const { folder } = useStore()
107+
const { user } = useStore()
101108
102109
const settingTags = reactive([
103110
{
@@ -153,6 +160,7 @@ function submitPermissions() {
153160
return [...pre, ...next]
154161
}, [])
155162
AuthorizationApi.putResourceAuthorization(
163+
currentWorkspaceId.value || 'default',
156164
currentUser.value,
157165
{ user_resource_permission_list: user_resource_permission_list },
158166
rLoading,
@@ -169,7 +177,7 @@ function clickMemberHandle(item: any) {
169177
}
170178
171179
function getMember(id?: string) {
172-
AuthorizationApi.getUserMember(loading).then((res) => {
180+
AuthorizationApi.getUserMember(currentWorkspaceId.value || 'default', loading).then((res) => {
173181
memberList.value = res.data
174182
filterMember.value = res.data
175183
@@ -256,13 +264,20 @@ const dfsFolder = (arr: any[] = [], folderIdMap: any) => {
256264
}
257265
258266
function getFolder() {
259-
return folder.asyncGetFolder('KNOWLEDGE', {}, loading)
267+
return AuthorizationApi.getSystemFolder(
268+
currentWorkspaceId.value || 'default',
269+
'KNOWLEDGE',
270+
{},
271+
loading,
272+
)
260273
}
261-
262274
function getResourcePermissions(user_id: string) {
263-
return AuthorizationApi.getResourceAuthorization(user_id, rLoading)
275+
return AuthorizationApi.getResourceAuthorization(
276+
currentWorkspaceId.value || 'default',
277+
user_id,
278+
rLoading,
279+
)
264280
}
265-
266281
const getWholeTree = async (user_id: string) => {
267282
const [parentRes, childrenRes] = await Promise.all([getFolder(), getResourcePermissions(user_id)])
268283
if (!childrenRes.data || Object.keys(childrenRes.data).length > 0) {
@@ -313,7 +328,11 @@ const getFolderIdMap = (arr: any = []) => {
313328
}, {})
314329
}
315330
function ResourcePermissions(user_id: string) {
316-
AuthorizationApi.getResourceAuthorization(user_id, rLoading).then((res) => {
331+
AuthorizationApi.getResourceAuthorization(
332+
currentWorkspaceId.value || 'default',
333+
user_id,
334+
rLoading,
335+
).then((res) => {
317336
if (!res.data || Object.keys(res.data).length > 0) {
318337
settingTags.map((item: any) => {
319338
if (Object.keys(res.data).indexOf(item.value) !== -1) {
@@ -325,6 +344,23 @@ function ResourcePermissions(user_id: string) {
325344
})
326345
}
327346
347+
const workspaceList = ref<WorkspaceItem[]>([])
348+
const currentWorkspaceId = ref<string | undefined>('')
349+
const currentWorkspace = computed(() => {
350+
return workspaceList.value.find((w) => w.id == currentWorkspaceId.value)
351+
})
352+
async function getWorkspaceList() {
353+
if (user.isEE()) {
354+
const res = await WorkspaceApi.getSystemWorkspaceList(loading)
355+
workspaceList.value = res.data
356+
currentWorkspaceId.value = 'default'
357+
}
358+
}
359+
360+
function changeWorkspace(item: WorkspaceItem) {
361+
currentWorkspaceId.value = item.id
362+
getMember()
363+
}
328364
function refresh(data?: string[]) {}
329365
330366
onMounted(() => {
@@ -334,6 +370,7 @@ onMounted(() => {
334370
tableHeight.value = window.innerHeight - 330
335371
})()
336372
}
373+
getWorkspaceList()
337374
getMember()
338375
})
339376
</script>

ui/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export default defineConfig(({ mode }) => {
1717
const prefix = process.env.VITE_DYNAMIC_PREFIX || ENV.VITE_BASE_PATH
1818
const proxyConf: Record<string, string | ProxyOptions> = {}
1919
proxyConf['/api'] = {
20-
// target: 'http://43.166.1.146:8080',
21-
target: 'http://127.0.0.1:8080',
20+
target: 'http://43.166.1.146:8080',
21+
// target: 'http://127.0.0.1:8080',
2222
changeOrigin: true,
2323
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
2424
}

0 commit comments

Comments
 (0)