2023-11-07 05:00:09 +00:00
|
|
|
from django.template.loader import render_to_string
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-01-10 11:02:18 +00:00
|
|
|
|
2024-03-21 03:05:04 +00:00
|
|
|
from accounts.models import ChangeSecretRecord
|
2023-11-07 07:10:46 +00:00
|
|
|
from common.tasks import send_mail_attachment_async, upload_backup_to_obj_storage
|
2023-11-07 05:00:09 +00:00
|
|
|
from notifications.notifications import UserMessage
|
2023-11-07 07:10:46 +00:00
|
|
|
from terminal.models.component.storage import ReplayStorage
|
2023-12-13 08:15:34 +00:00
|
|
|
from users.models import User
|
2022-01-10 11:02:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AccountBackupExecutionTaskMsg(object):
|
|
|
|
subject = _('Notification of account backup route task results')
|
|
|
|
|
|
|
|
def __init__(self, name: str, user: User):
|
|
|
|
self.name = name
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name = self.name
|
|
|
|
if self.user.secret_key:
|
2023-01-16 11:02:09 +00:00
|
|
|
return _('{} - The account backup passage task has been completed.'
|
|
|
|
' See the attachment for details').format(name)
|
|
|
|
else:
|
|
|
|
return _("{} - The account backup passage task has been completed: "
|
|
|
|
"the encryption password has not been set - "
|
2023-12-13 08:15:34 +00:00
|
|
|
"please go to personal information -> Basic file encryption password for preference settings"
|
|
|
|
).format(name)
|
2022-01-10 11:02:18 +00:00
|
|
|
|
|
|
|
def publish(self, attachment_list=None):
|
2022-11-04 03:15:34 +00:00
|
|
|
send_mail_attachment_async(
|
2022-01-10 11:02:18 +00:00
|
|
|
self.subject, self.message, [self.user.email], attachment_list
|
|
|
|
)
|
2022-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
|
2023-11-07 07:10:46 +00:00
|
|
|
class AccountBackupByObjStorageExecutionTaskMsg(object):
|
|
|
|
subject = _('Notification of account backup route task results')
|
|
|
|
|
|
|
|
def __init__(self, name: str, obj_storage: ReplayStorage):
|
|
|
|
self.name = name
|
|
|
|
self.obj_storage = obj_storage
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name = self.name
|
|
|
|
return _('{} - The account backup passage task has been completed.'
|
|
|
|
' See the attachment for details').format(name)
|
|
|
|
|
|
|
|
def publish(self, attachment_list=None):
|
|
|
|
upload_backup_to_obj_storage(
|
|
|
|
self.obj_storage, attachment_list
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-03 14:39:48 +00:00
|
|
|
class ChangeSecretExecutionTaskMsg(object):
|
|
|
|
subject = _('Notification of implementation result of encryption change plan')
|
|
|
|
|
2024-01-24 08:20:44 +00:00
|
|
|
def __init__(self, name: str, user: User, summary):
|
2022-11-03 14:39:48 +00:00
|
|
|
self.name = name
|
|
|
|
self.user = user
|
2024-01-24 08:20:44 +00:00
|
|
|
self.summary = summary
|
2022-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name = self.name
|
|
|
|
if self.user.secret_key:
|
2024-01-24 08:20:44 +00:00
|
|
|
default_message = _('{} - The encryption change task has been completed. '
|
|
|
|
'See the attachment for details').format(name)
|
|
|
|
|
2023-01-16 11:02:09 +00:00
|
|
|
else:
|
2024-01-24 08:20:44 +00:00
|
|
|
default_message = _("{} - The encryption change task has been completed: the encryption "
|
|
|
|
"password has not been set - please go to personal information -> "
|
2024-01-24 11:50:05 +00:00
|
|
|
"set encryption password in preferences").format(name)
|
2024-01-24 08:20:44 +00:00
|
|
|
return self.summary + '\n' + default_message
|
2022-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
def publish(self, attachments=None):
|
2022-11-04 03:15:34 +00:00
|
|
|
send_mail_attachment_async(
|
2022-11-03 14:39:48 +00:00
|
|
|
self.subject, self.message, [self.user.email], attachments
|
|
|
|
)
|
2023-11-07 05:00:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GatherAccountChangeMsg(UserMessage):
|
|
|
|
subject = _('Gather account change information')
|
|
|
|
|
|
|
|
def __init__(self, user, change_info: dict):
|
|
|
|
self.change_info = change_info
|
|
|
|
super().__init__(user)
|
|
|
|
|
|
|
|
def get_html_msg(self) -> dict:
|
|
|
|
context = {'change_info': self.change_info}
|
|
|
|
message = render_to_string('accounts/asset_account_change_info.html', context)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'subject': str(self.subject),
|
|
|
|
'message': message
|
|
|
|
}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
|
|
|
user = User.objects.first()
|
|
|
|
return cls(user, {})
|
2024-03-21 03:05:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChangeSecretFailedMsg(UserMessage):
|
|
|
|
subject = _('Change secret or push account failed information')
|
|
|
|
|
|
|
|
def __init__(self, name, execution_id, user, asset_account_errors: list):
|
|
|
|
self.name = name
|
|
|
|
self.execution_id = execution_id
|
|
|
|
self.asset_account_errors = asset_account_errors
|
|
|
|
super().__init__(user)
|
|
|
|
|
|
|
|
def get_html_msg(self) -> dict:
|
|
|
|
context = {
|
|
|
|
'name': self.name,
|
|
|
|
'recipient': self.user,
|
|
|
|
'execution_id': self.execution_id,
|
|
|
|
'asset_account_errors': self.asset_account_errors
|
|
|
|
}
|
|
|
|
message = render_to_string('accounts/change_secret_failed_info.html', context)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'subject': str(self.subject),
|
|
|
|
'message': message
|
|
|
|
}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
2024-03-21 03:32:23 +00:00
|
|
|
name = 'test'
|
2024-03-21 03:05:04 +00:00
|
|
|
user = User.objects.first()
|
|
|
|
record = ChangeSecretRecord.objects.first()
|
2024-03-21 03:32:23 +00:00
|
|
|
execution_id = str(record.execution_id)
|
|
|
|
return cls(name, execution_id, user, [])
|