Skip to content

Commit

Permalink
[improve] optimization notification code validation (#2102)
Browse files Browse the repository at this point in the history
Co-authored-by: zhangshenghang <admin@hadoop.wiki>
Co-authored-by: tomsun28 <tomsun28@outlook.com>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent a32757e commit f49e205
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a
List<List<FlyBookContent>> 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<FlyBookWebHookDto> flyEntity = new HttpEntity<>(flyBookWebHookDto, headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,9 @@
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 4">
<nz-form-label [nzSpan]="7" nzFor="phone">{{ 'alert.notice.type.phone' | i18n }}</nz-form-label>
<nz-form-control [nzErrorTip]="phoneErrorTpl" [nzSpan]="12">
<nz-form-control [nzErrorTip]="'validation.phone.invalid' | i18n" [nzSpan]="12">
<input [(ngModel)]="receiver.phone" pattern="^(1\d{10})(,\s*1\d{10})*$" id="WePhone" name="phone" nz-input type="tel" />
</nz-form-control>
<ng-template #phoneErrorTpl>
<ng-container *ngIf="receiverForm.controls['phone'].errors">
<div *ngIf="receiverForm.controls['phone'].hasError('invalidPhone')">
{{ receiverForm.controls['phone'].errors['invalidPhone'] }}
</div>
<div *ngIf="receiverForm.controls['phone'].hasError('pattern')">
{{ 'validation.phone.invalid' | i18n }}
</div>
</ng-container>
</ng-template>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 4">
<nz-form-label [nzSpan]="7" nzFor="userId">{{ 'alert.notice.type.userId' | i18n }}</nz-form-label>
Expand Down Expand Up @@ -634,16 +624,16 @@
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 6">
<nz-form-label [nzSpan]="7" nzFor="wechatId" [nzRequired]="receiver.type === 6">{{
<nz-form-label [nzSpan]="7" nzFor="accessToken" [nzRequired]="receiver.type === 6">{{
'alert.notice.type.fei-shu-key' | i18n
}}</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<input
[(ngModel)]="receiver.wechatId"
[(ngModel)]="receiver.accessToken"
(ngModelChange)="onSplitTokenStr(6)"
nz-input
[required]="receiver.type === 6"
name="wechatId"
name="accessToken"
type="text"
/>
</nz-form-control>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down
1 change: 0 additions & 1 deletion web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "两次输入的密码不匹配!",
Expand Down

0 comments on commit f49e205

Please sign in to comment.