From 23aea1adaaa2b4cbe806b54a76ab950b940a2eb9 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Tue, 24 Nov 2026 17:13:29 +0200 Subject: [PATCH] feat: Home follows the user's permissions: cards shown only where the user may read what they show (alarms, dashboards and devices including shared groups, API usage, usage info, mobile app settings, IoT Hub with full access), Get started only when every step can be done; alarm acknowledge, assign and clear only with alarm write, Add rule as on the alarm rules page, links to entities only where their pages open; Add device and Add dashboard and the setup empty states by create permission for tenant and customer users alike, View all to shared groups when only those are readable; status line badges counted only where readable; side cards fill the main column when it has none; quick links' row lines complete when the last row is short --- .../components/alarms-home.component.html | 51 ++++--- .../components/alarms-home.component.scss | 6 +- .../components/alarms-home.component.ts | 25 ++-- .../components/dashboards-home.component.html | 8 +- .../components/dashboards-home.component.ts | 12 +- .../components/devices-home.component.html | 12 +- .../components/devices-home.component.ts | 22 ++- .../quick-links-home.component.scss | 6 +- .../components/status-line-home.component.ts | 40 ++++-- .../home-page/home-permissions.service.ts | 128 ++++++++++++++++++ .../pages/customer-user-home.component.ts | 17 ++- .../pages/tenant-admin-home.component.ts | 19 ++- .../assets/locale/locale.constant-en_US.json | 1 + 13 files changed, 269 insertions(+), 78 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/home-page/home-permissions.service.ts diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.html b/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.html index 4b5d8a80c1..851c5e1ea8 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.html @@ -9,7 +9,7 @@ @if (total()) { } - @if (tenantAdmin) { + @if (canAddRule) { + @if (canWrite) { + + } } @@ -123,12 +133,15 @@ @if (row.alarm.acknowledged) { check_circle - } @else { + } @else if (canWrite) { + } @else { + radio_button_unchecked } @@ -151,11 +164,13 @@ - - @if (!row.mine) { + @if (canWrite) { + + } + @if (canWrite && !row.mine) { - + @if (canWrite) { + + } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.scss index da550c4cfd..c48a7487d2 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.scss @@ -190,7 +190,7 @@ } } -.tb-alarms-acked { +.tb-alarms-acked, .tb-alarms-unacked { width: 20px; height: 20px; font-size: 20px; @@ -198,6 +198,10 @@ color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); } +.tb-alarms-unacked { + color: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); +} + @container tb-alarms-home (max-width: 599px) { .tb-alarms-table { .col-origin { diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.ts index 75881395e5..70c3cd0a8d 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.ts @@ -34,7 +34,7 @@ import { AlarmSearchStatus, AlarmSeverity, alarmSeverityTranslations } from '@sh import { Authority } from '@shared/models/authority.enum'; import { EntityType } from '@shared/models/entity-type.models'; import { HomeCardId } from '@shared/models/user-settings.models'; -import { getEntityDetailsPageURL } from '@core/utils'; +import { HomePermissionsService } from '@home/pages/home-page/home-permissions.service'; import { HOME_CARDS } from '@home/pages/home-page/home-cards.models'; import { AlarmDetailsDialogComponent, AlarmDetailsDialogData } from '@home/components/alarm/alarm-details-dialog.component'; import { homeAgo, homeListPageSize, homeListShown } from '@home/pages/home-page/home-list.models'; @@ -108,10 +108,15 @@ export class AlarmsHomeComponent { private toast = inject(ToastNotificationService); private translate = inject(TranslateService); private alarmRulesService = inject(AlarmRulesService); + private permissions = inject(HomePermissionsService); private readonly authUser = getCurrentAuthUser(this.store); private readonly userId = this.authUser?.userId; readonly tenantAdmin = this.authUser?.authority === Authority.TENANT_ADMIN; + readonly canWrite = this.permissions.canWriteAlarms(); + readonly canAddRule = this.permissions.canAddAlarmRules(); + private readonly canReadRules = this.permissions.canReadAlarmRules(); + private readonly canReadDevices = this.permissions.canReadEntities(EntityType.DEVICE); readonly mine = signal(readMine()); readonly severity = signal(null); @@ -128,7 +133,7 @@ export class AlarmsHomeComponent { if (this.total() !== 0 || this.hasRules() === null || this.devices() === null) { return null; } - if (this.tenantAdmin && !this.hasRules()) { + if (this.canReadRules && !this.hasRules()) { return 'rules'; } return this.devices() ? 'clear' : 'devices'; @@ -200,8 +205,12 @@ export class AlarmsHomeComponent { constructor() { this.totalSubscriber = this.subscribeCount(this.total); - this.devicesSubscriber = this.subscribeDevices(); - if (this.tenantAdmin) { + if (this.canReadDevices) { + this.devicesSubscriber = this.subscribeDevices(); + } else { + this.devices.set(1); + } + if (this.canReadRules) { this.alarmRulesService.getAlarmRules(new PageLink(1), undefined, {ignoreLoading: true}).pipe( catchError(() => of(null)) ).subscribe(page => this.hasRules.set(!page || page.totalElements > 0)); @@ -272,10 +281,10 @@ export class AlarmsHomeComponent { data: { alarmId: row.alarm.id.id, alarm: row.alarm, - allowAcknowledgment: true, - allowClear: true, + allowAcknowledgment: this.canWrite, + allowClear: this.canWrite, displayDetails: true, - allowAssign: true + allowAssign: this.canWrite } }).afterClosed().subscribe(changed => { if (changed) { @@ -424,7 +433,7 @@ export class AlarmsHomeComponent { return { alarm, ago: homeAgo(this.translate, now - (alarm.createdTime ?? now)), - originatorLink: originator ? getEntityDetailsPageURL(originator.id, originator.entityType as EntityType) : null, + originatorLink: originator ? this.permissions.entityDetailsLink(originator.entityType as EntityType, originator.id) : null, assigneeName, initials, mine: !!alarm.assigneeId && alarm.assigneeId.id === this.userId diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.html b/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.html index dbec972563..514e849c78 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.html @@ -19,12 +19,14 @@ @if (loaded()) { @if (!total()) {
- - @if (tenantAdmin) { + + @if (canAdd) { diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.ts index 06c9cdfa58..725d1ee73b 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.ts @@ -11,11 +11,10 @@ import { AppState } from '@core/core.state'; import { getCurrentAuthState, getCurrentAuthUser } from '@core/auth/auth.selectors'; import { UserSettingsService } from '@core/http/user-settings.service'; import { DashboardService } from '@core/http/dashboard.service'; -import { UserPermissionsService } from '@core/http/user-permissions.service'; +import { HomePermissionsService } from '@home/pages/home-page/home-permissions.service'; import { ToastNotificationService } from '@core/services/toast-notification.service'; import { Authority } from '@shared/models/authority.enum'; import { EntityType } from '@shared/models/entity-type.models'; -import { Operation, Resource } from '@shared/models/security.models'; import { HelpLinks } from '@shared/models/constants'; import { PageLink } from '@shared/models/page/page-link'; import { Direction } from '@shared/models/page/sort-order'; @@ -68,16 +67,15 @@ export class DashboardsHomeComponent { private translate = inject(TranslateService); private userSettingsService = inject(UserSettingsService); private dashboardService = inject(DashboardService); - private userPermissions = inject(UserPermissionsService); private toast = inject(ToastNotificationService); private readonly authUser = getCurrentAuthUser(this.store); private readonly fullscreen = getCurrentAuthState(this.store).forceFullscreen; - readonly tenantAdmin = this.authUser?.authority === Authority.TENANT_ADMIN; - readonly canAdd = this.tenantAdmin && this.userPermissions.hasGenericPermission(Resource.DASHBOARD, Operation.CREATE); - readonly dashboardsLink = this.userPermissions.hasReadGenericPermission(Resource.DASHBOARD) ? '/dashboards/all' - : this.userPermissions.hasSharedReadGroupsPermission(EntityType.DASHBOARD) ? '/dashboards/shared' : null; + readonly canAdd = inject(HomePermissionsService).canReadAllEntities(EntityType.DASHBOARD) && + inject(HomePermissionsService).canCreateEntities(EntityType.DASHBOARD); + readonly dashboardsLink = inject(HomePermissionsService).entitiesLink(EntityType.DASHBOARD); + readonly canUseIotHub = inject(HomePermissionsService).canUseIotHub(); readonly tab = signal('last'); readonly expanded = signal(false); diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.html b/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.html index ae70d1e231..680019a649 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.html @@ -16,7 +16,7 @@ @if (total() === 0) {
- @if (tenantAdmin) { + @if (canAdd) {

{{ 'home.devices.none' | translate }}

@@ -69,7 +69,13 @@ @for (row of rows(); track row.id) { - {{ row.name }} + + @if (row.url) { + {{ row.name }} + } @else { + {{ row.name }} + } + {{ row.profile }} {{ row.profile }} @@ -90,7 +96,7 @@ } @else if (loaded()) {
{{ ('home.devices.none-' + (filter() ?? 'active')) | translate }}
} - } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.ts index 37cc069f9d..036fb27ea5 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.ts @@ -17,9 +17,9 @@ import { Store } from '@ngrx/store'; import { TranslateService } from '@ngx-translate/core'; import { take } from 'rxjs/operators'; import { AppState } from '@core/core.state'; -import { getCurrentAuthUser, selectPersistDeviceStateToTelemetry } from '@core/auth/auth.selectors'; +import { selectPersistDeviceStateToTelemetry } from '@core/auth/auth.selectors'; import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service'; -import { UserPermissionsService } from '@core/http/user-permissions.service'; +import { HomePermissionsService } from '@home/pages/home-page/home-permissions.service'; import { EntityCountCmd, EntityDataCmd, TelemetrySubscriber } from '@shared/models/telemetry/telemetry.models'; import { AliasFilterType } from '@shared/models/alias.models'; import { EntityType } from '@shared/models/entity-type.models'; @@ -35,11 +35,8 @@ import { NumericOperation } from '@shared/models/query/query.models'; import { Direction } from '@shared/models/page/sort-order'; -import { Authority } from '@shared/models/authority.enum'; -import { Operation, Resource } from '@shared/models/security.models'; import { HelpLinks } from '@shared/models/constants'; import { HomeCardId } from '@shared/models/user-settings.models'; -import { getEntityDetailsPageURL } from '@core/utils'; import { HOME_CARDS } from '@home/pages/home-page/home-cards.models'; import { homeAgo, homeListPageSize, homeListShown } from '@home/pages/home-page/home-list.models'; @@ -91,11 +88,10 @@ export class DevicesHomeComponent { private store = inject(Store); private router = inject(Router); private translate = inject(TranslateService); - private userPermissions = inject(UserPermissionsService); + private permissions = inject(HomePermissionsService); - private readonly authUser = getCurrentAuthUser(this.store); - readonly tenantAdmin = this.authUser?.authority === Authority.TENANT_ADMIN; - readonly canAdd = this.tenantAdmin && this.userPermissions.hasGenericPermission(Resource.DEVICE, Operation.CREATE); + readonly canAdd = this.permissions.canReadAllEntities(EntityType.DEVICE) && this.permissions.canCreateEntities(EntityType.DEVICE); + readonly devicesLink = this.permissions.entitiesLink(EntityType.DEVICE); readonly filter = signal(null); readonly expanded = signal(false); @@ -145,7 +141,7 @@ export class DevicesHomeComponent { readonly viewAllParams = computed(() => { const filter = this.filter(); - return filter ? {active: filter === 'active'} : null; + return filter && this.devicesLink?.endsWith('/all') ? {active: filter === 'active'} : null; }); private readonly queries = computed(() => { @@ -226,7 +222,9 @@ export class DevicesHomeComponent { } open(row: DeviceHomeRow): void { - this.router.navigateByUrl(row.url); + if (row.url) { + this.router.navigateByUrl(row.url); + } } private subscribeLists(queries: DeviceQuery[], pageSize: number): void { @@ -350,7 +348,7 @@ export class DevicesHomeComponent { active: state.active?.value === 'true', lastActivity, ago: lastActivity ? homeAgo(this.translate, now - lastActivity) : '', - url: getEntityDetailsPageURL(data.entityId.id, EntityType.DEVICE) + url: this.permissions.entityDetailsLink(EntityType.DEVICE, data.entityId.id) }; } } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/quick-links-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-page/components/quick-links-home.component.scss index b35b76d090..62e65b4237 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/quick-links-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/quick-links-home.component.scss @@ -15,7 +15,7 @@ display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; - clip-path: inset(1px -8px 0 -8px); + clip-path: inset(0 -8px 1px -8px); > .tb-quick-link { position: relative; @@ -24,10 +24,10 @@ &::before { content: ""; position: absolute; - top: 0; right: 8px; + bottom: 0; left: 8px; - border-top: 1px solid var(--tb-line-soft, rgba(0, 0, 0, 0.05)); + border-bottom: 1px solid var(--tb-line-soft, rgba(0, 0, 0, 0.05)); pointer-events: none; } } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts index f98d0a7266..e7fd12d732 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts @@ -12,6 +12,7 @@ import { EntityType } from '@shared/models/entity-type.models'; import { EntityKeyType, EntityKeyValueType, FilterPredicateType, BooleanOperation, KeyFilter } from '@shared/models/query/query.models'; import { AlarmSearchStatus, AlarmSeverity } from '@shared/models/alarm.models'; import { Authority } from '@shared/models/authority.enum'; +import { HomePermissionsService } from '@home/pages/home-page/home-permissions.service'; import { HomeCardId } from '@shared/models/user-settings.models'; import { AdminService } from '@core/http/admin.service'; import { SysAdminHomeService } from '@home/pages/home-page/sys-admin-home.service'; @@ -96,6 +97,10 @@ export class StatusLineHomeComponent { private readonly authority = getCurrentAuthUser(this.store)?.authority; private readonly customer = this.authority === Authority.CUSTOMER_USER; readonly sysAdmin = this.authority === Authority.SYS_ADMIN; + private readonly homePermissions = inject(HomePermissionsService); + private readonly canReadAlarms = !this.sysAdmin && this.homePermissions.canReadAlarms(); + private readonly canReadDevices = !this.sysAdmin && this.homePermissions.canReadEntities(EntityType.DEVICE); + private readonly devicesLink = this.canReadDevices ? this.homePermissions.entitiesLink(EntityType.DEVICE) : null; private readonly shownKey = `tb-home-status-line:${getCurrentAuthUser(this.store)?.userId}`; @@ -122,26 +127,28 @@ export class StatusLineHomeComponent { readonly kind = computed(() => this.sysAdmin ? this.sysAdminKind() : this.critical() ? 'crit' : this.inactive() ? 'warn' : 'ok'); private tenantParts(): StatusPart[] { - const critical = this.critical(); - const active = this.active(); - const devices = this.devices(); - const inactive = this.inactive(); + const critical = this.canReadAlarms ? this.critical() : 0; + const active = this.canReadAlarms ? this.active() : 0; + const devices = this.canReadDevices ? this.devices() : 0; + const inactive = this.canReadDevices ? this.inactive() : 0; if (critical === null || active === null || devices === null || inactive === null) { return []; } if (!devices) { - return this.customer ? [{key: 'home.status.nothing-assigned'}] : []; + return this.customer && this.canReadDevices ? [{key: 'home.status.nothing-assigned'}] : []; } const parts: StatusPart[] = []; - if (critical) { - parts.push({key: 'home.status.critical-alarms', params: {count: critical}, cards: [HomeCardId.ALARMS], link: '/alarms'}); - } else if (active) { - parts.push({key: 'home.status.active-alarms', params: {count: active}, cards: [HomeCardId.ALARMS], link: '/alarms'}); - } else { - parts.push({key: 'home.status.no-alarms'}); + if (this.canReadAlarms) { + if (critical) { + parts.push({key: 'home.status.critical-alarms', params: {count: critical}, cards: [HomeCardId.ALARMS], link: '/alarms'}); + } else if (active) { + parts.push({key: 'home.status.active-alarms', params: {count: active}, cards: [HomeCardId.ALARMS], link: '/alarms'}); + } else { + parts.push({key: 'home.status.no-alarms'}); + } } if (inactive) { - parts.push({key: 'home.status.inactive-devices', params: {count: inactive}, cards: [HomeCardId.DEVICES], link: '/entities/devices'}); + parts.push({key: 'home.status.inactive-devices', params: {count: inactive}, cards: [HomeCardId.DEVICES], link: this.devicesLink}); } else { parts.push({key: devices === 1 ? 'home.status.device-active' : 'home.status.all-devices-active', params: {count: devices}}); } @@ -226,8 +233,13 @@ export class StatusLineHomeComponent { private watchTenant(): void { this.store.select(selectPersistDeviceStateToTelemetry).pipe(take(1)).subscribe(persisted => { const activeKeyType = persisted ? EntityKeyType.TIME_SERIES : EntityKeyType.SERVER_ATTRIBUTE; - this.countAlarms(this.critical, [AlarmSeverity.CRITICAL]); - this.countAlarms(this.active); + if (this.canReadAlarms) { + this.countAlarms(this.critical, [AlarmSeverity.CRITICAL]); + this.countAlarms(this.active); + } + if (!this.canReadDevices) { + return; + } this.countDevices(this.devices); this.countDevices(this.inactive, [{ key: {type: activeKeyType, key: 'active'}, diff --git a/ui-ngx/src/app/modules/home/pages/home-page/home-permissions.service.ts b/ui-ngx/src/app/modules/home/pages/home-page/home-permissions.service.ts new file mode 100644 index 0000000000..414e3e6628 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-page/home-permissions.service.ts @@ -0,0 +1,128 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { inject, Injectable } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { getCurrentAuthUser } from '@core/auth/auth.selectors'; +import { UserPermissionsService } from '@core/http/user-permissions.service'; +import { Authority } from '@shared/models/authority.enum'; +import { EntityType } from '@shared/models/entity-type.models'; +import { Operation, Resource, resourceByEntityType } from '@shared/models/security.models'; +import { alarmRuleEntityTypeList } from '@shared/models/alarm-rule.models'; +import { getEntityDetailsPageURL } from '@core/utils'; +import { HomeCardId } from '@shared/models/user-settings.models'; + +const ENTITY_LIST_PATHS: Partial> = { + [EntityType.DEVICE]: '/entities/devices', + [EntityType.ASSET]: '/entities/assets', + [EntityType.CUSTOMER]: '/customers', + [EntityType.DASHBOARD]: '/dashboards' +}; + +@Injectable({ + providedIn: 'root' +}) +export class HomePermissionsService { + + private userPermissions = inject(UserPermissionsService); + private store = inject(Store); + + get tenantAdmin(): boolean { + return getCurrentAuthUser(this.store)?.authority === Authority.TENANT_ADMIN; + } + + canReadEntities(entityType: EntityType): boolean { + return this.userPermissions.hasReadGenericPermission(resourceByEntityType.get(entityType)) || + this.userPermissions.hasSharedReadGroupsPermission(entityType); + } + + canReadAllEntities(entityType: EntityType): boolean { + return this.userPermissions.hasReadGenericPermission(resourceByEntityType.get(entityType)); + } + + canCreateEntities(entityType: EntityType): boolean { + return this.userPermissions.hasGenericPermission(resourceByEntityType.get(entityType), Operation.CREATE); + } + + entitiesLink(entityType: EntityType): string | null { + const base = ENTITY_LIST_PATHS[entityType]; + if (!base) { + return null; + } + if (this.canReadAllEntities(entityType)) { + return `${base}/all`; + } + return this.userPermissions.hasSharedReadGroupsPermission(entityType) ? `${base}/shared` : null; + } + + entityDetailsLink(entityType: EntityType, id: string): string | null { + if (!this.canReadAllEntities(entityType)) { + return null; + } + return getEntityDetailsPageURL(id, entityType) || null; + } + + canReadAlarms(): boolean { + return this.userPermissions.hasReadGenericPermission(Resource.ALARM); + } + + canWriteAlarms(): boolean { + return this.userPermissions.hasGenericPermission(Resource.ALARM, Operation.WRITE); + } + + canReadAlarmRules(): boolean { + return this.tenantAdmin && alarmRuleEntityTypeList.some(entityType => + this.userPermissions.hasGenericPermissionByEntityGroupType(Operation.READ_CALCULATED_FIELD, entityType)); + } + + canAddAlarmRules(): boolean { + return this.tenantAdmin && alarmRuleEntityTypeList.some(entityType => + this.userPermissions.hasGenericPermissionByEntityGroupType(Operation.WRITE_CALCULATED_FIELD, entityType)); + } + + canUseIotHub(): boolean { + return this.tenantAdmin && this.userPermissions.hasGenericPermission(Resource.ALL, Operation.ALL); + } + + canReadApiUsage(): boolean { + return this.tenantAdmin && this.userPermissions.hasReadGenericPermission(Resource.API_USAGE_STATE) && + this.userPermissions.hasGenericPermission(Resource.API_USAGE_STATE, Operation.READ_TELEMETRY); + } + + canReadUsageInfo(): boolean { + return this.tenantAdmin && this.userPermissions.hasGenericPermission(Resource.ALL, Operation.READ); + } + + canReadMobileAppSettings(): boolean { + return this.userPermissions.hasReadGenericPermission(Resource.MOBILE_APP_SETTINGS); + } + + canGetStarted(): boolean { + return this.tenantAdmin && this.canAddAlarmRules() && + [EntityType.DEVICE, EntityType.DASHBOARD, EntityType.CUSTOMER].every(entityType => + this.canReadAllEntities(entityType) && this.canCreateEntities(entityType)); + } + + cardAvailable(id: HomeCardId): boolean { + switch (id) { + case HomeCardId.GET_STARTED: + return this.canGetStarted(); + case HomeCardId.IOT_HUB: + return this.canUseIotHub(); + case HomeCardId.ALARMS: + return this.canReadAlarms(); + case HomeCardId.DASHBOARDS: + return this.canReadEntities(EntityType.DASHBOARD); + case HomeCardId.DEVICES: + return this.canReadEntities(EntityType.DEVICE); + case HomeCardId.ACTIVITY: + return this.canReadApiUsage(); + case HomeCardId.USAGE: + return this.canReadUsageInfo(); + case HomeCardId.MOBILE_APP: + return this.canReadMobileAppSettings(); + default: + return true; + } + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-page/pages/customer-user-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/pages/customer-user-home.component.ts index 077ab98883..e3e4b5b87c 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/pages/customer-user-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/pages/customer-user-home.component.ts @@ -7,6 +7,7 @@ import { AppState } from '@core/core.state'; import { selectHomeCards } from '@core/auth/auth.selectors'; import { HomeCardId } from '@shared/models/user-settings.models'; import { isHomeCardShown } from '@home/pages/home-page/home-cards.models'; +import { HomePermissionsService } from '@home/pages/home-page/home-permissions.service'; const MAIN_CARDS = [HomeCardId.ALARMS, HomeCardId.DASHBOARDS, HomeCardId.DEVICES]; const SIDE_CARDS = [HomeCardId.NOTIFICATIONS, HomeCardId.QUICK_LINKS]; @@ -61,11 +62,21 @@ export class CustomerUserHomeComponent { readonly HomeCardId = HomeCardId; - readonly cards = [...MAIN_CARDS, ...SIDE_CARDS]; + private readonly permissions = inject(HomePermissionsService); + + private readonly mainCardIds = MAIN_CARDS.filter(id => this.permissions.cardAvailable(id)); + + private readonly sideCardIds = SIDE_CARDS.filter(id => this.permissions.cardAvailable(id)); + + readonly cards = [...this.mainCardIds, ...this.sideCardIds]; private settings = toSignal(inject(Store).select(selectHomeCards), {initialValue: {}}); - readonly mainCards = computed(() => MAIN_CARDS.filter(id => isHomeCardShown(this.settings(), id))); + private readonly shownMainCards = computed(() => this.mainCardIds.filter(id => isHomeCardShown(this.settings(), id))); + + private readonly shownSideCards = computed(() => this.sideCardIds.filter(id => isHomeCardShown(this.settings(), id))); + + readonly mainCards = computed(() => this.shownMainCards().length ? this.shownMainCards() : this.shownSideCards()); - readonly sideCards = computed(() => SIDE_CARDS.filter(id => isHomeCardShown(this.settings(), id))); + readonly sideCards = computed(() => this.shownMainCards().length ? this.shownSideCards() : []); } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts index 395d33a9d7..8d75816242 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts @@ -6,10 +6,9 @@ import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { selectHomeCards, selectMobileQrEnabled } from '@core/auth/auth.selectors'; import { TourService } from '@core/services/tour.service'; -import { UserPermissionsService } from '@core/http/user-permissions.service'; -import { Operation, Resource } from '@shared/models/security.models'; import { HomeCardId } from '@shared/models/user-settings.models'; import { isHomeCardShown } from '@home/pages/home-page/home-cards.models'; +import { HomePermissionsService } from '@home/pages/home-page/home-permissions.service'; const MAIN_CARDS = [HomeCardId.IOT_HUB, HomeCardId.ALARMS, HomeCardId.DASHBOARDS, HomeCardId.DEVICES, HomeCardId.ACTIVITY]; const SIDE_CARDS = [HomeCardId.GET_STARTED, HomeCardId.NOTIFICATIONS, HomeCardId.QUICK_LINKS, HomeCardId.USAGE, HomeCardId.MOBILE_APP]; @@ -27,20 +26,26 @@ export class TenantAdminHomeComponent { private readonly store = inject(Store); - private readonly usageAccess = inject(UserPermissionsService).hasGenericPermission(Resource.ALL, Operation.READ); + private readonly permissions = inject(HomePermissionsService); private readonly mobileQrEnabled = toSignal(this.store.select(selectMobileQrEnabled), {initialValue: false}); + private readonly mainCardIds = MAIN_CARDS.filter(id => this.permissions.cardAvailable(id)); + private readonly sideCardIds = computed(() => SIDE_CARDS.filter(id => - (id !== HomeCardId.USAGE || this.usageAccess) && (id !== HomeCardId.MOBILE_APP || this.mobileQrEnabled()))); + this.permissions.cardAvailable(id) && (id !== HomeCardId.MOBILE_APP || this.mobileQrEnabled()))); - readonly cards = computed(() => [...MAIN_CARDS, ...this.sideCardIds()]); + readonly cards = computed(() => [...this.mainCardIds, ...this.sideCardIds()]); readonly aiAvailable = inject(TourService).aiAvailable(); private settings = toSignal(this.store.select(selectHomeCards), {initialValue: {}}); - readonly mainCards = computed(() => MAIN_CARDS.filter(id => isHomeCardShown(this.settings(), id))); + private readonly shownMainCards = computed(() => this.mainCardIds.filter(id => isHomeCardShown(this.settings(), id))); + + private readonly shownSideCards = computed(() => this.sideCardIds().filter(id => isHomeCardShown(this.settings(), id))); + + readonly mainCards = computed(() => this.shownMainCards().length ? this.shownMainCards() : this.shownSideCards()); - readonly sideCards = computed(() => this.sideCardIds().filter(id => isHomeCardShown(this.settings(), id))); + readonly sideCards = computed(() => this.shownMainCards().length ? this.shownSideCards() : []); } 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 f7d5ecd3c7..c92e368aca 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -8608,6 +8608,7 @@ "assign-me": "Assign to me", "acknowledge": "Acknowledge", "acknowledged-tip": "Acknowledged", + "not-acknowledged": "Not acknowledged", "open-details": "Open details", "clear": "Clear", "clear-title": "Clear {{name}}?",