From f4de7542029f1344961a1a5a99aad10b0ef81dfb Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Mon, 3 Apr 2023 17:39:58 +0300 Subject: [PATCH] UI: Add tenant admin notification settings --- ui-ngx/src/app/core/services/menu.service.ts | 8 ++ .../home/pages/admin/admin-routing.module.ts | 2 +- .../pages/admin/sms-provider.component.html | 113 +++++++++--------- .../pages/admin/sms-provider.component.ts | 60 ++++++---- ui-ngx/src/app/shared/models/constants.ts | 1 + .../assets/locale/locale.constant-en_US.json | 3 +- 6 files changed, 102 insertions(+), 85 deletions(-) diff --git a/ui-ngx/src/app/core/services/menu.service.ts b/ui-ngx/src/app/core/services/menu.service.ts index 33544e4ac7..82ad8221fa 100644 --- a/ui-ngx/src/app/core/services/menu.service.ts +++ b/ui-ngx/src/app/core/services/menu.service.ts @@ -573,6 +573,14 @@ export class MenuService { path: '/settings/home', icon: 'settings_applications' }, + { + id: guid(), + name: 'admin.notifications', + type: 'link', + path: '/settings/notifications', + icon: 'mdi:message-badge', + isMdiIcon: true + }, { id: guid(), name: 'admin.repository', diff --git a/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts b/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts index 7b3fb8664e..adc87a7886 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts @@ -164,7 +164,7 @@ const routes: Routes = [ component: SmsProviderComponent, canDeactivate: [ConfirmOnExitGuard], data: { - auth: [Authority.SYS_ADMIN], + auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN], title: 'admin.notifications-settings', breadcrumb: { label: 'admin.notifications', diff --git a/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.html b/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.html index fc86fd06ad..0ea223e8b8 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.html +++ b/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.html @@ -15,66 +15,63 @@ limitations under the License. --> -
- + + + + admin.sms-provider-settings + + +
+
+ + +
+ +
+
+ + +
+ + +
+
+
+
+
+ - admin.notifications-settings + admin.slack-settings -
+
- - -
- -
-
- - -
- - -
-
-
-
-
- - - - - - - - - - -
- -
-
-
- admin.slack - - admin.slack-api-token - - -
-
- -
-
-
-
-
-
+ + +
+ +
+
+
+ + admin.slack-api-token + + +
+
+ +
+
+
+
+ diff --git a/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.ts b/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.ts index d8cbe0548d..e56f02c4e4 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/sms-provider.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Component, OnInit } from '@angular/core'; +import { Component } from '@angular/core'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { PageComponent } from '@shared/components/page.component'; @@ -28,20 +28,25 @@ import { SendTestSmsDialogComponent, SendTestSmsDialogData } from '@home/pages/a import { NotificationSettings } from '@shared/models/notification.models'; import { deepTrim, isEmptyStr } from '@core/utils'; import { NotificationService } from '@core/http/notification.service'; +import { Authority } from '@shared/models/authority.enum'; +import { AuthUser } from '@shared/models/user.model'; +import { getCurrentAuthUser } from '@core/auth/auth.selectors'; @Component({ selector: 'tb-sms-provider', templateUrl: './sms-provider.component.html', styleUrls: ['./sms-provider.component.scss', './settings-card.scss'] }) -export class SmsProviderComponent extends PageComponent implements OnInit, HasConfirmForm { +export class SmsProviderComponent extends PageComponent implements HasConfirmForm { smsProvider: FormGroup; - adminSettings: AdminSettings; + private adminSettings: AdminSettings; - notificationSettingsForm: FormGroup; + slackSettingsForm: FormGroup; private notificationSettings: NotificationSettings; + private readonly authUser: AuthUser; + constructor(protected store: Store, private router: Router, private adminService: AdminService, @@ -49,30 +54,30 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo private dialog: MatDialog, public fb: FormBuilder) { super(store); - } - - ngOnInit() { + this.authUser = getCurrentAuthUser(this.store); this.buildSmsProviderForm(); this.buildGeneralServerSettingsForm(); this.notificationService.getNotificationSettings().subscribe( (settings) => { this.notificationSettings = settings; - this.notificationSettingsForm.reset(this.notificationSettings); + this.slackSettingsForm.reset(this.notificationSettings); } ); - this.adminService.getAdminSettings('sms', {ignoreErrors: true}).subscribe({ - next: adminSettings => { - this.adminSettings = adminSettings; - this.smsProvider.reset({configuration: this.adminSettings.jsonValue}); - }, - error: () => { - this.adminSettings = { - key: 'sms', - jsonValue: null - }; - this.smsProvider.reset({configuration: this.adminSettings.jsonValue}); - } - }); + if (this.isSysAdmin()) { + this.adminService.getAdminSettings('sms', {ignoreErrors: true}).subscribe({ + next: adminSettings => { + this.adminSettings = adminSettings; + this.smsProvider.reset({configuration: this.adminSettings.jsonValue}); + }, + error: () => { + this.adminSettings = { + key: 'sms', + jsonValue: null + }; + this.smsProvider.reset({configuration: this.adminSettings.jsonValue}); + } + }); + } } private buildSmsProviderForm() { @@ -103,23 +108,24 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo } confirmForm(): FormGroup { - return this.smsProvider.dirty ? this.smsProvider : this.notificationSettingsForm; + return this.smsProvider.dirty ? this.smsProvider : this.slackSettingsForm; } private buildGeneralServerSettingsForm() { - this.notificationSettingsForm = this.fb.group({ + this.slackSettingsForm = this.fb.group({ deliveryMethodsConfigs: this.fb.group({ SLACK: this.fb.group({ botToken: [''] }) }) }); + this.registerDisableOnLoadFormControl(this.slackSettingsForm.get('deliveryMethodsConfigs')); } saveNotification(): void { this.notificationSettings = deepTrim({ ...this.notificationSettings, - ...this.notificationSettingsForm.value + ...this.slackSettingsForm.value }); // eslint-disable-next-line guard-for-in for (const method in this.notificationSettings.deliveryMethodsConfigs) { @@ -132,8 +138,12 @@ export class SmsProviderComponent extends PageComponent implements OnInit, HasCo } this.notificationService.saveNotificationSettings(this.notificationSettings).subscribe(setting => { this.notificationSettings = setting; - this.notificationSettingsForm.reset(this.notificationSettings); + this.slackSettingsForm.reset(this.notificationSettings); }); } + isSysAdmin(): boolean { + return this.authUser.authority === Authority.SYS_ADMIN; + } + } diff --git a/ui-ngx/src/app/shared/models/constants.ts b/ui-ngx/src/app/shared/models/constants.ts index bee7ebacc0..a93df2e3fd 100644 --- a/ui-ngx/src/app/shared/models/constants.ts +++ b/ui-ngx/src/app/shared/models/constants.ts @@ -76,6 +76,7 @@ export const HelpLinks = { linksMap: { outgoingMailSettings: helpBaseUrl + '/docs/user-guide/ui/mail-settings', smsProviderSettings: helpBaseUrl + '/docs/user-guide/ui/sms-provider-settings', + slackSettings: helpBaseUrl + '/docs/user-guide/ui/slack-settings', securitySettings: helpBaseUrl + '/docs/user-guide/ui/security-settings', oauth2Settings: helpBaseUrl + '/docs/user-guide/oauth-2-support/', twoFactorAuthSettings: helpBaseUrl + '/docs/', diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 00279b50e6..c5a000944e 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -417,7 +417,8 @@ "notifications": "Notifications", "notifications-settings": "Notifications settings", "slack-api-token": "Slack api token", - "slack": "Slack" + "slack": "Slack", + "slack-settings": "Slack settings" }, "alarm": { "alarm": "Alarm",