Fix of the encryption of when getting the upcoming events for a user
This commit is contained in:
@@ -265,7 +265,9 @@ def remove_done():
|
|||||||
|
|
||||||
|
|
||||||
def get_upcoming_for_user(user: str, limit: int = 25):
|
def get_upcoming_for_user(user: str, limit: int = 25):
|
||||||
"""Return upcoming appointment plans for a user, matching by encrypted username."""
|
"""
|
||||||
|
Return upcoming appointment plans for a user, handling encrypted database records.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
if hasattr(globals(), 'remove_done'):
|
if hasattr(globals(), 'remove_done'):
|
||||||
remove_done()
|
remove_done()
|
||||||
@@ -279,20 +281,26 @@ def get_upcoming_for_user(user: str, limit: int = 25):
|
|||||||
items = db['appointments']
|
items = db['appointments']
|
||||||
|
|
||||||
today = datetime.date.today().strftime('%Y-%m-%d')
|
today = datetime.date.today().strftime('%Y-%m-%d')
|
||||||
|
target_user = str(user or '').strip()
|
||||||
|
|
||||||
cursor = items.find(
|
cursor = items.find(
|
||||||
_active_record_query(
|
_active_record_query({
|
||||||
{
|
|
||||||
'user': user,
|
|
||||||
'date_end': {'$gte': today},
|
'date_end': {'$gte': today},
|
||||||
}
|
})
|
||||||
)
|
|
||||||
).sort('date_start', 1)
|
).sort('date_start', 1)
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for item in cursor:
|
for item in cursor:
|
||||||
item['_id'] = str(item.get('_id'))
|
decrypted_item = _decrypt_appointment(item)
|
||||||
results.append(item)
|
if not decrypted_item:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if decrypted_item.get('user', '').strip() != target_user:
|
||||||
|
continue
|
||||||
|
|
||||||
|
decrypted_item['_id'] = str(decrypted_item.get('_id'))
|
||||||
|
results.append(decrypted_item)
|
||||||
|
|
||||||
if len(results) >= max(1, int(limit)):
|
if len(results) >= max(1, int(limit)):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user