From f6135ced5fc28131f5fbad748817f6aa4ceb3736 Mon Sep 17 00:00:00 2001 From: berkay Date: Mon, 11 Nov 2024 18:58:28 +0300 Subject: [PATCH] alchemy flush and save functions updated --- api_services/redis/auth_actions/auth.py | 5 ----- api_services/redis/functions.py | 2 -- databases/extensions/auth.py | 3 +-- databases/no_sql_models/identity.py | 4 +--- databases/no_sql_models/mongo_database.py | 1 - databases/sql_models/sql_operations.py | 3 ++- 6 files changed, 4 insertions(+), 14 deletions(-) diff --git a/api_services/redis/auth_actions/auth.py b/api_services/redis/auth_actions/auth.py index 9245539..399ddb5 100644 --- a/api_services/redis/auth_actions/auth.py +++ b/api_services/redis/auth_actions/auth.py @@ -50,7 +50,6 @@ def save_access_token_to_redis( Employees, Staff, ) - print('save_access_token_to_redis') if not found_user: raise HTTPException( status_code=400, @@ -58,10 +57,8 @@ def save_access_token_to_redis( # headers=json.loads(json.dumps(request.headers)), ) - print('save_access_token_to_redis', found_user) # Check user is already logged in or has a previous session already_tokens = get_object_via_user_uu_id(user_id=found_user.uu_id) - print('already_tokens', already_tokens) for key in already_tokens or []: token_user = json.loads(redis_cli.get(key).decode() or {}) if token_user.get("domain", "") == domain: @@ -70,7 +67,6 @@ def save_access_token_to_redis( access_token = ( found_user.generate_access_token() if not access_token else access_token ) - print('access_token', access_token) # Prepare the user's details to save in Redis Session if found_user.is_occupant: # Check if user is NOT an occupant living_spaces: list[BuildLivingSpace] = BuildLivingSpace.filter_all( @@ -84,7 +80,6 @@ def save_access_token_to_redis( ), # headers=json.loads(json.dumps(request.headers)), ) - print('living_spaces', living_spaces) occupants_selection_dict = {} for living_space in living_spaces: build_parts_selection = BuildParts.filter_active( diff --git a/api_services/redis/functions.py b/api_services/redis/functions.py index 77b1de0..978e49d 100644 --- a/api_services/redis/functions.py +++ b/api_services/redis/functions.py @@ -28,8 +28,6 @@ def get_object_via_access_key( already_tokens = redis_cli.scan_iter( match=str(request.headers.get(Auth.ACCESS_TOKEN_TAG) + ":*") ) - print('already_tokens', already_tokens) - if already_tokens := list(already_tokens): try: if redis_object := json.loads( diff --git a/databases/extensions/auth.py b/databases/extensions/auth.py index 5be1e9a..d163e0e 100644 --- a/databases/extensions/auth.py +++ b/databases/extensions/auth.py @@ -161,9 +161,8 @@ class AuthModule(PasswordModule): found_user.password_expiry_begins = str(system_arrow.now()) found_user.hash_password = new_password_dict.get("password") found_user.password_token = "" if found_user.password_token else "" - found_user.save() query_engine.refresh_password_history_via_user(payload=history_dict) - return + return found_user.save() @staticmethod def reset_password_token(found_user): diff --git a/databases/no_sql_models/identity.py b/databases/no_sql_models/identity.py index 5bec0bd..1d3449a 100644 --- a/databases/no_sql_models/identity.py +++ b/databases/no_sql_models/identity.py @@ -79,7 +79,6 @@ class MongoQueryIdentity: hashed_password = payload.password_add.get("password") for password_in_history in password_history_list: if str(password_in_history.get("password")) == str(hashed_password): - print('Password already used. Please enter a new password that you have not used last 3 times.') raise HTTPException( status_code=400, detail="Password already used. Please enter a new password that you have not used last 3 times.", @@ -89,7 +88,7 @@ class MongoQueryIdentity: password_history_list.pop(0) password_history_list.append(payload.password_add) - self.mongo_engine.update( + return self.mongo_engine.update( match=payload.user_uu_id, payload={ "password_history": password_history_list, @@ -98,7 +97,6 @@ class MongoQueryIdentity: }, field="user_uu_id", ) - return True def get_password_history_via_user(self, user_uu_id): self.use_collection("PasswordHistory") diff --git a/databases/no_sql_models/mongo_database.py b/databases/no_sql_models/mongo_database.py index 32fa7b8..d535496 100644 --- a/databases/no_sql_models/mongo_database.py +++ b/databases/no_sql_models/mongo_database.py @@ -61,7 +61,6 @@ class MongoQuery: return self.table.insert_many(documents=[payload]) def update(self, match, payload, field: str = "id"): - print('update', match, payload, field) if field == "id": filter_ = {"_id": ObjectId(match)} self.table.update_one(filter=filter_, update={"$set": payload}) diff --git a/databases/sql_models/sql_operations.py b/databases/sql_models/sql_operations.py index 1fe3f07..6474e0c 100644 --- a/databases/sql_models/sql_operations.py +++ b/databases/sql_models/sql_operations.py @@ -24,11 +24,11 @@ class FilterAttributes: FilterModel = ListOptions def flush(self): - from fastapi import status """Flush the current session.""" try: self.__session__.add(self) self.__session__.flush() + return self except SQLAlchemyError as e: self.raise_http_exception( status_code="HTTP_400_BAD_REQUEST", @@ -47,6 +47,7 @@ class FilterAttributes: """Saves the updated model to the current entity db.""" try: cls.__session__.commit() + return cls except SQLAlchemyError as e: cls.raise_http_exception( status_code="HTTP_400_BAD_REQUEST",