Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions backend/apps/system/api/workspace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from fastapi import APIRouter, HTTPException, Query
from sqlmodel import exists, or_, select, delete as sqlmodel_delete
from sqlmodel import exists, or_, select, delete as sqlmodel_delete, update as sqlmodel_update
from apps.system.crud.user import clean_user_cache
from apps.system.crud.workspace import reset_single_user_oid, reset_user_oid
from apps.system.models.system_model import UserWsModel, WorkspaceBase, WorkspaceEditor, WorkspaceModel
Expand Down Expand Up @@ -204,13 +204,21 @@ async def get_one(session: SessionDep, trans: Trans, id: int):
return db_model

@router.delete("/{id}")
async def single_delete(session: SessionDep, id: int):
async def single_delete(session: SessionDep, current_user: CurrentUser, id: int):
if not current_user.isAdmin:
raise HTTPException("only admin can delete workspace")
if id == 1:
raise HTTPException(f"Can not delete default workspace")
db_model = session.get(WorkspaceModel, id)
if not db_model:
raise HTTPException(f"WorkspaceModel with id {id} not found")

if current_user.oid == id:
current_user.oid = 1 # reset to default workspace
update_stmt = sqlmodel_update(UserModel).where(UserModel.id == current_user.id).values(oid=1)
session.exec(update_stmt)
await clean_user_cache(current_user.id)

user_ws_list = session.exec(select(UserWsModel).where(UserWsModel.oid == id)).all()
if user_ws_list:
# clean user cache
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/layout/Workspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const formatKeywords = (item: string) => {
const emit = defineEmits(['selectWorkspace'])

const handleDefaultWorkspaceChange = (item: any) => {
if (item.id.toString() === currentWorkspace.value.id.toString()) {
if (currentWorkspace.value?.id && item.id.toString() === currentWorkspace.value.id.toString()) {
return
}
currentWorkspace.value = { id: item.id, name: item.name }
Expand Down Expand Up @@ -81,8 +81,8 @@ onMounted(async () => {
<el-icon size="18">
<icon_moments_categories_outlined></icon_moments_categories_outlined>
</el-icon>
<span v-if="!collapse" :title="currentWorkspace.name" class="name ellipsis">{{
currentWorkspace.name
<span v-if="!collapse" :title="currentWorkspace?.name || ''" class="name ellipsis">{{
currentWorkspace?.name || ''
}}</span>
<el-icon v-if="!collapse" style="transform: scale(0.5)" class="expand" size="24">
<icon_expand_down_filled></icon_expand_down_filled>
Expand All @@ -107,7 +107,7 @@ onMounted(async () => {
v-for="ele in defaultWorkspaceListWithSearch"
:key="ele.name"
class="popover-item"
:class="currentWorkspace.id === ele.id && 'isActive'"
:class="currentWorkspace?.id === ele.id && 'isActive'"
@click="handleDefaultWorkspaceChange(ele)"
>
<el-icon size="16">
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/views/system/workspace/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import delIcon from '@/assets/svg/icon_delete.svg'
import icon_more_outlined from '@/assets/svg/icon_more_outlined.svg'
import icon_done_outlined from '@/assets/svg/icon_done_outlined.svg'

import { useUserStore } from '@/stores/user'

const userStore = useUserStore()

const { t } = useI18n()
const multipleSelectionAll = ref<any[]>([])
const tableList = ref([] as any[])
Expand Down Expand Up @@ -259,12 +263,16 @@ const delWorkspace = (row: any) => {
customClass: 'confirm-no_icon',
autofocus: false,
}).then(() => {
workspaceDelete(row.id).then(() => {
workspaceDelete(row.id).then(async () => {
ElMessage({
type: 'success',
message: t('dashboard.delete_success'),
})
init()
if (row.id === userStore.getOid) {
userStore.setOid('1')
await userStore.info()
}
})
})
}
Expand Down