Browse Source

[Alarm comment] Fixed alarm comment deletion button visibility for admin (#15837)

* fixed alarm comment deletion button visibility for admin

* docs(alarm): point comment-permission note at the backend check it mirrors
pull/15849/head
Daria Shevchenko 3 months ago
committed by GitHub
parent
commit
d95724fd5e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      ui-ngx/src/app/modules/home/components/alarm/alarm-comment.component.html
  2. 16
      ui-ngx/src/app/modules/home/components/alarm/alarm-comment.component.ts

4
ui-ngx/src/app/modules/home/components/alarm/alarm-comment.component.html

@ -69,7 +69,7 @@
<ng-template #userComment> <ng-template #userComment>
<div class="user-comment flex flex-row items-center justify-start gap-2" <div class="user-comment flex flex-row items-center justify-start gap-2"
*ngIf="!displayDataElement.edit; else commentEditing" *ngIf="!displayDataElement.edit; else commentEditing"
(mouseenter)="onCommentMouseEnter(displayDataElement.commentId, i)" (mouseenter)="onCommentMouseEnter(i)"
(mouseleave)="onCommentMouseLeave(i)"> (mouseleave)="onCommentMouseLeave(i)">
<div *ngIf="displayDataElement.userExists; else userDeleted" <div *ngIf="displayDataElement.userExists; else userDeleted"
class="user-avatar flex flex-row items-center justify-center self-start xs:!hidden" class="user-avatar flex flex-row items-center justify-center self-start xs:!hidden"
@ -98,11 +98,13 @@
<div class="action-buttons flex flex-row xs:flex-col" <div class="action-buttons flex flex-row xs:flex-col"
[class.show-buttons]="displayDataElement.showActions"> [class.show-buttons]="displayDataElement.showActions">
<button mat-icon-button <button mat-icon-button
*ngIf="displayDataElement.canEdit"
type="button" type="button"
(click)="editComment(displayDataElement.commentId)"> (click)="editComment(displayDataElement.commentId)">
<mat-icon class="material-icons">edit</mat-icon> <mat-icon class="material-icons">edit</mat-icon>
</button> </button>
<button mat-icon-button <button mat-icon-button
*ngIf="displayDataElement.canDelete"
type="button" type="button"
(click)="deleteComment(displayDataElement.commentId)"> (click)="deleteComment(displayDataElement.commentId)">
<mat-icon class="material-icons">delete</mat-icon> <mat-icon class="material-icons">delete</mat-icon>

16
ui-ngx/src/app/modules/home/components/alarm/alarm-comment.component.ts

@ -22,6 +22,7 @@ import { AlarmCommentService } from '@core/http/alarm-comment.service';
import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms'; import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
import { AuthUser } from '@shared/models/user.model'; import { AuthUser } from '@shared/models/user.model';
import { Authority } from '@shared/models/authority.enum';
import { getCurrentAuthUser, selectUserDetails } from '@core/auth/auth.selectors'; import { getCurrentAuthUser, selectUserDetails } from '@core/auth/auth.selectors';
import { Direction, SortOrder } from '@shared/models/page/sort-order'; import { Direction, SortOrder } from '@shared/models/page/sort-order';
import { MAX_SAFE_PAGE_SIZE, PageLink } from '@shared/models/page/page-link'; import { MAX_SAFE_PAGE_SIZE, PageLink } from '@shared/models/page/page-link';
@ -44,6 +45,8 @@ interface AlarmCommentsDisplayData {
editedTime?: string; editedTime?: string;
editedDateAgo?: string; editedDateAgo?: string;
showActions?: boolean; showActions?: boolean;
canEdit?: boolean;
canDelete?: boolean;
commentText?: string; commentText?: string;
isSystemComment?: boolean; isSystemComment?: boolean;
avatarBgColor?: string; avatarBgColor?: string;
@ -135,6 +138,11 @@ export class AlarmCommentComponent implements OnInit {
displayDataElement.editedTime = this.datePipe.transform(alarmComment.comment.editedOn, 'yyyy-MM-dd HH:mm:ss'); displayDataElement.editedTime = this.datePipe.transform(alarmComment.comment.editedOn, 'yyyy-MM-dd HH:mm:ss');
displayDataElement.editedDateAgo = this.dateAgoPipe.transform(alarmComment.comment.editedOn) + '\n'; displayDataElement.editedDateAgo = this.dateAgoPipe.transform(alarmComment.comment.editedOn) + '\n';
displayDataElement.showActions = false; displayDataElement.showActions = false;
const isCommentAuthor = this.authUser.userId === alarmComment.userId?.id;
// Mirrors backend AlarmCommentController#deleteAlarmComment / checkUserPermission:
// author may edit and delete own comments; tenant admin may delete any comment.
displayDataElement.canEdit = isCommentAuthor;
displayDataElement.canDelete = isCommentAuthor || this.authUser.authority === Authority.TENANT_ADMIN;
displayDataElement.isSystemComment = false; displayDataElement.isSystemComment = false;
displayDataElement.avatarBgColor = this.utilsService.stringToHslColor(displayDataElement.displayName, displayDataElement.avatarBgColor = this.utilsService.stringToHslColor(displayDataElement.displayName,
40, 60); 40, 60);
@ -243,11 +251,11 @@ export class AlarmCommentComponent implements OnInit {
return this.alarmCommentSortOrder.direction === Direction.ASC; return this.alarmCommentSortOrder.direction === Direction.ASC;
} }
onCommentMouseEnter(commentId: string, displayDataIndex: number): void { onCommentMouseEnter(displayDataIndex: number): void {
if (!this.editMode) { if (!this.editMode) {
const alarmUserId = this.getAlarmCommentById(commentId).userId.id; const displayDataElement = this.displayData[displayDataIndex];
if (this.authUser.userId === alarmUserId) { if (displayDataElement.canEdit || displayDataElement.canDelete) {
this.displayData[displayDataIndex].showActions = true; displayDataElement.showActions = true;
} }
} }
} }

Loading…
Cancel
Save