refactor: streamline logging and permission checks in auths.py (#22960)
This commit is contained in:
1 parent
abe42eaf09
commit
05252e19b5
1 file changed
+3
-2
@@ -1155,8 +1155,9 @@ async def update_ldap_config(request: Request, form_data: LdapConfigForm, user=D
|
|||||||
# create api key
|
# create api key
|
||||||
@router.post('/api_key', response_model=ApiKey)
|
@router.post('/api_key', response_model=ApiKey)
|
||||||
async def generate_api_key(request: Request, user=Depends(get_current_user), db: Session = Depends(get_session)):
|
async def generate_api_key(request: Request, user=Depends(get_current_user), db: Session = Depends(get_session)):
|
||||||
if not request.app.state.config.ENABLE_API_KEYS or not has_permission(
|
if not request.app.state.config.ENABLE_API_KEYS or (
|
||||||
user.id, 'features.api_keys', request.app.state.config.USER_PERMISSIONS
|
user.role != 'admin'
|
||||||
|
and not has_permission(user.id, 'features.api_keys', request.app.state.config.USER_PERMISSIONS)
|
||||||
):
|
):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
|||||||
Reference in new issue
Block a user