enh: access grant level perms
This commit is contained in:
@@ -28,7 +28,7 @@ from open_webui.constants import ERROR_MESSAGES
|
||||
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.access_control import has_permission
|
||||
from open_webui.models.access_grants import AccessGrants, has_public_read_access_grant
|
||||
from open_webui.models.access_grants import AccessGrants, has_public_read_access_grant, has_user_access_grant, strip_user_access_grants
|
||||
from open_webui.internal.db import get_session
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -296,6 +296,18 @@ async def update_note_by_id(
|
||||
):
|
||||
form_data.access_grants = []
|
||||
|
||||
# Strip individual user sharing if user lacks permission
|
||||
if (
|
||||
user.role != "admin"
|
||||
and has_user_access_grant(form_data.access_grants)
|
||||
and not has_permission(
|
||||
user.id,
|
||||
"access_grants.allow_users",
|
||||
request.app.state.config.USER_PERMISSIONS,
|
||||
)
|
||||
):
|
||||
form_data.access_grants = strip_user_access_grants(form_data.access_grants)
|
||||
|
||||
try:
|
||||
note = Notes.update_note_by_id(id, form_data, db=db)
|
||||
await sio.emit(
|
||||
@@ -376,6 +388,18 @@ async def update_note_access_by_id(
|
||||
)
|
||||
]
|
||||
|
||||
# Strip individual user sharing if user lacks permission
|
||||
if (
|
||||
user.role != "admin"
|
||||
and has_user_access_grant(form_data.access_grants)
|
||||
and not has_permission(
|
||||
user.id,
|
||||
"access_grants.allow_users",
|
||||
request.app.state.config.USER_PERMISSIONS,
|
||||
)
|
||||
):
|
||||
form_data.access_grants = strip_user_access_grants(form_data.access_grants)
|
||||
|
||||
AccessGrants.set_access_grants("note", id, form_data.access_grants, db=db)
|
||||
|
||||
return Notes.get_note_by_id(id, db=db)
|
||||
|
||||
Reference in New Issue
Block a user