Skip to content

Commit

Permalink
feat: add extra fields to /admin/user POST endpoint
Browse files Browse the repository at this point in the history
...to make user creation more uniform, reflecting what is also done elsewhere
in fence/sync/sync_users.py _upsert_userinfo() for example
  • Loading branch information
pieterlukasse committed Sep 24, 2024
1 parent a976efc commit f7e2d40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
16 changes: 15 additions & 1 deletion fence/blueprints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,22 @@ def create_user():
username = request.get_json().get("name", None)
role = request.get_json().get("role", None)
email = request.get_json().get("email", None)
display_name = request.get_json().get("display_name", None)
phone_number = request.get_json().get("phone_number", None)
idp_name = request.get_json().get("idp_name", None)
tags = request.get_json().get("tags", None)

return jsonify(
admin.create_user(current_app.scoped_session(), username, role, email)
admin.create_user(
current_app.scoped_session(),
username,
role,
email,
display_name,
phone_number,
idp_name,
tags,
)
)


Expand Down
15 changes: 14 additions & 1 deletion fence/resources/admin/admin_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ def get_user_groups(current_session, username):
return {"groups": user_groups_info}


def create_user(current_session, username, role, email):
def create_user(
current_session,
username,
role,
email,
display_name=None,
phone_number=None,
ipd_name=None,
tags=None,
):
"""
Create a user for all the projects or groups in the list.
If the user already exists, to avoid unadvertedly changing it, we suggest update
Expand Down Expand Up @@ -123,6 +132,10 @@ def create_user(current_session, username, role, email):
is_admin = role == "admin"
email_add = email
usr = User(username=username, active=True, is_admin=is_admin, email=email_add)
usr.display_name = display_name
usr.phone_number = phone_number
usr.ipd_name = ipd_name
usr.tags = tags
current_session.add(usr)
return us.get_user_info(current_session, username)

Expand Down

0 comments on commit f7e2d40

Please sign in to comment.