|
|
@ -160,6 +160,25 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.UPDATED_COMMENT, 1, updatedAlarmComment); |
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.UPDATED_COMMENT, 1, updatedAlarmComment); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testEditOthersAlarmCommentIsProhibited() throws Exception { |
|
|
|
|
|
loginCustomerUser(); |
|
|
|
|
|
AlarmComment alarmComment = createAlarmComment(alarm.getId()); |
|
|
|
|
|
|
|
|
|
|
|
JsonNode newComment = JacksonUtil.newObjectNode().set("text", new TextNode("Second customer rewrite")); |
|
|
|
|
|
alarmComment.setComment(newComment); |
|
|
|
|
|
|
|
|
|
|
|
loginSecondCustomerUser(); |
|
|
|
|
|
doPost("/api/alarm/" + alarm.getId() + "/comment", alarmComment) |
|
|
|
|
|
.andExpect(status().isForbidden()) |
|
|
|
|
|
.andExpect(statusReason(containsString("User is not allowed to edit other user's comment"))); |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
@Test |
|
|
public void testUpdateAlarmViaDifferentTenant() throws Exception { |
|
|
public void testUpdateAlarmViaDifferentTenant() throws Exception { |
|
|
loginTenantAdmin(); |
|
|
loginTenantAdmin(); |
|
|
@ -209,12 +228,36 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
.alarmId(alarm.getId()) |
|
|
.alarmId(alarm.getId()) |
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
.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))) |
|
|
CUSTOMER_USER_EMAIL))) |
|
|
.build(); |
|
|
.build(); |
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testDeleteOthersAlarmCommentIsAllowedForAuthorOrTenantAdmin() throws Exception { |
|
|
|
|
|
loginCustomerUser(); |
|
|
|
|
|
AlarmComment alarmComment = createAlarmComment(alarm.getId()); |
|
|
|
|
|
|
|
|
|
|
|
loginSecondCustomerUser(); |
|
|
|
|
|
Mockito.reset(tbClusterService, auditLogService); |
|
|
|
|
|
|
|
|
|
|
|
doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) |
|
|
|
|
|
.andExpect(status().isForbidden()) |
|
|
|
|
|
.andExpect(statusReason(containsString("User is not allowed to delete other user's comment"))); |
|
|
|
|
|
|
|
|
|
|
|
loginTenantAdmin(); |
|
|
|
|
|
doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) |
|
|
|
|
|
.andExpect(status().isOk()); |
|
|
|
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
|
|
|
.alarmId(alarm.getId()) |
|
|
|
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
|
|
|
.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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testDeleteAlarmViaTenant() throws Exception { |
|
|
public void testDeleteAlarmViaTenant() throws Exception { |
|
|
loginTenantAdmin(); |
|
|
loginTenantAdmin(); |
|
|
@ -234,13 +277,13 @@ public class AlarmCommentControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
|
assertThat(systemComment.getId()).isEqualTo(alarmComment.getId()); |
|
|
assertThat(systemComment.getId()).isEqualTo(alarmComment.getId()); |
|
|
assertThat(systemComment.getType()).isEqualTo(AlarmCommentType.SYSTEM); |
|
|
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)); |
|
|
TENANT_ADMIN_EMAIL)); |
|
|
|
|
|
|
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
AlarmComment expectedAlarmComment = AlarmComment.builder() |
|
|
.alarmId(alarm.getId()) |
|
|
.alarmId(alarm.getId()) |
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
.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))) |
|
|
TENANT_ADMIN_EMAIL))) |
|
|
.build(); |
|
|
.build(); |
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment); |
|
|
|