diff --git a/src/authx/auth.py b/src/authx/auth.py index 7fc4ad2..f2c9101 100644 --- a/src/authx/auth.py +++ b/src/authx/auth.py @@ -638,6 +638,8 @@ def add_program_to_opa(program_auth): response2, status_code = set_service_store_secret("opa", key="programs", value=json.dumps(response2)) return response, status_code + # add the users to the preapproved user list + return {"message": f"{program_id} not added"}, status_code @@ -822,7 +824,7 @@ def clear_pending_users_in_opa(): def list_preapproved_users_in_opa(): response, status_code = get_service_store_secret("opa", key=f"preapproved_users") if status_code == 200: - response = list(response["preapproved_users"].keys()) + response = response["preapproved_users"] return response, status_code @@ -842,18 +844,16 @@ def get_preapproved_user(user_name): def add_preapproved_user_in_opa(user_name): response, status_code = get_service_store_secret("opa", key=f"preapproved_users") - if status_code != 200: - return response, status_code - preapproved_users = response["preapproved_users"] - if user_name in preapproved_users: - user_dict = preapproved_users[user_name] - user_dict["dac_authorizations"] = {} - response2, status_code = write_user_in_opa(user_dict) - if status_code == 200: - preapproved_users.pop(user_name) - response3, status_code = set_service_store_secret("opa", key=f"preapproved_users", value=json.dumps(response)) - else: - return {"error": f"no preapproved user with ID {user_name}"}, 404 + + if user_name in response["preapproved_users"]: + # return 200 to indicate OK but nothing was added + return {"message": f"User {user_name} already pending"}, 200 + + response["preapproved_users"].append(user_name) + + response, status_code = set_service_store_secret("opa", key=f"preapproved_users", value=json.dumps(response)) + if status_code == 200: + return response, 201 # 201 created, to indicate that we added the user return response, status_code