Skip to content

Commit 538501c

Browse files
committed
refac
1 parent 0b6c92b commit 538501c

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

backend/open_webui/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,17 @@ def reachable(host: str, port: int) -> bool:
12871287
os.environ.get("DEFAULT_GROUP_ID", ""),
12881288
)
12891289

1290+
# Controls the default "Who can share to this group" setting for new groups.
1291+
# Env var values: "true" (anyone), "false" (no one), "members" (only group members).
1292+
_default_group_share = os.environ.get(
1293+
"DEFAULT_GROUP_SHARE_PERMISSION", "members"
1294+
).strip().lower()
1295+
DEFAULT_GROUP_SHARE_PERMISSION = (
1296+
"members"
1297+
if _default_group_share == "members"
1298+
else _default_group_share == "true"
1299+
)
1300+
12901301
PENDING_USER_OVERLAY_TITLE = PersistentConfig(
12911302
"PENDING_USER_OVERLAY_TITLE",
12921303
"ui.pending_user_overlay_title",

backend/open_webui/models/groups.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from sqlalchemy.orm import Session
88
from open_webui.internal.db import Base, JSONField, get_db, get_db_context
9+
from open_webui.config import DEFAULT_GROUP_SHARE_PERMISSION
910

1011
from open_webui.models.files import FileMetadataResponse
1112

@@ -130,13 +131,26 @@ class GroupListResponse(BaseModel):
130131

131132

132133
class GroupTable:
134+
def _ensure_default_share_config(self, group_data: dict) -> dict:
135+
"""Ensure the group data dict has a default share config if not already set."""
136+
if "data" not in group_data or group_data["data"] is None:
137+
group_data["data"] = {}
138+
if "config" not in group_data["data"]:
139+
group_data["data"]["config"] = {}
140+
if "share" not in group_data["data"]["config"]:
141+
group_data["data"]["config"]["share"] = DEFAULT_GROUP_SHARE_PERMISSION
142+
return group_data
143+
133144
def insert_new_group(
134145
self, user_id: str, form_data: GroupForm, db: Optional[Session] = None
135146
) -> Optional[GroupModel]:
136147
with get_db_context(db) as db:
148+
group_data = self._ensure_default_share_config(
149+
form_data.model_dump(exclude_none=True)
150+
)
137151
group = GroupModel(
138152
**{
139-
**form_data.model_dump(exclude_none=True),
153+
**group_data,
140154
"id": str(uuid.uuid4()),
141155
"user_id": user_id,
142156
"created_at": int(time.time()),
@@ -504,6 +518,11 @@ def create_groups_by_group_names(
504518
user_id=user_id,
505519
name=group_name,
506520
description="",
521+
data={
522+
"config": {
523+
"share": DEFAULT_GROUP_SHARE_PERMISSION,
524+
}
525+
},
507526
created_at=int(time.time()),
508527
updated_at=int(time.time()),
509528
)

src/lib/components/admin/Users/Groups/General.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<div class="flex items-center gap-2 p-1">
7979
<select
8080
class="text-sm bg-transparent outline-hidden rounded-lg px-2"
81-
value={data?.config?.share ?? true}
81+
value={data?.config?.share ?? 'members'}
8282
on:change={(e) => {
8383
const value = e.target.value;
8484
let shareValue;

0 commit comments

Comments
 (0)