Skip to content

Commit

Permalink
feat: add soft-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Nov 6, 2024
1 parent b583a70 commit 24b357c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fence/blueprints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ def delete_user(username):
return response


@blueprint.route("/users/<username>/soft", methods=["DELETE"])
@blueprint.route("/user/<username>/soft", methods=["DELETE"])
@admin_login_required
@debug_log
def soft_delete_user(username):
"""
Soft-remove the user by marking it as active=False.
Returns json object
"""
response = jsonify(admin.soft_delete_user(current_app.scoped_session(), username))
return response


@blueprint.route("/users/<username>/groups", methods=["GET"])
@blueprint.route("/user/<username>/groups", methods=["GET"])
@admin_login_required
Expand Down
12 changes: 12 additions & 0 deletions fence/resources/admin/admin_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"update_user",
"add_user_to_projects",
"delete_user",
"soft_delete_user",
"add_user_to_groups",
"connect_user_to_group",
"remove_user_from_groups",
Expand Down Expand Up @@ -359,6 +360,17 @@ def raise_unavailable(gpg_email):
logger.info("Done with Google deletions.")


def soft_delete_user(current_session, username):
"""
Soft-remove the user by marking it as active=False.
"""
logger.debug("Soft-delete user.")
usr = us.get_user(current_session, username)
usr.active = False
current_session.commit()
return us.get_user_info(current_session, usr.username)


def delete_user(current_session, username):
"""
Remove a user from both the userdatamodel
Expand Down

0 comments on commit 24b357c

Please sign in to comment.