diff --git a/api_events/events/events/events_bind_modules.py b/api_events/events/events/events_bind_modules.py index c3fbd83..b205e0f 100644 --- a/api_events/events/events/events_bind_modules.py +++ b/api_events/events/events/events_bind_modules.py @@ -33,8 +33,10 @@ class ModulesBindOccupantEventMethods(MethodToEvent): living_space = BuildLivingSpace.filter_one( BuildLivingSpace.id == build_living_space_id, + system=True ).data modules = Modules.filter_all(Modules.is_default_module == True).data + print('living_space', living_space, 'modules', modules) if not living_space or not modules: print(f"Giving living Space or Modules: Default not found") return @@ -104,14 +106,14 @@ class ModulesBindEmployeeEventMethods(MethodToEvent): @classmethod def bind_default_module_for_first_init_occupant( - cls, employee_id: int, expires_at: str = None + cls, employee_id: int, expires_at: str = None ): employee = Employees.filter_one( Employees.id == employee_id, ).data modules = Modules.filter_all(Modules.is_default_module == True).data - + print('living_space', employee, 'modules', modules) if not employee or not modules: print(f"Giving living Space or Modules: Default not found") return diff --git a/api_events/events/identity/users.py b/api_events/events/identity/users.py index 535d84a..8f09513 100644 --- a/api_events/events/identity/users.py +++ b/api_events/events/identity/users.py @@ -87,7 +87,9 @@ class UserCreateEventMethods(MethodToEvent): company_uuid=created_user.related_company, ) mongo_query_identity.create_domain_via_user(payload=domain_via_user) - reset_password_token = created_user.reset_password_token(found_user=created_user) + reset_password_token = created_user.reset_password_token( + found_user=created_user + ) send_email_completed = send_email( subject=f"Dear {created_user.user_tag}, your password has been changed.", receivers=[str(created_user.email)], diff --git a/api_services/redis/auth_actions/auth.py b/api_services/redis/auth_actions/auth.py index 3e7163c..86d888e 100644 --- a/api_services/redis/auth_actions/auth.py +++ b/api_services/redis/auth_actions/auth.py @@ -175,7 +175,23 @@ def save_access_token_to_redis( company_address=company_address, ) ) - + print(dict( + access_token=access_token, + model_object=EmployeeTokenObject( + domain=domain, + user_type=UserType.employee.value, + user_uu_id=str(found_user.uu_id), + credentials=found_user.credentials(), + user_id=found_user.id, + person_id=found_user.person_id, + person_uu_id=str(found_user.person.uu_id), + request=dict(request.headers), + companies_uu_id_list=companies_uu_id_list, + companies_id_list=companies_id_list, + duty_uu_id_list=duty_uu_id_list, + duty_id_list=duty_id_list, + ), + )) save_object_to_redis( access_token=access_token, model_object=EmployeeTokenObject( diff --git a/databases/extensions/auth.py b/databases/extensions/auth.py index 595b8ce..f218e89 100644 --- a/databases/extensions/auth.py +++ b/databases/extensions/auth.py @@ -126,7 +126,7 @@ class AuthModule(PasswordModule): except Exception as e: err = e token_is_expired = system_arrow.now() >= system_arrow.get( - found_user.password_expiry_begins + str(found_user.password_expiry_begins) ).shift(days=replace_day) if not password_token == found_user.password_token and token_is_expired: @@ -157,7 +157,8 @@ class AuthModule(PasswordModule): found_user.hash_password = new_password_dict.get("password") found_user.password_token = "" if found_user.password_token else "" query_engine.refresh_password_history_via_user(payload=history_dict) - return found_user.save() + found_user.save() + return found_user @staticmethod def reset_password_token(found_user): @@ -241,7 +242,6 @@ class UserLoginModule(AuthModule): found_user.last_platform = headers_request.get("evyos-platform", None) found_user.last_remote_addr = headers_request.get("evyos-ip-ext", None) found_user.last_seen = str(system_arrow.now()) - if ext_ip := headers_request.get("evyos-ip-ext"): agent = headers_request.get("evyos-user-agent", "") platform = headers_request.get("evyos-platform", "") diff --git a/databases/sql_models/building/build.py b/databases/sql_models/building/build.py index 30885d1..40797fa 100644 --- a/databases/sql_models/building/build.py +++ b/databases/sql_models/building/build.py @@ -551,9 +551,7 @@ class BuildLivingSpace(CrudCollection): token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject], ): from databases import Services, OccupantTypes - from api_events.events.events.events_bind_services import ( - ServiceBindOccupantEventMethods, - ) + from api_events.events.events.events_bind_modules import ModulesBindOccupantEventMethods if data.get("expiry_starts"): data["expiry_starts"] = str(system_arrow.get(data["expiry_starts"])) @@ -566,18 +564,16 @@ class BuildLivingSpace(CrudCollection): related_service = Services.filter_by_one( related_responsibility=occupant_type.occupant_code, ).data - - created_living_space.save_and_confirm() - if not related_service: raise HTTPException( status_code=status.HTTP_418_IM_A_TEAPOT, detail="Service is not found in database. Re-enter service record then try again.", ) - ServiceBindOccupantEventMethods.bind_services_occupant_system( - service_id=related_service.id, + print('created_living_space', created_living_space.get_dict()) + ModulesBindOccupantEventMethods.bind_default_module_for_first_init_occupant( build_living_space_id=created_living_space.id, ) + created_living_space.save_and_confirm() return created_living_space @classmethod diff --git a/databases/sql_models/event/event.py b/databases/sql_models/event/event.py index 207fd8c..eef6962 100644 --- a/databases/sql_models/event/event.py +++ b/databases/sql_models/event/event.py @@ -216,7 +216,10 @@ class Event2Employee(CrudCollection): cls.employee_id == employee_id, ).data active_events = Service2Events.filter_all( - Service2Events.service_id.in_([event.event_service_id for event in occupant_events]), system=True + Service2Events.service_id.in_( + [event.event_service_id for event in occupant_events] + ), + system=True, ).data active_events_id = [event.event_id for event in active_events] if extra_events := Event2EmployeeExtra.filter_all( @@ -265,7 +268,10 @@ class Event2Occupant(CrudCollection): cls.build_living_space_id == build_living_space_id, ).data active_events = Service2Events.filter_all( - Service2Events.service_id.in_([event.event_service_id for event in occupant_events]), system=True + Service2Events.service_id.in_( + [event.event_service_id for event in occupant_events] + ), + system=True, ).data active_events_id = [event.event_id for event in active_events] if extra_events := Event2OccupantExtra.filter_all( diff --git a/service_app/routers/rules/router.py b/service_app/routers/rules/router.py index 621d5aa..99d40ae 100644 --- a/service_app/routers/rules/router.py +++ b/service_app/routers/rules/router.py @@ -44,23 +44,18 @@ def endpoint_restriction_update(request: Request, data: UpdateEndpointAccessList def endpoint_restriction_list(request: Request): token_dict, records = parse_token_object_to_dict(request=request), [] if isinstance(token_dict, OccupantTokenObject): - occupant_events = Event2Occupant.filter_all( - Event2Occupant.build_living_space_id - == token_dict.selected_occupant.living_space_id - ).data - events_list = Events.filter_all( - Events.id.in_([event.event_id for event in occupant_events]) - ).data + occupant_events = Event2Occupant.get_event_id_by_build_living_space_id( + build_living_space_id=token_dict.selected_occupant.living_space_id + ) + events_list = Events.filter_all(Events.id.in_(occupant_events)).data records = EndpointRestriction.filter_all( EndpointRestriction.id.in_([event.endpoint_id for event in events_list]) ).data elif isinstance(token_dict, EmployeeTokenObject): - employee_events = Event2Employee.filter_all( - Event2Employee.employee_id == token_dict.selected_company.employee_id - ).data - events_list = Events.filter_all( - Events.id.in_([event.event_id for event in employee_events]) - ).data + employee_events = Event2Employee.get_event_id_by_employee_id( + employee_id=token_dict.selected_company.employee_id + ) + events_list = Events.filter_all(Events.id.in_(employee_events)).data records = EndpointRestriction.filter_all( EndpointRestriction.id.in_([event.endpoint_id for event in events_list]) ).data diff --git a/service_app_test/bases.py b/service_app_test/bases.py index aef00b9..724a802 100644 --- a/service_app_test/bases.py +++ b/service_app_test/bases.py @@ -94,7 +94,7 @@ class RequestToApi: access_token = content.get("access_token") refresh_token = content.get("refresh_token") access_object = content.get("access_object") - print('access_object', access_object) + print("access_object", access_object) if not access_object: raise Exception("Access object is not found") @@ -112,8 +112,8 @@ class RequestToApi: self.set_access_token(access_token) if access_object.get("user_type") == "employee": - uu_id = companies_uu_id_list[0].get('uu_id') - print('uu_id', uu_id) + uu_id = companies_uu_id_list[0].get("uu_id") + print("uu_id", uu_id) refresh_company = self.post( endpoint="authentication/select", data={"company_uu_id": uu_id} ) diff --git a/service_app_test/test_application/migrate_old_data/runner.py b/service_app_test/test_application/migrate_old_data/runner.py index 9cf470d..8cc442f 100644 --- a/service_app_test/test_application/migrate_old_data/runner.py +++ b/service_app_test/test_application/migrate_old_data/runner.py @@ -50,7 +50,7 @@ def decode_as_json_indent(data): return json.dumps(json.loads(json.dumps(data)), indent=2) -password_token = "AVqRAPWQ9yvZqX14pWEAHfv72MsTYbjrlPNH97xDPr9RrDySPmu1zlPEH-IsQ9GNR1wrGQHv4xsR6eNbZYDe8rnvYbaiGOFpu1t18AMOZBEB3cKiashFCXznglPGd670QmAsRAqC-VO8GsIoGjtRr2ZQCKVY2lXTc3RcqRA26YXP31Bc-mDr_nzpjQCGrVcd" +password_token = "EKWKEMvmeXathlGjRPqnlmGA7ybWSuB9OWpyP0qPc-_K75pa0A5EDj7uxqjgk5Zaz_DJsm1Xugx4KbHT07cSRpRnc9IlTomQAORHwrVycaMno_nbNbLm85cRmrMXz2G4uOMkIqpdtWFI4SAmIwSMacZO3ns0RPYQSI_GnZhrrbAzXFJJq_aoW0N8uFbAdC5J" password_token_occ = "" login_data = { "domain": "evyos.com.tr",