uranusjr commented on a change in pull request #18757:
URL: https://github.com/apache/airflow/pull/18757#discussion_r722748881
##########
File path: airflow/api_connexion/endpoints/user_endpoint.py
##########
@@ -124,9 +124,21 @@ def patch_user(username, update_mask=None):
if user is None:
detail = f"The User with username `{username}` was not found"
raise NotFound(title="User not found", detail=detail)
-
- # Get fields to update. 'username' is always excluded (and it's an error to
- # include it in update_maek).
+ # Check unique username
+ new_username = data.get('username')
+ if new_username:
+ usr = security_manager.find_user(username=new_username)
Review comment:
This could use a better variable name⦠How about `existing_user`? (Same
for the email check below.)
##########
File path: airflow/api_connexion/endpoints/user_endpoint.py
##########
@@ -124,9 +124,21 @@ def patch_user(username, update_mask=None):
if user is None:
detail = f"The User with username `{username}` was not found"
raise NotFound(title="User not found", detail=detail)
-
- # Get fields to update. 'username' is always excluded (and it's an error to
- # include it in update_maek).
+ # Check unique username
+ new_username = data.get('username')
+ if new_username:
+ usr = security_manager.find_user(username=new_username)
+ if usr and usr != user:
+ raise AlreadyExists(detail=f"The username `{new_username}` already
exists")
+
+ # Check unique email
+ email = data.get('email')
+ if email:
+ usr = security_manager.find_user(email=email)
+ if usr and usr != user:
+ raise AlreadyExists(detail=f"The email `{email}` already exists")
Review comment:
I think we could save a round-trip to the database in many cases with
```python
if email and email != user.email:
```
Also, could either `user` and `email` be empty strings in the data schema?
We should emit 400 for those instead of treating them like missing fields (as
the logic implemented here would do).
##########
File path: airflow/api_connexion/endpoints/user_endpoint.py
##########
@@ -124,9 +124,21 @@ def patch_user(username, update_mask=None):
if user is None:
detail = f"The User with username `{username}` was not found"
raise NotFound(title="User not found", detail=detail)
-
- # Get fields to update. 'username' is always excluded (and it's an error to
- # include it in update_maek).
+ # Check unique username
+ new_username = data.get('username')
+ if new_username:
+ usr = security_manager.find_user(username=new_username)
+ if usr and usr != user:
Review comment:
When would the two users not match? `user` was obtained from the
username in the first place...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]