فهرست منبع

fix: display system collections and groups in WebUI

- Fix Collection type to have is_system at top level (matches API)
- Add include_system query param to groups API for superadmins
- Update Groups.tsx to fetch system groups when checkbox is checked
- Update Collections.tsx to use correct is_system field path
Fszontagh 6 ماه پیش
والد
کامیت
2b394f61f2
4فایلهای تغییر یافته به همراه40 افزوده شده و 10 حذف شده
  1. 27 0
      webserver/src/http_server.cpp
  2. 5 5
      webui/src/pages/Collections.tsx
  3. 6 4
      webui/src/pages/Groups.tsx
  4. 2 1
      webui/src/types/index.ts

+ 27 - 0
webserver/src/http_server.cpp

@@ -1976,6 +1976,9 @@ void HttpServer::HandleListGroups(const httplib::Request& req, httplib::Response
         if (IsSuperadmin(*auth_user) && req.has_param("include_deleted")) {
             include_deleted = req.get_param_value("include_deleted") == "true";
         }
+        bool include_system = IsSuperadmin(*auth_user) &&
+                              req.has_param("include_system") &&
+                              req.get_param_value("include_system") == "true";
 
         auto result = groupService_->ListGroups(workspace_id, limit, offset, include_deleted);
 
@@ -1988,12 +1991,36 @@ void HttpServer::HandleListGroups(const httplib::Request& req, httplib::Response
 
         // Build response
         nlohmann::json groups_array = nlohmann::json::array();
+
+        // Add global system groups first if requested
+        if (include_system) {
+            auto global_result = groupService_->ListSystemGroups();
+            if (global_result.success) {
+                for (const auto& group : global_result.groups) {
+                    nlohmann::json grp_json = {
+                        {"id", group.id},
+                        {"workspace_id", group.workspace_id},
+                        {"name", group.name},
+                        {"permissions", group.permissions},
+                        {"is_system", group.is_system},
+                        {"parent_group_id", group.parent_group_id},
+                        {"created_at", group.created_at},
+                        {"updated_at", group.updated_at},
+                        {"deleted_at", group.deleted_at}
+                    };
+                    groups_array.push_back(grp_json);
+                }
+            }
+        }
+
         for (const auto& group : result.groups) {
             nlohmann::json grp_json = {
                 {"id", group.id},
                 {"workspace_id", group.workspace_id},
                 {"name", group.name},
                 {"permissions", group.permissions},
+                {"is_system", group.is_system},
+                {"parent_group_id", group.parent_group_id},
                 {"created_at", group.created_at},
                 {"updated_at", group.updated_at}
             };

+ 5 - 5
webui/src/pages/Collections.tsx

@@ -509,7 +509,7 @@ function Collections() {
                       </div>
                     </td>
                     <td className="whitespace-nowrap px-6 py-4">
-                      {collection.settings?.is_system ? (
+                      {collection.is_system ? (
                         <span className="inline-flex rounded-full bg-purple-100 px-2 py-0.5 text-xs font-medium text-purple-800">
                           System
                         </span>
@@ -546,9 +546,9 @@ function Collections() {
                         <button
                           onClick={() => setEditingCollection(collection)}
                           className="rounded px-3 py-1 text-sm text-primary-600 hover:bg-primary-50"
-                          disabled={collection.settings?.is_system}
+                          disabled={collection.is_system}
                           title={
-                            collection.settings?.is_system
+                            collection.is_system
                               ? 'Cannot edit system collections'
                               : 'Edit'
                           }
@@ -558,9 +558,9 @@ function Collections() {
                         <button
                           onClick={() => setDeletingCollection(collection)}
                           className="rounded px-3 py-1 text-sm text-red-600 hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-50"
-                          disabled={collection.settings?.is_system}
+                          disabled={collection.is_system}
                           title={
-                            collection.settings?.is_system
+                            collection.is_system
                               ? 'Cannot delete system collections'
                               : 'Delete'
                           }

+ 6 - 4
webui/src/pages/Groups.tsx

@@ -204,16 +204,18 @@ function Groups() {
     setIsLoading(true)
     setError(null)
     try {
-      const response = await apiClient.get<{ groups: Group[] }>(
-        `/workspaces/${currentWorkspace.id}/groups`
-      )
+      let url = `/workspaces/${currentWorkspace.id}/groups`
+      if (showSystemGroups) {
+        url += '?include_system=true'
+      }
+      const response = await apiClient.get<{ groups: Group[] }>(url)
       setGroups(response.groups || [])
     } catch (err) {
       setError(err instanceof Error ? err.message : 'Failed to fetch groups')
     } finally {
       setIsLoading(false)
     }
-  }, [currentWorkspace])
+  }, [currentWorkspace, showSystemGroups])
 
   useEffect(() => {
     fetchGroups()

+ 2 - 1
webui/src/types/index.ts

@@ -76,9 +76,10 @@ export interface Collection {
   workspace_id: string
   document_count: number
   size_bytes: number
+  is_system: boolean
   created_at: string
   updated_at: string
-  settings: CollectionSettings
+  settings?: CollectionSettings
 }
 
 // Permission scope types