validations and dockerfiles are updated
This commit is contained in:
@@ -6,6 +6,20 @@ from databases.no_sql_models.validations import (
|
||||
AccessHistoryViaUser,
|
||||
)
|
||||
from databases.no_sql_models.mongo_database import MongoQuery
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
|
||||
|
||||
def validate_timestamp(doc):
|
||||
"""Validate and fix timestamp fields in MongoDB documents"""
|
||||
if not doc:
|
||||
return doc
|
||||
|
||||
timestamp_fields = ['modified_at', 'created_at', 'accessed_at', 'timestamp']
|
||||
for field in timestamp_fields:
|
||||
if field in doc and not isinstance(doc[field], (int, float)):
|
||||
# Convert to proper timestamp if it's not already
|
||||
doc[field] = system_arrow.to_timestamp(doc[field])
|
||||
return doc
|
||||
|
||||
|
||||
class MongoQueryIdentity:
|
||||
@@ -42,7 +56,7 @@ class MongoQueryIdentity:
|
||||
"user_uu_id": payload.user_uu_id,
|
||||
"other_domains_list": [payload.main_domain],
|
||||
"main_domain": payload.main_domain,
|
||||
"modified_at": datetime.datetime.now().timestamp(),
|
||||
"modified_at": system_arrow.to_timestamp(system_arrow.now()),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -52,14 +66,15 @@ class MongoQueryIdentity:
|
||||
match=payload.user_uu_id,
|
||||
payload={
|
||||
"other_domains_list": payload.other_domains_list,
|
||||
"modified_at": datetime.datetime.now().timestamp(),
|
||||
"modified_at": system_arrow.to_timestamp(system_arrow.now()),
|
||||
},
|
||||
field="user_uu_id",
|
||||
)
|
||||
|
||||
def get_domain_via_user(self, user_uu_id):
|
||||
self.use_collection("Domain")
|
||||
return self.mongo_engine.get_one(match=str(user_uu_id), field="user_uu_id")
|
||||
result = self.mongo_engine.find(match=user_uu_id, field="user_uu_id")
|
||||
return [validate_timestamp(doc) for doc in result] if result else None
|
||||
|
||||
def refresh_password_history_via_user(self, payload: PasswordHistoryViaUser):
|
||||
self.use_collection("PasswordHistory")
|
||||
@@ -96,14 +111,15 @@ class MongoQueryIdentity:
|
||||
payload={
|
||||
"password_history": password_history_list,
|
||||
"access_history_detail": payload.access_history_detail,
|
||||
"modified_at": datetime.datetime.now().timestamp(),
|
||||
"modified_at": system_arrow.to_timestamp(system_arrow.now()),
|
||||
},
|
||||
field="user_uu_id",
|
||||
)
|
||||
|
||||
def get_password_history_via_user(self, user_uu_id):
|
||||
self.use_collection("PasswordHistory")
|
||||
return self.mongo_engine.get_one(match=user_uu_id, field="user_uu_id")
|
||||
self.use_collection("UserPasswordHistory")
|
||||
result = self.mongo_engine.find(match=user_uu_id, field="user_uu_id")
|
||||
return [validate_timestamp(doc) for doc in result] if result else None
|
||||
|
||||
def update_access_history_via_user(self, payload: AccessHistoryViaUser):
|
||||
self.use_collection("AccessHistory")
|
||||
@@ -119,7 +135,7 @@ class MongoQueryIdentity:
|
||||
payload={
|
||||
"user_uu_id": payload.user_uu_id,
|
||||
"access_history": access_history,
|
||||
"modified_at": datetime.datetime.now().timestamp(),
|
||||
"modified_at": system_arrow.to_timestamp(system_arrow.now()),
|
||||
},
|
||||
field="user_uu_id",
|
||||
)
|
||||
@@ -127,14 +143,11 @@ class MongoQueryIdentity:
|
||||
payload={
|
||||
"user_uu_id": payload.user_uu_id,
|
||||
"access_history": [payload.access_history],
|
||||
"modified_at": datetime.datetime.now().timestamp(),
|
||||
"modified_at": system_arrow.to_timestamp(system_arrow.now()),
|
||||
}
|
||||
)
|
||||
|
||||
def get_access_history_via_user(self, user_uu_id):
|
||||
self.use_collection("AccessHistory")
|
||||
return self.mongo_engine.filter_by(
|
||||
payload={"user_uu_id": user_uu_id},
|
||||
sort_by="modified_at",
|
||||
sort_direction="desc",
|
||||
)
|
||||
result = self.mongo_engine.find(match=user_uu_id, field="user_uu_id")
|
||||
return [validate_timestamp(doc) for doc in result] if result else None
|
||||
|
||||
Reference in New Issue
Block a user