mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-04 02:28:02 -05:00
refac
This commit is contained in:
1 parent
6b1d890ffd
commit
464e83e414
15 files changed
+321
-255
No files matched your search
@@ -0,0 +1,18 @@
|
||||
from open_webui.models.access_grants import AccessGrants
|
||||
from open_webui.models.folders import Folders
|
||||
from open_webui.utils.access_control.folders import has_folder_access
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
|
||||
async def has_note_access(user_id: str, note, permission: str = 'read', db: AsyncSession | None = None) -> bool:
|
||||
"""Owner, a direct grant, or the same permission on the note's folder."""
|
||||
if note.user_id == user_id:
|
||||
return True
|
||||
if await AccessGrants.has_access(
|
||||
user_id=user_id, resource_type='note', resource_id=note.id, permission=permission, db=db
|
||||
):
|
||||
return True
|
||||
if note.folder_id:
|
||||
folder = await Folders.get_folder_by_id(note.folder_id, db=db)
|
||||
return bool(folder) and await has_folder_access(user_id, folder, permission, db)
|
||||
return False
|
||||
Reference in new issue
Block a user