Browse Source

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

pull/16848/head
Igor Kulikov 1 week ago
parent
commit
23aea1adaa
  1. 51
      ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.html
  2. 6
      ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.scss
  3. 25
      ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.ts
  4. 8
      ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.html
  5. 12
      ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.ts
  6. 12
      ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.html
  7. 22
      ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.ts
  8. 6
      ui-ngx/src/app/modules/home/pages/home-page/components/quick-links-home.component.scss
  9. 40
      ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts
  10. 128
      ui-ngx/src/app/modules/home/pages/home-page/home-permissions.service.ts
  11. 17
      ui-ngx/src/app/modules/home/pages/home-page/pages/customer-user-home.component.ts
  12. 19
      ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts
  13. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

51
ui-ngx/src/app/modules/home/pages/home-page/components/alarms-home.component.html

@ -9,7 +9,7 @@
@if (total()) {
<tb-home-toggle [options]="whoseOptions" [value]="mine()" [label]="'home.alarms.whose' | translate" (valueChange)="setMine($event)"></tb-home-toggle>
}
@if (tenantAdmin) {
@if (canAddRule) {
<button mat-button color="primary" type="button" class="tb-home-add" (click)="addAlarmRule()">
<mat-icon>add</mat-icon>
<span class="tb-home-add-label">{{ 'home.alarms.add-rule' | translate }}</span>
@ -94,12 +94,20 @@
<a class="tb-alarms-link" href="#" (click)="openDetails(row, $event)">{{ row.alarm.type }}</a>
</span>
<span class="tb-alarms-cell-sub">
<a class="tb-alarms-link tb-alarms-origin" [routerLink]="row.originatorLink" (click)="stop($event)">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</a>
@if (row.originatorLink) {
<a class="tb-alarms-link tb-alarms-origin" [routerLink]="row.originatorLink" (click)="stop($event)">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</a>
} @else {
<span class="tb-alarms-origin">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</span>
}
<span class="tb-alarms-sub-age"> · {{ row.ago }}</span>
</span>
</td>
<td class="col-origin">
<a class="tb-alarms-link tb-alarms-origin" [routerLink]="row.originatorLink" (click)="stop($event)">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</a>
@if (row.originatorLink) {
<a class="tb-alarms-link tb-alarms-origin" [routerLink]="row.originatorLink" (click)="stop($event)">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</a>
} @else {
<span class="tb-alarms-origin">{{ row.alarm.originatorDisplayName || row.alarm.originatorName }}</span>
}
</td>
<td class="col-age col-time" [matTooltip]="'home.alarms.started-at' | translate: {time: (row.alarm.createdTime | date: 'd MMM, HH:mm')}">{{ row.ago }}</td>
@if (!mine()) {
@ -111,10 +119,12 @@
} @else {
<span class="tb-alarms-assign-cell">
<span class="tb-alarms-dash" [matTooltip]="'home.alarms.not-assigned' | translate">—</span>
<button mat-icon-button type="button" class="tb-alarms-assign" [matTooltip]="'home.alarms.assign-me' | translate"
[attr.aria-label]="'home.alarms.assign-me' | translate" (click)="assignToMe(row, $event)">
<mat-icon>person_add</mat-icon>
</button>
@if (canWrite) {
<button mat-icon-button type="button" class="tb-alarms-assign" [matTooltip]="'home.alarms.assign-me' | translate"
[attr.aria-label]="'home.alarms.assign-me' | translate" (click)="assignToMe(row, $event)">
<mat-icon>person_add</mat-icon>
</button>
}
</span>
}
</td>
@ -123,12 +133,15 @@
@if (row.alarm.acknowledged) {
<mat-icon class="tb-alarms-acked" role="img" [matTooltip]="'home.alarms.acknowledged-tip' | translate"
[attr.aria-label]="'home.alarms.acknowledged-tip' | translate">check_circle</mat-icon>
} @else {
} @else if (canWrite) {
<button mat-icon-button type="button" class="tb-alarms-ack" [matTooltip]="'home.alarms.acknowledge' | translate"
[attr.aria-label]="'home.alarms.acknowledge' | translate" (click)="acknowledge(row, $event)">
<mat-icon class="off">radio_button_unchecked</mat-icon>
<mat-icon class="on">check_circle_outline</mat-icon>
</button>
} @else {
<mat-icon class="tb-alarms-unacked" role="img" [matTooltip]="'home.alarms.not-acknowledged' | translate"
[attr.aria-label]="'home.alarms.not-acknowledged' | translate">radio_button_unchecked</mat-icon>
}
</td>
<td class="col-actions">
@ -151,11 +164,13 @@
<mat-menu #alarmMenu="matMenu" xPosition="before" class="tb-ai-chat-menu tb-alarms-home-menu">
<ng-template matMenuContent let-row="row">
<button mat-menu-item [disabled]="row.alarm.acknowledged" (click)="acknowledge(row)">
<mat-icon fontSet="material-icons-round">{{ row.alarm.acknowledged ? 'done_all' : 'done' }}</mat-icon>
<span>{{ (row.alarm.acknowledged ? 'home.alarms.acknowledged-tip' : 'home.alarms.acknowledge') | translate }}</span>
</button>
@if (!row.mine) {
@if (canWrite) {
<button mat-menu-item [disabled]="row.alarm.acknowledged" (click)="acknowledge(row)">
<mat-icon fontSet="material-icons-round">{{ row.alarm.acknowledged ? 'done_all' : 'done' }}</mat-icon>
<span>{{ (row.alarm.acknowledged ? 'home.alarms.acknowledged-tip' : 'home.alarms.acknowledge') | translate }}</span>
</button>
}
@if (canWrite && !row.mine) {
<button mat-menu-item (click)="assignToMe(row)">
<mat-icon fontSet="material-icons-round">person_add</mat-icon>
<span>{{ 'home.alarms.assign-me' | translate }}</span>
@ -165,9 +180,11 @@
<mat-icon fontSet="material-icons-round">open_in_new</mat-icon>
<span>{{ 'home.alarms.open-details' | translate }}</span>
</button>
<button mat-menu-item class="danger" (click)="clear(row)">
<mat-icon fontSet="material-icons-round">clear</mat-icon>
<span>{{ 'home.alarms.clear' | translate }}</span>
</button>
@if (canWrite) {
<button mat-menu-item class="danger" (click)="clear(row)">
<mat-icon fontSet="material-icons-round">clear</mat-icon>
<span>{{ 'home.alarms.clear' | translate }}</span>
</button>
}
</ng-template>
</mat-menu>

6
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 {

25
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<AlarmSeverity | null>(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

8
ui-ngx/src/app/modules/home/pages/home-page/components/dashboards-home.component.html

@ -19,12 +19,14 @@
@if (loaded()) {
@if (!total()) {
<div class="tb-home-setup-empty">
<span class="tb-home-setup-empty-glyph" aria-hidden="true"><mat-icon>{{ tenantAdmin ? 'dashboard_customize' : 'dashboard' }}</mat-icon></span>
@if (tenantAdmin) {
<span class="tb-home-setup-empty-glyph" aria-hidden="true"><mat-icon>{{ canAdd ? 'dashboard_customize' : 'dashboard' }}</mat-icon></span>
@if (canAdd) {
<div class="tb-home-setup-empty-text">
<p>{{ 'home.dashboards.none' | translate }}</p>
<div class="tb-home-setup-empty-actions">
<a routerLink="/iot-hub/solution-templates">{{ 'home.dashboards.from-template' | translate }}</a>
@if (canUseIotHub) {
<a routerLink="/iot-hub/solution-templates">{{ 'home.dashboards.from-template' | translate }}</a>
}
<a [href]="howToLink" target="_blank" rel="noopener">{{ 'home.dashboards.how-to' | translate }}<mat-icon class="tb-home-ext" aria-hidden="true">north_east</mat-icon><span class="tb-home-sr-only">{{ 'home.dashboards.opens-new-tab' | translate }}</span></a>
</div>
</div>

12
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<DashboardsTab>('last');
readonly expanded = signal(false);

12
ui-ngx/src/app/modules/home/pages/home-page/components/devices-home.component.html

@ -16,7 +16,7 @@
@if (total() === 0) {
<div class="tb-home-setup-empty">
<span class="tb-home-setup-empty-glyph" aria-hidden="true"><mat-icon>memory</mat-icon></span>
@if (tenantAdmin) {
@if (canAdd) {
<div class="tb-home-setup-empty-text">
<p>{{ 'home.devices.none' | translate }}</p>
<div class="tb-home-setup-empty-actions">
@ -69,7 +69,13 @@
@for (row of rows(); track row.id) {
<tr (click)="open(row)">
<td class="col-name">
<span class="tb-devices-cell-main"><a class="tb-home-cell-link" [routerLink]="row.url" (click)="$event.stopPropagation()">{{ row.name }}</a></span>
<span class="tb-devices-cell-main">
@if (row.url) {
<a class="tb-home-cell-link" [routerLink]="row.url" (click)="$event.stopPropagation()">{{ row.name }}</a>
} @else {
{{ row.name }}
}
</span>
<span class="tb-devices-cell-sub">{{ row.profile }}</span>
</td>
<td class="col-profile">{{ row.profile }}</td>
@ -90,7 +96,7 @@
} @else if (loaded()) {
<div class="tb-home-empty-note">{{ ('home.devices.none-' + (filter() ?? 'active')) | translate }}</div>
}
<tb-home-list-footer [total]="listed()" [expanded]="expanded()" link="/entities/devices/all" [params]="viewAllParams()"
<tb-home-list-footer [total]="listed()" [expanded]="expanded()" [link]="devicesLink" [params]="viewAllParams()"
(expandedChange)="expanded.set($event)"></tb-home-list-footer>
}
</tb-home-card>

22
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<AppState>);
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<DeviceState | null>(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<DeviceQuery[]>(() => {
@ -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)
};
}
}

6
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;
}
}

40
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<StatusKind>(() => 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'},

128
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<Record<EntityType, string>> = {
[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<AppState>);
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;
}
}
}

17
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<AppState>).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() : []);
}

19
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<AppState>);
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() : []);
}

1
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}}?",

Loading…
Cancel
Save