From 1c51796e5247c12e01d60850a4f3fe532d8ca74b Mon Sep 17 00:00:00 2001 From: George Taylor Date: Wed, 24 Jul 2024 11:58:51 +0100 Subject: [PATCH] Better summary for update user roles job (#53) * :ambulance: Use sync search and add summary for searches and actions * Formatted code with black --line-length 120 * better debugging --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- cli/ldap_cmds/user.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/cli/ldap_cmds/user.py b/cli/ldap_cmds/user.py index 2313548..6432b66 100644 --- a/cli/ldap_cmds/user.py +++ b/cli/ldap_cmds/user.py @@ -249,6 +249,9 @@ def update_roles( log.exception("Failed to connect to LDAP") raise e + removed = 0 + not_removed = 0 + failed = 0 for item in cartesian_product: if add: try: @@ -287,19 +290,19 @@ def update_roles( failed = failed + 1 else: log.error("No action specified") - - log.info("SUMMARY") - log.info("User/role searches:") - log.info(f"Found {len(roles_found)} users with roles matching the role filter") - log.info(f"Found {len(users_found)} users matching the user filter") - - log.info("This produces the following matches:") - log.info(f"Found {len(matched_users)} users with roles matching the role filter and user filter") - - log.info("Actions:") - log.info(f"Successfully removed {removed} roles") - log.info(f"Roles already absent for {not_removed} users") - log.info(f"Failed to remove {failed} roles due to errors") + + log.info("\n==========================\n\tSUMMARY\n==========================") + log.info("User/role searches:") + log.info(f" - Found {len(roles_found)} users with roles matching the role filter") + log.info(f" - Found {len(users_found)} users matching the user filter") + + log.info("This produces the following matches:") + log.info(f" - Found {len(matched_users)} users with roles matching the role filter and user filter") + + log.info("Actions:") + log.info(f" - Successfully removed {removed} roles") + log.info(f" - Roles already absent for {not_removed} users") + log.info(f" - Failed to remove {failed} roles due to errors") if update_notes: connection = cli.database.connection()