From f3bd727c3271a1dfae8f78f7c47dd63b62148853 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:53:47 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=94=B9=E5=AF=86=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=8F=91=E7=BB=99=E6=94=B6=E4=BB=B6=E4=BA=BA=20(#13009)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: feng <1304903146@qq.com> --- .../automations/change_secret/manager.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index 160988748..644bec384 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -240,27 +240,28 @@ class ChangeSecretManager(AccountBasePlaybookManager): r for r in recorders if r.status == ChangeSecretRecordStatusChoice.failed.value ] - super_users = User.get_super_admins() - if failed_recorders and super_users: + recipients = self.execution.recipients + recipients = User.objects.filter(id__in=list(recipients.keys())) + if not recipients: + return + + if failed_recorders: name = self.execution.snapshot.get('name') execution_id = str(self.execution.id) _ids = [r.id for r in failed_recorders] asset_account_errors = ChangeSecretRecord.objects.filter( id__in=_ids).values_list('asset__name', 'account__username', 'error') - for user in super_users: + for user in recipients: ChangeSecretFailedMsg(name, execution_id, user, asset_account_errors).publish() - self.send_recorder_mail(recorders, summary) - - def send_recorder_mail(self, recorders, summary): - recipients = self.execution.recipients - if not recorders or not recipients: + if not recorders: return - recipients = User.objects.filter(id__in=list(recipients.keys())) + self.send_recorder_mail(recipients, recorders, summary) + def send_recorder_mail(self, recipients, recorders, summary): name = self.execution.snapshot['name'] path = os.path.join(os.path.dirname(settings.BASE_DIR), 'tmp') filename = os.path.join(path, f'{name}-{local_now_filename()}-{time.time()}.xlsx')