You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/06/23 11:51:42 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #16609: API endpoint to create new user

uranusjr commented on a change in pull request #16609:
URL: https://github.com/apache/airflow/pull/16609#discussion_r657019061



##########
File path: airflow/api_connexion/endpoints/user_endpoint.py
##########
@@ -62,3 +64,43 @@ def get_users(limit, order_by='id', offset=None):
     users = query.offset(offset).limit(limit).all()
 
     return user_collection_schema.dump(UserCollection(users=users, total_entries=total_entries))
+
+
+@security.requires_access([(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_USER)])
+def post_user():
+    """Create a new user"""
+    try:
+        data = user_schema.load(request.json)
+    except ValidationError as e:
+        raise BadRequest(detail=str(e.messages))
+
+    security_manager = current_app.appbuilder.sm
+
+    user = security_manager.find_user(username=data["username"])
+    if user is not None:
+        detail = f"Username `{user.username}` already exists. Please update with PATCH endpoint."

Review comment:
       I just realised I didn’t include a PATCH endpoint 😆 
   
   ```suggestion
           detail = f"Username `{user.username}` already exists."
   ```




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org