forked from open-webui/open-webui
feat: super-admin (first one to signup)
This commit is contained in:
parent
a433315346
commit
68cfccedee
2 changed files with 8 additions and 1 deletions
|
@ -123,6 +123,13 @@ class UsersTable:
|
||||||
def get_num_users(self) -> Optional[int]:
|
def get_num_users(self) -> Optional[int]:
|
||||||
return User.select().count()
|
return User.select().count()
|
||||||
|
|
||||||
|
def get_first_user(self) -> UserModel:
|
||||||
|
try:
|
||||||
|
user = User.select().order_by(User.created_at).first()
|
||||||
|
return UserModel(**model_to_dict(user))
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def update_user_role_by_id(self, id: str, role: str) -> Optional[UserModel]:
|
def update_user_role_by_id(self, id: str, role: str) -> Optional[UserModel]:
|
||||||
try:
|
try:
|
||||||
query = User.update(role=role).where(User.id == id)
|
query = User.update(role=role).where(User.id == id)
|
||||||
|
|
|
@ -58,7 +58,7 @@ async def update_user_permissions(
|
||||||
@router.post("/update/role", response_model=Optional[UserModel])
|
@router.post("/update/role", response_model=Optional[UserModel])
|
||||||
async def update_user_role(form_data: UserRoleUpdateForm, user=Depends(get_admin_user)):
|
async def update_user_role(form_data: UserRoleUpdateForm, user=Depends(get_admin_user)):
|
||||||
|
|
||||||
if user.id != form_data.id:
|
if user.id != form_data.id and form_data.id != Users.get_first_user().id:
|
||||||
return Users.update_user_role_by_id(form_data.id, form_data.role)
|
return Users.update_user_role_by_id(form_data.id, form_data.role)
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
Loading…
Reference in a new issue