Skip to content

Commit

Permalink
fix: run ruf formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Pioupuch authored Feb 18, 2025
1 parent 8865045 commit 0d6f985
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions backend/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ def check_controls_with_expired_eta():
for owner_email, controls in owner_controls.items():
send_notification_email_expired_eta(owner_email, controls)


# @db_periodic_task(crontab(minute='*/1'))# for testing
@db_periodic_task(crontab(hour="5", minute="30"))
def check_deprecated_controls():
deprecated_controls_list = (
AppliedControl.objects
.filter(status="active")
.filter(expiry_date__lte=date.today(), expiry_date__isnull=False)
deprecated_controls_list = AppliedControl.objects.filter(status="active").filter(
expiry_date__lte=date.today(), expiry_date__isnull=False
)

deprecated_controls = deprecated_controls_list.prefetch_related("owner")
Expand All @@ -56,10 +55,11 @@ def check_deprecated_controls():

# Update the status of each expired control
deprecated_controls_list.update(status="deprecated")

for owner_email, controls in owner_controls.items():
send_notification_email_deprecated_control(owner_email, controls)


@task()
def send_notification_email_expired_eta(owner_email, controls):
if not check_email_configuration(owner_email, controls):
Expand All @@ -75,13 +75,16 @@ def send_notification_email_expired_eta(owner_email, controls):

send_notification_email(subject, message, owner_email)


@task()
def send_notification_email_deprecated_control(owner_email, controls):
if not check_email_configuration(owner_email, controls):
return

subject = f"CISO Assistant: You have {len(controls)} deprecated control(s)"
message = "Hello,\n\nThe following controls have the expiracy date set to today:\n\n"
message = (
"Hello,\n\nThe following controls have the expiracy date set to today:\n\n"
)
for control in controls:
message += f"- {control.name} (Set to: deprecated)\n"
message += "\nThis control(s) will be set to deprecated.\n"
Expand All @@ -90,6 +93,7 @@ def send_notification_email_deprecated_control(owner_email, controls):

send_notification_email(subject, message, owner_email)


@task()
def send_notification_email(subject, message, owner_email):
try:
Expand All @@ -105,9 +109,9 @@ def send_notification_email(subject, message, owner_email):
except Exception as e:
logger.error(f"Failed to send notification email to {owner_email}: {str(e)}")


@task()
def check_email_configuration(owner_email, controls):
# TODO this will probably will move to a common section later on.
notifications_enable_mailing = GlobalSettings.objects.get(name="general").value.get(
"notifications_enable_mailing", False
)
Expand All @@ -133,5 +137,5 @@ def check_email_configuration(owner_email, controls):
if not owner_email:
logger.error("Cannot send email notification: No recipient email provided")
return False

return True

0 comments on commit 0d6f985

Please sign in to comment.