Fix for removing user from sysadmin level alarm unassignment
This commit is contained in:
parent
1cd1df0401
commit
5f8d6176a5
@ -82,7 +82,7 @@ public class DefaultUserService extends AbstractTbEntityService implements TbUse
|
|||||||
UserId userId = tbUser.getId();
|
UserId userId = tbUser.getId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tbAlarmService.unassignUserAlarms(tenantId, tbUser, System.currentTimeMillis());
|
tbAlarmService.unassignUserAlarms(tbUser.getTenantId(), tbUser, System.currentTimeMillis());
|
||||||
userService.deleteUser(tenantId, userId);
|
userService.deleteUser(tenantId, userId);
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, customerId, userId, tbUser,
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, customerId, userId, tbUser,
|
||||||
user, ActionType.DELETED, true, null, customerId.toString());
|
user, ActionType.DELETED, true, null, customerId.toString());
|
||||||
|
|||||||
@ -531,6 +531,55 @@ public class AlarmControllerTest extends AbstractControllerTest {
|
|||||||
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ALARM_UNASSIGNED);
|
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ALARM_UNASSIGNED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnassignTenantUserAlarmOnUserRemoving() throws Exception {
|
||||||
|
loginDifferentTenant();
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setAuthority(Authority.TENANT_ADMIN);
|
||||||
|
user.setTenantId(tenantId);
|
||||||
|
user.setEmail("tenantForAssign@thingsboard.org");
|
||||||
|
User savedUser = createUser(user, "password");
|
||||||
|
|
||||||
|
Device device = createDevice("Different tenant device", "default", "differentTenantTest");
|
||||||
|
|
||||||
|
Alarm alarm = Alarm.builder()
|
||||||
|
.type(TEST_ALARM_TYPE)
|
||||||
|
.tenantId(savedDifferentTenant.getId())
|
||||||
|
.originator(device.getId())
|
||||||
|
.severity(AlarmSeverity.MAJOR)
|
||||||
|
.build();
|
||||||
|
alarm = doPost("/api/alarm", alarm, Alarm.class);
|
||||||
|
Assert.assertNotNull(alarm);
|
||||||
|
|
||||||
|
alarm = doGet("/api/alarm/info/" + alarm.getId(), AlarmInfo.class);
|
||||||
|
Assert.assertNotNull(alarm);
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
|
long beforeAssignmentTs = System.currentTimeMillis();
|
||||||
|
|
||||||
|
doPost("/api/alarm/" + alarm.getId() + "/assign/" + savedUser.getId().getId()).andExpect(status().isOk());
|
||||||
|
AlarmInfo foundAlarm = doGet("/api/alarm/info/" + alarm.getId(), AlarmInfo.class);
|
||||||
|
Assert.assertNotNull(foundAlarm);
|
||||||
|
Assert.assertEquals(savedUser.getId(), foundAlarm.getAssigneeId());
|
||||||
|
Assert.assertTrue(foundAlarm.getAssignTs() >= beforeAssignmentTs);
|
||||||
|
|
||||||
|
beforeAssignmentTs = System.currentTimeMillis();
|
||||||
|
|
||||||
|
Mockito.reset(tbClusterService, auditLogService);
|
||||||
|
|
||||||
|
loginSysAdmin();
|
||||||
|
|
||||||
|
doDelete("/api/user/" + savedUser.getId().getId()).andExpect(status().isOk());
|
||||||
|
|
||||||
|
loginDifferentTenant();
|
||||||
|
|
||||||
|
foundAlarm = doGet("/api/alarm/info/" + alarm.getId(), AlarmInfo.class);
|
||||||
|
Assert.assertNotNull(foundAlarm);
|
||||||
|
Assert.assertNull(foundAlarm.getAssigneeId());
|
||||||
|
Assert.assertTrue(foundAlarm.getAssignTs() >= beforeAssignmentTs);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnassignAlarmOnUserRemoving() throws Exception {
|
public void testUnassignAlarmOnUserRemoving() throws Exception {
|
||||||
loginDifferentTenant();
|
loginDifferentTenant();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user