|
|
|
@ -161,25 +161,22 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateOthersAlarmCommentByTenantAdmin() throws Exception { |
|
|
|
// Tenant admins may moderate comments authored by other users — the ownership rule
|
|
|
|
// applies only to non-admin users, so a tenant admin can edit someone else's comment.
|
|
|
|
public void testEditOthersAlarmCommentIsProhibited() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
AlarmComment alarmComment = createAlarmComment(alarm.getId()); |
|
|
|
|
|
|
|
loginTenantAdmin(); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
JsonNode newComment = JacksonUtil.newObjectNode().set("text", new TextNode("Tenant rewrite")); |
|
|
|
JsonNode newComment = JacksonUtil.newObjectNode().set("text", new TextNode("Second customer rewrite")); |
|
|
|
alarmComment.setComment(newComment); |
|
|
|
AlarmComment updatedAlarmComment = saveAlarmComment(alarm.getId(), alarmComment); |
|
|
|
|
|
|
|
Assert.assertNotNull(updatedAlarmComment); |
|
|
|
Assert.assertEquals(newComment.get("text"), updatedAlarmComment.getComment().get("text")); |
|
|
|
Assert.assertEquals("true", updatedAlarmComment.getComment().get("edited").asText()); |
|
|
|
Assert.assertNotNull(updatedAlarmComment.getComment().get("editedOn")); |
|
|
|
loginSecondCustomerUser(); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/comment", alarmComment) |
|
|
|
.andExpect(status().isForbidden()) |
|
|
|
.andExpect(statusReason(containsString("User is not allowed to edit other user's comment"))); |
|
|
|
|
|
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.UPDATED_COMMENT, 1, updatedAlarmComment); |
|
|
|
loginTenantAdmin(); |
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/comment", alarmComment) |
|
|
|
.andExpect(status().isForbidden()) |
|
|
|
.andExpect(statusReason(containsString("User is not allowed to edit other user's comment"))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -231,20 +228,18 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
|
.alarmId(alarm.getId()) |
|
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("User %s deleted his comment", |
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("Comment was deleted by user %s", |
|
|
|
CUSTOMER_USER_EMAIL))) |
|
|
|
.build(); |
|
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeleteOthersAlarmCommentByTenantAdmin() throws Exception { |
|
|
|
// Tenant admins may moderate comments authored by other users — the ownership rule
|
|
|
|
// applies only to non-admin users, so a tenant admin can delete someone else's comment.
|
|
|
|
public void testDeleteOthersAlarmCommentIsAllowedForUserWithAlarmWritePermission() throws Exception { |
|
|
|
loginCustomerUser(); |
|
|
|
AlarmComment alarmComment = createAlarmComment(alarm.getId()); |
|
|
|
|
|
|
|
loginTenantAdmin(); |
|
|
|
loginSecondCustomerUser(); |
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) |
|
|
|
@ -253,10 +248,10 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
|
.alarmId(alarm.getId()) |
|
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("User %s deleted his comment", |
|
|
|
TENANT_ADMIN_EMAIL))) |
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("Comment was deleted by user %s", |
|
|
|
SECOND_CUSTOMER_USER_EMAIL))) |
|
|
|
.build(); |
|
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, secondCustomerUserId, SECOND_CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -278,13 +273,13 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
assertThat(systemComment.getId()).isEqualTo(alarmComment.getId()); |
|
|
|
assertThat(systemComment.getType()).isEqualTo(AlarmCommentType.SYSTEM); |
|
|
|
assertThat(systemComment.getComment().get("text").asText()).isEqualTo(String.format("User %s deleted his comment", |
|
|
|
assertThat(systemComment.getComment().get("text").asText()).isEqualTo(String.format("Comment was deleted by user %s", |
|
|
|
TENANT_ADMIN_EMAIL)); |
|
|
|
|
|
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
|
.alarmId(alarm.getId()) |
|
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("User %s deleted his comment", |
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("Comment was deleted by user %s", |
|
|
|
TENANT_ADMIN_EMAIL))) |
|
|
|
.build(); |
|
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
|
|