fix: workspace (#3320)
This commit is contained in:
parent
7acdd887bf
commit
f40e625ee1
@ -11,7 +11,6 @@ import os
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from itertools import product
|
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.mail.backends.smtp import EmailBackend
|
from django.core.mail.backends.smtp import EmailBackend
|
||||||
@ -71,6 +70,14 @@ def is_workspace_manage(user_id: str, workspace_id: str):
|
|||||||
return QuerySet(User).filter(id=user_id, role=RoleConstants.ADMIN.value.__str__()).exists()
|
return QuerySet(User).filter(id=user_id, role=RoleConstants.ADMIN.value.__str__()).exists()
|
||||||
|
|
||||||
|
|
||||||
|
def get_workspace_list_by_user(user_id):
|
||||||
|
get_workspace_list = DatabaseModelManage.get_model('get_workspace_list_by_user')
|
||||||
|
license_is_valid = DatabaseModelManage.get_model('license_is_valid') or (lambda: False)
|
||||||
|
if get_workspace_list is not None and license_is_valid():
|
||||||
|
return get_workspace_list(user_id)
|
||||||
|
return [{'id': 'default', 'name': 'default'}]
|
||||||
|
|
||||||
|
|
||||||
class UserProfileSerializer(serializers.Serializer):
|
class UserProfileSerializer(serializers.Serializer):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def profile(user: User, auth: Auth):
|
def profile(user: User, auth: Auth):
|
||||||
@ -80,6 +87,7 @@ class UserProfileSerializer(serializers.Serializer):
|
|||||||
@param auth: 认证对象
|
@param auth: 认证对象
|
||||||
@return:
|
@return:
|
||||||
"""
|
"""
|
||||||
|
workspace_list = get_workspace_list_by_user(user.id)
|
||||||
return {
|
return {
|
||||||
'id': user.id,
|
'id': user.id,
|
||||||
'username': user.username,
|
'username': user.username,
|
||||||
@ -89,6 +97,7 @@ class UserProfileSerializer(serializers.Serializer):
|
|||||||
'permissions': auth.permission_list,
|
'permissions': auth.permission_list,
|
||||||
'is_edit_password': user.role == RoleConstants.ADMIN.name and user.password == 'd880e722c47a34d8e9fce789fc62389d',
|
'is_edit_password': user.role == RoleConstants.ADMIN.name and user.password == 'd880e722c47a34d8e9fce789fc62389d',
|
||||||
'language': user.language,
|
'language': user.language,
|
||||||
|
'workspace_list': workspace_list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ interface User {
|
|||||||
IS_XPACK?: boolean
|
IS_XPACK?: boolean
|
||||||
XPACK_LICENSE_IS_VALID?: boolean
|
XPACK_LICENSE_IS_VALID?: boolean
|
||||||
language?: string
|
language?: string
|
||||||
|
workspace_list?: Array<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LoginRequest {
|
interface LoginRequest {
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu v-loading="loading">
|
<el-dropdown-menu v-loading="loading">
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
v-for="item in workspaceList"
|
v-for="item in user.workspace_list"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
||||||
@click="changeWorkspace(item)"
|
@click="changeWorkspace(item)"
|
||||||
@ -35,33 +35,20 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onBeforeMount, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import WorkspaceApi from '@/api/workspace/workspace'
|
|
||||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
|
||||||
const { user } = useStore()
|
const { user } = useStore()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const workspaceList = ref<WorkspaceItem[]>([])
|
|
||||||
const currentWorkspace = ref()
|
|
||||||
|
|
||||||
async function getWorkspaceList() {
|
const currentWorkspace = computed(() => {
|
||||||
try {
|
return user.workspace_list.find((w) => w.id == user.workspace_id)
|
||||||
const res = await WorkspaceApi.getWorkspaceListByUser(loading)
|
|
||||||
workspaceList.value = res.data
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
|
||||||
await getWorkspaceList()
|
|
||||||
const id = localStorage.getItem('workspace_id') ?? 'default'
|
|
||||||
currentWorkspace.value = workspaceList.value.find((item) => item.id === id)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function changeWorkspace(item: WorkspaceItem) {
|
function changeWorkspace(item: WorkspaceItem) {
|
||||||
if (item.id === currentWorkspace.value.id) return
|
if (item.id === user.workspace_id) return
|
||||||
currentWorkspace.value = item
|
|
||||||
user.setWorkspaceId(item.id || 'default')
|
user.setWorkspaceId(item.id || 'default')
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ export interface userStateTypes {
|
|||||||
edition: 'CE' | 'PE' | 'EE'
|
edition: 'CE' | 'PE' | 'EE'
|
||||||
themeInfo: any
|
themeInfo: any
|
||||||
workspace_id: string
|
workspace_id: string
|
||||||
|
workspace_list: Array<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
const useUserStore = defineStore('user', {
|
const useUserStore = defineStore('user', {
|
||||||
@ -33,6 +34,7 @@ const useUserStore = defineStore('user', {
|
|||||||
edition: 'CE',
|
edition: 'CE',
|
||||||
themeInfo: null,
|
themeInfo: null,
|
||||||
workspace_id: '',
|
workspace_id: '',
|
||||||
|
workspace_list: [],
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
getLanguage() {
|
getLanguage() {
|
||||||
@ -125,6 +127,15 @@ const useUserStore = defineStore('user', {
|
|||||||
async profile(loading?: Ref<boolean>) {
|
async profile(loading?: Ref<boolean>) {
|
||||||
return UserApi.getUserProfile(loading).then((ok) => {
|
return UserApi.getUserProfile(loading).then((ok) => {
|
||||||
this.userInfo = ok.data
|
this.userInfo = ok.data
|
||||||
|
const workspace_list =
|
||||||
|
ok.data.workspace_list && ok.data.workspace_list.length > 0
|
||||||
|
? ok.data.workspace_list
|
||||||
|
: [{ id: 'default', name: 'default' }]
|
||||||
|
const workspace_id = this.getWorkspaceId()
|
||||||
|
if (!workspace_id || !workspace_list.some((w) => w.id == workspace_id)) {
|
||||||
|
this.setWorkspaceId(workspace_list[0].id)
|
||||||
|
}
|
||||||
|
this.workspace_list = workspace_list
|
||||||
useLocalStorage<string>(localeConfigKey, 'en-US').value =
|
useLocalStorage<string>(localeConfigKey, 'en-US').value =
|
||||||
ok?.data?.language || this.getLanguage()
|
ok?.data?.language || this.getLanguage()
|
||||||
const theme = useThemeStore()
|
const theme = useThemeStore()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user