mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:02:46 +00:00
feat: resource-authorization
This commit is contained in:
parent
1287da6ed0
commit
687fd6cb84
|
|
@ -4,22 +4,22 @@ import type { pageRequest } from '@/api/type/common'
|
|||
import type { Ref } from 'vue'
|
||||
|
||||
import useStore from '@/stores'
|
||||
const prefix: any = { _value: '/workspace/' }
|
||||
Object.defineProperty(prefix, 'value', {
|
||||
get: function () {
|
||||
const { user } = useStore()
|
||||
return this._value + user.getWorkspaceId()
|
||||
},
|
||||
})
|
||||
const prefix = '/workspace'
|
||||
|
||||
/**
|
||||
* 获取资源权限
|
||||
* @query 参数
|
||||
*/
|
||||
const getResourceAuthorization: (
|
||||
workspace_id: string,
|
||||
user_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<any>> = (user_id, loading) => {
|
||||
return get(`${prefix.value}/user_resource_permission/user/${user_id}`, undefined, loading)
|
||||
) => Promise<Result<any>> = (workspace_id, user_id, loading) => {
|
||||
return get(
|
||||
`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`,
|
||||
undefined,
|
||||
loading,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,24 +41,45 @@ const getResourceAuthorization: (
|
|||
}
|
||||
*/
|
||||
const putResourceAuthorization: (
|
||||
workspace_id: string,
|
||||
user_id: string,
|
||||
body: any,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<any>> = (user_id, body, loading) => {
|
||||
return put(`${prefix.value}/user_resource_permission/user/${user_id}`, body, loading)
|
||||
) => Promise<Result<any>> = (workspace_id, user_id, body, loading) => {
|
||||
return put(`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`, body, loading)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取成员列表
|
||||
* @query 参数
|
||||
*/
|
||||
const getUserList: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
||||
return get(`${prefix.value}/user_list`, undefined, loading)
|
||||
const getUserList: (workspace_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||
workspace_id,
|
||||
loading,
|
||||
) => {
|
||||
return get(`${prefix}/${workspace_id}/user_list`, undefined, loading)
|
||||
}
|
||||
|
||||
const getUserMember: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
||||
return get(`${prefix.value}/user_member`, undefined, loading)
|
||||
const getUserMember: (workspace_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||
workspace_id,
|
||||
loading,
|
||||
) => {
|
||||
return get(`${prefix}/${workspace_id}/user_member`, undefined, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得系统文件夹列表
|
||||
* @params 参数
|
||||
* source : APPLICATION, KNOWLEDGE, TOOL
|
||||
* data : {name: string}
|
||||
*/
|
||||
const getSystemFolder: (
|
||||
workspace_id: string,
|
||||
source: string,
|
||||
data?: any,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Array<any>>> = (workspace_id, source, data, loading) => {
|
||||
return get(`${prefix}/${workspace_id}/${source}/folder`, data, loading)
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
@ -66,4 +87,5 @@ export default {
|
|||
putResourceAuthorization,
|
||||
getUserList,
|
||||
getUserMember,
|
||||
getSystemFolder,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<template #dropdown>
|
||||
<el-dropdown-menu v-loading="loading">
|
||||
<el-dropdown-item
|
||||
v-for="item in user.workspace_list"
|
||||
v-for="item in data"
|
||||
:key="item.id"
|
||||
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
||||
@click="changeWorkspace(item)"
|
||||
|
|
@ -37,19 +37,21 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||
import useStore from '@/stores'
|
||||
|
||||
const { user } = useStore()
|
||||
const loading = ref(false)
|
||||
|
||||
const currentWorkspace = computed(() => {
|
||||
return user.workspace_list.find((w) => w.id == user.workspace_id)
|
||||
const props = defineProps({
|
||||
data: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
currentWorkspace: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
const emit = defineEmits(['changeWorkspace'])
|
||||
function changeWorkspace(item: WorkspaceItem) {
|
||||
if (item.id === user.workspace_id) return
|
||||
user.setWorkspaceId(item.id || 'default')
|
||||
window.location.reload()
|
||||
emit('changeWorkspace', item)
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,12 @@
|
|||
direction="vertical"
|
||||
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||
/>
|
||||
<WorkspaceDropdown v-if="hasPermission(EditionConst.IS_EE, 'OR')" />
|
||||
<WorkspaceDropdown
|
||||
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||
:data="user.workspace_list"
|
||||
:currentWorkspace="currentWorkspace"
|
||||
@changeWorkspace="changeWorkspace"
|
||||
/>
|
||||
</div>
|
||||
<TopMenu></TopMenu>
|
||||
<TopAbout></TopAbout>
|
||||
|
|
@ -22,11 +27,24 @@
|
|||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import TopMenu from './top-menu/index.vue'
|
||||
import Avatar from './avatar/index.vue'
|
||||
import TopAbout from './top-about/index.vue'
|
||||
import { EditionConst } from '@/utils/permission/data'
|
||||
import { hasPermission } from '@/utils/permission/index'
|
||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||
import useStore from '@/stores'
|
||||
const { user } = useStore()
|
||||
const currentWorkspace = computed(() => {
|
||||
return user.workspace_list.find((w) => w.id == user.workspace_id)
|
||||
})
|
||||
|
||||
function changeWorkspace(item: WorkspaceItem) {
|
||||
if (item.id === user.workspace_id) return
|
||||
user.setWorkspaceId(item.id || 'default')
|
||||
window.location.reload()
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.app-top-bar-container {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@
|
|||
direction="vertical"
|
||||
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||
/>
|
||||
<WorkspaceDropdown v-if="hasPermission(EditionConst.IS_EE, 'OR')" />
|
||||
<WorkspaceDropdown
|
||||
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||
:data="workspaceList"
|
||||
:currentWorkspace="currentWorkspace"
|
||||
@changeWorkspace="changeWorkspace"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<el-card style="--el-card-padding: 0">
|
||||
|
|
@ -76,7 +81,7 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, ref, reactive, watch } from 'vue'
|
||||
import { onMounted, ref, reactive, watch, computed } from 'vue'
|
||||
import AuthorizationApi from '@/api/user/resource-authorization'
|
||||
import PermissionSetting from './component/PermissionSetting.vue'
|
||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||
|
|
@ -86,6 +91,8 @@ import useStore from '@/stores'
|
|||
import { cloneDeep } from 'lodash'
|
||||
import { EditionConst } from '@/utils/permission/data'
|
||||
import { hasPermission } from '@/utils/permission/index'
|
||||
import WorkspaceApi from '@/api/workspace/workspace.ts'
|
||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||
|
||||
const loading = ref(false)
|
||||
const rLoading = ref(false)
|
||||
|
|
@ -97,7 +104,7 @@ const filterText = ref('')
|
|||
|
||||
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
|
||||
const tableHeight = ref(0)
|
||||
const { folder } = useStore()
|
||||
const { user } = useStore()
|
||||
|
||||
const settingTags = reactive([
|
||||
{
|
||||
|
|
@ -153,6 +160,7 @@ function submitPermissions() {
|
|||
return [...pre, ...next]
|
||||
}, [])
|
||||
AuthorizationApi.putResourceAuthorization(
|
||||
currentWorkspaceId.value || 'default',
|
||||
currentUser.value,
|
||||
{ user_resource_permission_list: user_resource_permission_list },
|
||||
rLoading,
|
||||
|
|
@ -169,7 +177,7 @@ function clickMemberHandle(item: any) {
|
|||
}
|
||||
|
||||
function getMember(id?: string) {
|
||||
AuthorizationApi.getUserMember(loading).then((res) => {
|
||||
AuthorizationApi.getUserMember(currentWorkspaceId.value || 'default', loading).then((res) => {
|
||||
memberList.value = res.data
|
||||
filterMember.value = res.data
|
||||
|
||||
|
|
@ -256,13 +264,20 @@ const dfsFolder = (arr: any[] = [], folderIdMap: any) => {
|
|||
}
|
||||
|
||||
function getFolder() {
|
||||
return folder.asyncGetFolder('KNOWLEDGE', {}, loading)
|
||||
return AuthorizationApi.getSystemFolder(
|
||||
currentWorkspaceId.value || 'default',
|
||||
'KNOWLEDGE',
|
||||
{},
|
||||
loading,
|
||||
)
|
||||
}
|
||||
|
||||
function getResourcePermissions(user_id: string) {
|
||||
return AuthorizationApi.getResourceAuthorization(user_id, rLoading)
|
||||
return AuthorizationApi.getResourceAuthorization(
|
||||
currentWorkspaceId.value || 'default',
|
||||
user_id,
|
||||
rLoading,
|
||||
)
|
||||
}
|
||||
|
||||
const getWholeTree = async (user_id: string) => {
|
||||
const [parentRes, childrenRes] = await Promise.all([getFolder(), getResourcePermissions(user_id)])
|
||||
if (!childrenRes.data || Object.keys(childrenRes.data).length > 0) {
|
||||
|
|
@ -313,7 +328,11 @@ const getFolderIdMap = (arr: any = []) => {
|
|||
}, {})
|
||||
}
|
||||
function ResourcePermissions(user_id: string) {
|
||||
AuthorizationApi.getResourceAuthorization(user_id, rLoading).then((res) => {
|
||||
AuthorizationApi.getResourceAuthorization(
|
||||
currentWorkspaceId.value || 'default',
|
||||
user_id,
|
||||
rLoading,
|
||||
).then((res) => {
|
||||
if (!res.data || Object.keys(res.data).length > 0) {
|
||||
settingTags.map((item: any) => {
|
||||
if (Object.keys(res.data).indexOf(item.value) !== -1) {
|
||||
|
|
@ -325,6 +344,23 @@ function ResourcePermissions(user_id: string) {
|
|||
})
|
||||
}
|
||||
|
||||
const workspaceList = ref<WorkspaceItem[]>([])
|
||||
const currentWorkspaceId = ref<string | undefined>('')
|
||||
const currentWorkspace = computed(() => {
|
||||
return workspaceList.value.find((w) => w.id == currentWorkspaceId.value)
|
||||
})
|
||||
async function getWorkspaceList() {
|
||||
if (user.isEE()) {
|
||||
const res = await WorkspaceApi.getSystemWorkspaceList(loading)
|
||||
workspaceList.value = res.data
|
||||
currentWorkspaceId.value = 'default'
|
||||
}
|
||||
}
|
||||
|
||||
function changeWorkspace(item: WorkspaceItem) {
|
||||
currentWorkspaceId.value = item.id
|
||||
getMember()
|
||||
}
|
||||
function refresh(data?: string[]) {}
|
||||
|
||||
onMounted(() => {
|
||||
|
|
@ -334,6 +370,7 @@ onMounted(() => {
|
|||
tableHeight.value = window.innerHeight - 330
|
||||
})()
|
||||
}
|
||||
getWorkspaceList()
|
||||
getMember()
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ export default defineConfig(({ mode }) => {
|
|||
const prefix = process.env.VITE_DYNAMIC_PREFIX || ENV.VITE_BASE_PATH
|
||||
const proxyConf: Record<string, string | ProxyOptions> = {}
|
||||
proxyConf['/api'] = {
|
||||
// target: 'http://43.166.1.146:8080',
|
||||
target: 'http://127.0.0.1:8080',
|
||||
target: 'http://43.166.1.146:8080',
|
||||
// target: 'http://127.0.0.1:8080',
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue