auth updated availaible event
This commit is contained in:
parent
88309eb49d
commit
9e955841c3
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)],
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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", "")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue