[PR #23992] [CLOSED] feat: add per-group knowledge base file count and size limits #66325

Closed
opened 2026-05-06 12:37:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/23992
Author: @rbx
Created: 4/22/2026
Status: Closed

Base: devHead: kb-limits


📝 Commits (1)

  • 464a2dd feat: add per-group knowledge base file count and size limits

📊 Changes

13 files changed (+346 additions, -25 deletions)

View changed files

📝 backend/open_webui/config.py (+20 -0)
📝 backend/open_webui/main.py (+23 -1)
📝 backend/open_webui/models/knowledge.py (+12 -0)
📝 backend/open_webui/routers/knowledge.py (+51 -1)
📝 backend/open_webui/routers/users.py (+3 -1)
backend/open_webui/test/util/conftest.py (+5 -0)
backend/open_webui/test/util/test_access_control.py (+125 -0)
📝 backend/open_webui/utils/access_control/__init__.py (+58 -0)
📝 src/lib/components/admin/Users/Groups/Permissions.svelte (+28 -1)
📝 src/lib/components/workspace/Knowledge/KnowledgeBase.svelte (+12 -10)
📝 src/lib/components/workspace/Models/Knowledge.svelte (+3 -11)
📝 src/lib/constants/permissions.ts (+2 -0)
📝 src/lib/i18n/locales/en-US/translation.json (+4 -0)

📄 Description

Resolves #23848

Description

Adds optional per-group (and global default) limits on the number of files and maximum file size for knowledge base uploads. Limits are enforced both in the backend and early in the frontend upload pipeline (before text extraction begins). Admins always bypass both limits.

Pull Request Checklist

  • Target branch: dev
  • Description: See above
  • Changelog: Added below
  • Documentation: Companion docs PR: open-webui/docs#1209
  • Dependencies: No new dependencies
  • Testing: Manual testing performed; unit tests added for combine_permissions and get_permission_value
  • Agentic AI Code: I confirm this PR has gone through human review and manual testing
  • Code review: Self-reviewed
  • Design & Architecture: Limits follow existing additive/most-permissive permission semantics; no new settings patterns introduced
  • Git Hygiene: Single atomic commit, rebased on dev
  • Title Prefix: feat:

Changelog Entry

Description

Adds per-group knowledge base upload limits: maximum file count and maximum file size per knowledge base. Configured via Group Permissions UI; enforced in backend and frontend. Admins bypass all limits.

Added

  • WorkspacePermissions extended with knowledge_max_count and knowledge_max_size (nullable int fields)
  • DEFAULT_PERMISSIONS in permissions.ts gains the two nullable fields
  • Group Permissions UI: numeric inputs for both limits beneath the Knowledge Access toggle (0 / empty = unlimited)
  • New get_permission_value() utility in access_control - mirrors has_permission but returns a raw value (int/bool/None) instead of a boolean
  • /api/config resolves and exposes knowledge.max_count and knowledge.max_size per-user
  • USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_MAX_COUNT and USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_MAX_SIZE env vars to set default limits at startup (0 = unlimited, unset = unlimited)
  • Unit tests for integer-valued permission merging and get_permission_value

Changed

  • combine_permissions extended to handle integer-valued permissions using most-permissive semantics: 0 = unlimited always wins, otherwise the maximum across groups
  • KnowledgeBase.svelte and Models/Knowledge.svelte check limits before calling uploadFile
  • Backend enforces limits in both /{id}/file/add and /{id}/files/batch/add

Additional Information

Screenshots or Videos

image

Contributor License Agreement


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/23992 **Author:** [@rbx](https://github.com/rbx) **Created:** 4/22/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `kb-limits` --- ### 📝 Commits (1) - [`464a2dd`](https://github.com/open-webui/open-webui/commit/464a2dd58da8861e8d2f26b26b4fbdfebd5b3278) feat: add per-group knowledge base file count and size limits ### 📊 Changes **13 files changed** (+346 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/config.py` (+20 -0) 📝 `backend/open_webui/main.py` (+23 -1) 📝 `backend/open_webui/models/knowledge.py` (+12 -0) 📝 `backend/open_webui/routers/knowledge.py` (+51 -1) 📝 `backend/open_webui/routers/users.py` (+3 -1) ➕ `backend/open_webui/test/util/conftest.py` (+5 -0) ➕ `backend/open_webui/test/util/test_access_control.py` (+125 -0) 📝 `backend/open_webui/utils/access_control/__init__.py` (+58 -0) 📝 `src/lib/components/admin/Users/Groups/Permissions.svelte` (+28 -1) 📝 `src/lib/components/workspace/Knowledge/KnowledgeBase.svelte` (+12 -10) 📝 `src/lib/components/workspace/Models/Knowledge.svelte` (+3 -11) 📝 `src/lib/constants/permissions.ts` (+2 -0) 📝 `src/lib/i18n/locales/en-US/translation.json` (+4 -0) </details> ### 📄 Description Resolves #23848 ## Description Adds optional per-group (and global default) limits on the number of files and maximum file size for knowledge base uploads. Limits are enforced both in the backend and early in the frontend upload pipeline (before text extraction begins). Admins always bypass both limits. ## Pull Request Checklist - [x] **Target branch:** `dev` - [x] **Description:** See above - [x] **Changelog:** Added below - [x] **Documentation:** Companion docs PR: open-webui/docs#1209 - [x] **Dependencies:** No new dependencies - [x] **Testing:** Manual testing performed; unit tests added for `combine_permissions` and `get_permission_value` - [x] **Agentic AI Code:** I confirm this PR has gone through human review and manual testing - [x] **Code review:** Self-reviewed - [x] **Design & Architecture:** Limits follow existing additive/most-permissive permission semantics; no new settings patterns introduced - [x] **Git Hygiene:** Single atomic commit, rebased on `dev` - [x] **Title Prefix:** `feat:` --- # Changelog Entry ### Description Adds per-group knowledge base upload limits: maximum file count and maximum file size per knowledge base. Configured via Group Permissions UI; enforced in backend and frontend. Admins bypass all limits. ### Added - `WorkspacePermissions` extended with `knowledge_max_count` and `knowledge_max_size` (nullable int fields) - `DEFAULT_PERMISSIONS` in `permissions.ts` gains the two nullable fields - Group Permissions UI: numeric inputs for both limits beneath the Knowledge Access toggle (`0` / empty = unlimited) - New `get_permission_value()` utility in `access_control` - mirrors `has_permission` but returns a raw value (int/bool/None) instead of a boolean - `/api/config` resolves and exposes `knowledge.max_count` and `knowledge.max_size` per-user - `USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_MAX_COUNT` and `USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_MAX_SIZE` env vars to set default limits at startup (`0` = unlimited, unset = unlimited) - Unit tests for integer-valued permission merging and `get_permission_value` ### Changed - `combine_permissions` extended to handle integer-valued permissions using most-permissive semantics: `0` = unlimited always wins, otherwise the maximum across groups - `KnowledgeBase.svelte` and `Models/Knowledge.svelte` check limits before calling `uploadFile` - Backend enforces limits in both `/{id}/file/add` and `/{id}/files/batch/add` --- ### Additional Information - Issue: #23848 - Limits are per-knowledge-base, not per-user total - Integer permissions use the same additive model as boolean permissions: most-permissive value across all group memberships wins; `0` (unlimited) always takes precedence over any finite cap - Admins bypass limits in both frontend and backend ### Screenshots or Videos <img width="877" height="235" alt="image" src="https://github.com/user-attachments/assets/1a6daaf8-3428-4d90-8fa9-b3475dcde682" /> --- ### Contributor License Agreement - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 12:37:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#66325