|
6 | 6 |
|
7 | 7 | from sqlalchemy.orm import Session |
8 | 8 | from open_webui.internal.db import Base, JSONField, get_db, get_db_context |
| 9 | +from open_webui.config import DEFAULT_GROUP_SHARE_PERMISSION |
9 | 10 |
|
10 | 11 | from open_webui.models.files import FileMetadataResponse |
11 | 12 |
|
@@ -130,13 +131,26 @@ class GroupListResponse(BaseModel): |
130 | 131 |
|
131 | 132 |
|
132 | 133 | 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 | + |
133 | 144 | def insert_new_group( |
134 | 145 | self, user_id: str, form_data: GroupForm, db: Optional[Session] = None |
135 | 146 | ) -> Optional[GroupModel]: |
136 | 147 | with get_db_context(db) as db: |
| 148 | + group_data = self._ensure_default_share_config( |
| 149 | + form_data.model_dump(exclude_none=True) |
| 150 | + ) |
137 | 151 | group = GroupModel( |
138 | 152 | **{ |
139 | | - **form_data.model_dump(exclude_none=True), |
| 153 | + **group_data, |
140 | 154 | "id": str(uuid.uuid4()), |
141 | 155 | "user_id": user_id, |
142 | 156 | "created_at": int(time.time()), |
@@ -504,6 +518,11 @@ def create_groups_by_group_names( |
504 | 518 | user_id=user_id, |
505 | 519 | name=group_name, |
506 | 520 | description="", |
| 521 | + data={ |
| 522 | + "config": { |
| 523 | + "share": DEFAULT_GROUP_SHARE_PERMISSION, |
| 524 | + } |
| 525 | + }, |
507 | 526 | created_at=int(time.time()), |
508 | 527 | updated_at=int(time.time()), |
509 | 528 | ) |
|
0 commit comments