From dd576bade3449057803248450ac453b29e6a60a5 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 5 Oct 2026 10:40:09 +0400 Subject: [PATCH] refac --- backend/open_webui/models/groups.py | 13 +++++++++---- .../workspace/common/AccessControl.svelte | 12 +++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/open_webui/models/groups.py b/backend/open_webui/models/groups.py index 611afe576d..60c84936e0 100644 --- a/backend/open_webui/models/groups.py +++ b/backend/open_webui/models/groups.py @@ -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: diff --git a/src/lib/components/workspace/common/AccessControl.svelte b/src/lib/components/workspace/common/AccessControl.svelte index 6037cf76cf..8e3ee70e12 100644 --- a/src/lib/components/workspace/common/AccessControl.svelte +++ b/src/lib/components/workspace/common/AccessControl.svelte @@ -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 @@
{group.name} - {group?.member_count} {$i18n.t('members')} + {#if group.member_count != null} + {group.member_count} {$i18n.t('members')} + {/if}