Skip to content

Commit

Permalink
clean aws sender records
Browse files Browse the repository at this point in the history
  • Loading branch information
KlemenSpruk committed Oct 12, 2023
1 parent 6310e4a commit 15109e5
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions django_project_base/base/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,31 @@ def trigger_changed(self, old_state=None, new_state=None, payload=None, **kwargs

if new_state.name == EMAIL_SENDER_ID_SETTING_NAME:
# TODO: THIS IS ONLY FOR AWS FOR NOW
# from django_project_base.aws.ses import AwsSes
from django_project_base.aws.ses import AwsSes

if not old_state:
print("AWS add EMAIL")
return
# AwsSes.add_sender_email(new_state.python_value)
# return
if (old_state.python_value != new_state.python_value) or (
AwsSes.add_sender_email(new_state.python_value)
elif (old_state.python_value != new_state.python_value) or (
new_state.python_value
and new_state.pending_value
and new_state.python_pending_value != new_state.python_value
):
return

print("AWS SEND EMAIL")
# AwsSes.add_sender_email(new_state.pending_value)
# return
# clear old email - or not what if another project is using email ???
# go through all project and delete diff AMAZON - DB
# ####### AwsSes.remove_sender_email(old_state.python_value) if old_state.python_value else None
AwsSes.add_sender_email(new_state.pending_value)

project_settings_manager = swapper.load_model("django_project_base", "ProjectSettings").objects
for sender in set(AwsSes.list_sender_emails()) - (
set(
project_settings_manager.objects.filter(name=EMAIL_SENDER_ID_SETTING_NAME).values_list(
"value", flat=True
)
)
| set(
project_settings_manager.objects.filter(name=EMAIL_SENDER_ID_SETTING_NAME).values_list(
"pending_value", flat=True
)
)
):
AwsSes.remove_sender_email(sender)


class SmsSenderChangedEvent(ProjectSettingChangedEvent):
Expand Down

0 comments on commit 15109e5

Please sign in to comment.