forked from open-webui/open-webui
fix: delete auth with user
This commit is contained in:
parent
48cc2c5053
commit
5b4bf45ad2
3 changed files with 22 additions and 4 deletions
|
@ -109,5 +109,21 @@ class AuthsTable:
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def delete_auth_by_id(self, id: str) -> Optional[UserModel]:
|
||||||
|
try:
|
||||||
|
# Delete User
|
||||||
|
result = Users.delete_user_by_id(id)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
# Delete Auth
|
||||||
|
query = Auth.delete().where(Auth.id == id)
|
||||||
|
query.execute() # Remove the rows, return number of rows removed.
|
||||||
|
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
Auths = AuthsTable(DB)
|
Auths = AuthsTable(DB)
|
||||||
|
|
|
@ -8,7 +8,7 @@ from utils.utils import decode_token
|
||||||
from utils.misc import get_gravatar_url
|
from utils.misc import get_gravatar_url
|
||||||
|
|
||||||
from apps.web.internal.db import DB
|
from apps.web.internal.db import DB
|
||||||
from apps.web.models.chats import Chat
|
from apps.web.models.chats import Chats
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
@ -115,7 +115,7 @@ class UsersTable:
|
||||||
def delete_user_by_id(self, id: str) -> bool:
|
def delete_user_by_id(self, id: str) -> bool:
|
||||||
try:
|
try:
|
||||||
# Delete User Chats
|
# Delete User Chats
|
||||||
result = Chat.delete_chats_by_user_id(id)
|
result = Chats.delete_chats_by_user_id(id)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
# Delete User
|
# Delete User
|
||||||
|
|
|
@ -9,6 +9,8 @@ import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from apps.web.models.users import UserModel, UserRoleUpdateForm, Users
|
from apps.web.models.users import UserModel, UserRoleUpdateForm, Users
|
||||||
|
from apps.web.models.auths import Auths
|
||||||
|
|
||||||
|
|
||||||
from utils.utils import (
|
from utils.utils import (
|
||||||
get_password_hash,
|
get_password_hash,
|
||||||
|
@ -76,7 +78,7 @@ async def update_user_role(form_data: UserRoleUpdateForm, cred=Depends(bearer_sc
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
# DeleteUser
|
# DeleteUserById
|
||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +90,7 @@ async def delete_user_by_id(user_id: str, cred=Depends(bearer_scheme)):
|
||||||
if user:
|
if user:
|
||||||
if user.role == "admin":
|
if user.role == "admin":
|
||||||
if user.id != user_id:
|
if user.id != user_id:
|
||||||
result = Users.delete_user_by_id(user_id)
|
result = Auths.delete_auth_by_id(user_id)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue