From f49e20535cc4069b4c95c369f628dfa02218d3a8 Mon Sep 17 00:00:00 2001 From: Jast <745925668@qq.com> Date: Thu, 20 Jun 2024 09:14:16 +0800 Subject: [PATCH] [improve] optimization notification code validation (#2102) Co-authored-by: zhangshenghang Co-authored-by: tomsun28 --- .../impl/FlyBookAlertNotifyHandlerImpl.java | 2 +- .../alert-notice/alert-notice.component.html | 18 +++------- .../alert-notice/alert-notice.component.ts | 34 ++----------------- web-app/src/assets/i18n/zh-CN.json | 1 - 4 files changed, 8 insertions(+), 47 deletions(-) diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImpl.java b/manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImpl.java index 2bf6f6c1b86..0ee227fdb33 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImpl.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/impl/FlyBookAlertNotifyHandlerImpl.java @@ -92,7 +92,7 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a List> contents = Collections.singletonList(contentList); zhCn.setContent(contents); - String webHookUrl = alerterProperties.getFlyBookWebhookUrl() + receiver.getWechatId(); + String webHookUrl = alerterProperties.getFlyBookWebhookUrl() + receiver.getAccessToken(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity flyEntity = new HttpEntity<>(flyBookWebHookDto, headers); diff --git a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html index 92ceaad08a8..472f8b05dd6 100644 --- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html +++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html @@ -586,19 +586,9 @@ {{ 'alert.notice.type.phone' | i18n }} - + - - -
- {{ receiverForm.controls['phone'].errors['invalidPhone'] }} -
-
- {{ 'validation.phone.invalid' | i18n }} -
-
-
{{ 'alert.notice.type.userId' | i18n }} @@ -634,16 +624,16 @@ - {{ + {{ 'alert.notice.type.fei-shu-key' | i18n }} diff --git a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts index 0ea35aed631..2014dafbfed 100644 --- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts +++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts @@ -300,10 +300,10 @@ export class AlertNoticeComponent implements OnInit { } break; case 6: - if (this.receiver?.wechatId) { - index = this.receiver.wechatId.indexOf('hook'); + if (this.receiver?.accessToken) { + index = this.receiver.accessToken.indexOf('hook'); if (index > 0) { - this.receiver.wechatId = this.receiver.wechatId.substring(index + 5); + this.receiver.accessToken = this.receiver.accessToken.substring(index + 5); } } break; @@ -352,35 +352,7 @@ export class AlertNoticeComponent implements OnInit { this.isManageReceiverModalVisible = false; } - private markAllControlsAsTouched(form: NgForm | undefined): void { - Object.keys(form!.controls).forEach(field => { - const control = form!.controls[field]; - control.markAsTouched(); - }); - } - - private markAllControlsAsUnTouched(form: NgForm | undefined): void { - Object.keys(form!.controls).forEach(field => { - const control = form!.controls[field]; - control.markAsUntouched(); - }); - } - onManageReceiverModalOk() { - if (this.receiver.type == 4) { - if (!this.receiver.phone && !this.receiver.userId) { - this.markAllControlsAsTouched(this.receiverForm); - this.receiverForm!.controls['phone'].setErrors({ invalidPhone: this.i18nSvc.fanyi('validation.phone.or.userid.invalid') }); - this.markAllControlsAsUnTouched(this.receiverForm); - return; - } else { - const errors = this.receiverForm!.controls['phone'].errors; - if (errors && errors.invalidPhone) { - delete errors.invalidPhone; - this.receiverForm!.controls['phone'].setErrors(errors); - } - } - } if (this.receiverForm?.invalid) { let isWaring = false; Object.values(this.receiverForm.controls).forEach(control => { diff --git a/web-app/src/assets/i18n/zh-CN.json b/web-app/src/assets/i18n/zh-CN.json index 008d9cd2f4a..f8f453fd5db 100644 --- a/web-app/src/assets/i18n/zh-CN.json +++ b/web-app/src/assets/i18n/zh-CN.json @@ -695,7 +695,6 @@ "validation.email.wrong-format": "邮箱地址格式错误!", "validation.email.invalid": "无效的邮箱地址!", "validation.phone.invalid": "无效的手机号!", - "validation.phone.or.userid.invalid": "用户ID或手机号至少填写一个!", "validation.verification-code.invalid": "无效的验证码,应是6位数字!", "validation.password.required": "请输入密码!", "validation.password.twice": "两次输入的密码不匹配!",