diff --git a/Maintenance Events/src-test/com/infiniteautomation/mango/spring/service/MaintenanceEventsServiceTest.java b/Maintenance Events/src-test/com/infiniteautomation/mango/spring/service/MaintenanceEventsServiceTest.java index f362581e4..6106db61e 100644 --- a/Maintenance Events/src-test/com/infiniteautomation/mango/spring/service/MaintenanceEventsServiceTest.java +++ b/Maintenance Events/src-test/com/infiniteautomation/mango/spring/service/MaintenanceEventsServiceTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -140,4 +141,34 @@ public void testAddEditRoleUserDoesNotHave() { //TODO Test Add/Remove/Use Toggle Permission + @Override + String getReadRolesContextKey() { + return "toggleRoles"; + } + + @Override + String getEditRolesContextKey() { + return "toggleRoles"; + } + + @Test + @Override + public void testAddReadRoleUserDoesNotHave() { + runTest(() -> { + MaintenanceEventVO vo = newVO(readUser); + setReadRoles(Collections.singleton(roleService.getUserRole()), vo); + setEditRoles(Collections.singleton(roleService.getUserRole()), vo); + getService().permissionService.runAsSystemAdmin(() -> { + service.insert(vo); + }); + getService().permissionService.runAs(readUser, () -> { + MaintenanceEventVO fromDb = service.get(vo.getId()); + assertVoEqual(vo, fromDb); + vo.setToggleRoles(Collections.singleton(roleService.getSuperadminRole())); + service.update(fromDb.getId(), fromDb); + }); + + }, getReadRolesContextKey(), getReadRolesContextKey()); + } + } diff --git a/Watchlist/src-test/com/infiniteautomation/mango/spring/service/WatchListServiceTest.java b/Watchlist/src-test/com/infiniteautomation/mango/spring/service/WatchListServiceTest.java index 88197542a..e87ee3d29 100644 --- a/Watchlist/src-test/com/infiniteautomation/mango/spring/service/WatchListServiceTest.java +++ b/Watchlist/src-test/com/infiniteautomation/mango/spring/service/WatchListServiceTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -129,4 +130,38 @@ public void testCreatePrivilegeFails() { service.insert(vo); }); } + + @Override + @Test + public void testAddReadRoleUserDoesNotHave() { + runTest(() -> { + WatchListVO vo = newVO(readUser); + + //Change Owner + vo.setUserId(this.allUser.getId()); + + setReadRoles(Collections.singleton(roleService.getUserRole()), vo); + setEditRoles(Collections.singleton(roleService.getUserRole()), vo); + getService().permissionService.runAsSystemAdmin(() -> { + service.insert(vo); + }); + getService().permissionService.runAs(readUser, () -> { + WatchListVO fromDb = service.get(vo.getId()); + assertVoEqual(vo, fromDb); + setReadRoles(Collections.singleton(roleService.getSuperadminRole()), fromDb); + service.update(fromDb.getId(), fromDb); + }); + + }, getReadRolesContextKey(), getReadRolesContextKey()); + } + + @Override + String getReadRolesContextKey() { + return "readRoles"; + } + + @Override + String getEditRolesContextKey() { + return "editRoles"; + } }