Skip to content

Commit

Permalink
fix: error when sending reports for autodelete (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMohammad20000 authored Dec 14, 2024
1 parent 8f662d4 commit 05851bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ def update_user(db: Session, dbuser: User, modify: UserModify) -> User:
for days_left in sorted(NOTIFY_DAYS_LEFT):
if not dbuser.expire or (calculate_expiration_days(
dbuser.expire) > days_left):
reminder = get_notification_reminder(db, dbuser.id, ReminderType.expiration_date, threshold=days_left)
reminder = get_notification_reminder(
db, dbuser.id, ReminderType.expiration_date, threshold=days_left)
if reminder:
delete_notification_reminder(db, reminder)
else:
Expand Down Expand Up @@ -739,7 +740,7 @@ def autodelete_expired_users(db: Session,
).filter(
auto_delete >= 0, # Negative values prevent auto-deletion
User.status.in_(target_status),
)
).options(joinedload(User.admin))

# TODO: Handle time filter in query itself (NOTE: Be careful with sqlite's strange datetime handling)
expired_users = [
Expand Down Expand Up @@ -1072,7 +1073,7 @@ def reset_admin_usage(db: Session, dbadmin: Admin) -> int:
"""
if (dbadmin.users_usage == 0):
return dbadmin

usage_log = AdminUsageLogs(
admin=dbadmin,
used_traffic_at_reset=dbadmin.users_usage
Expand Down
7 changes: 5 additions & 2 deletions app/jobs/remove_expired_users.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging

from app import logger, scheduler
from app.db import GetDB, crud
from app.jobs.utils import SYSTEM_ADMIN
from app.models.admin import Admin
from app.utils import report
from app.jobs.utils import SYSTEM_ADMIN
from config import USER_AUTODELETE_INCLUDE_LIMITED_ACCOUNTS


Expand All @@ -12,7 +13,9 @@ def remove_expired_users():
deleted_users = crud.autodelete_expired_users(db, USER_AUTODELETE_INCLUDE_LIMITED_ACCOUNTS)

for user in deleted_users:
report.user_deleted(user.username, SYSTEM_ADMIN, user_admin=Admin.model_validate(user.admin))
report.user_deleted(user.username, SYSTEM_ADMIN,
user_admin=Admin.model_validate(user.admin) if user.admin else None
)
logger.log(logging.INFO, "Expired user %s deleted." % user.username)


Expand Down

0 comments on commit 05851bd

Please sign in to comment.