mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-07 02:58:21 +00:00
refac
This commit is contained in:
parent
d4a2d11ecf
commit
dd576bade3
2 changed files with 16 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ from typing import Optional
|
|||
|
||||
from open_webui.env import DEFAULT_GROUP_SHARE_PERMISSION
|
||||
from open_webui.internal.db import Base, JSONField, get_async_db_context
|
||||
from open_webui.models.access_grants import AccessGrant
|
||||
from open_webui.models.files import FileMetadataResponse
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from sqlalchemy import (
|
||||
|
|
@ -433,22 +434,26 @@ class GroupTable:
|
|||
return None
|
||||
|
||||
async def delete_group_by_id(self, id: str, db: Optional[AsyncSession] = None) -> bool:
|
||||
try:
|
||||
async with get_async_db_context(db) as db:
|
||||
async with get_async_db_context(db) as db:
|
||||
try:
|
||||
await db.execute(delete(Group).filter_by(id=id))
|
||||
await db.execute(delete(AccessGrant).filter_by(principal_type='group', principal_id=id))
|
||||
await db.commit()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
except Exception:
|
||||
await db.rollback()
|
||||
return False
|
||||
|
||||
async def delete_all_groups(self, db: Optional[AsyncSession] = None) -> bool:
|
||||
async with get_async_db_context(db) as db:
|
||||
try:
|
||||
await db.execute(delete(Group))
|
||||
await db.execute(delete(AccessGrant).filter_by(principal_type='group'))
|
||||
await db.commit()
|
||||
|
||||
return True
|
||||
except Exception:
|
||||
await db.rollback()
|
||||
return False
|
||||
|
||||
async def remove_user_from_all_groups(self, user_id: str, db: Optional[AsyncSession] = None) -> bool:
|
||||
|
|
|
|||
|
|
@ -424,8 +424,8 @@
|
|||
})
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
$: accessGroups = groups
|
||||
.filter((group) => readGroupIds.includes(group.id) || writeGroupIds.includes(group.id))
|
||||
$: accessGroups = Array.from(new Set([...readGroupIds, ...writeGroupIds]))
|
||||
.map((id) => groups.find((group) => group.id === id) ?? { id, name: id })
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
$: if (selectedUserIds.length > 0) {
|
||||
|
|
@ -599,9 +599,11 @@
|
|||
|
||||
<div class="truncate text-sm flex items-center gap-2">
|
||||
{group.name}
|
||||
<span class="text-xs text-gray-400 font-normal"
|
||||
>{group?.member_count} {$i18n.t('members')}</span
|
||||
>
|
||||
{#if group.member_count != null}
|
||||
<span class="text-xs text-gray-400 font-normal"
|
||||
>{group.member_count} {$i18n.t('members')}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue