use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class AbstractBasicVOServiceWithPermissionsTestBase method testAddEditRoleUserDoesNotHave.
/**
* There will be 2 validation messages about this, must retain permission AND cannot add/remove a role you do not have
*/
@Test
public void testAddEditRoleUserDoesNotHave() {
validation.expectValidationException(getEditPermissionContextKey());
VO vo = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
VO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
setEditPermission(MangoPermission.superadminOnly(), fromDb);
service.update(fromDb.getId(), fromDb);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class AbstractBasicVOServiceWithPermissionsTestBase method testAddReadRoleUserDoesNotHave.
/**
* There will be 2 validation messages about this, must retain permission AND cannot add/remove a role you do not have
*/
@Test
public void testAddReadRoleUserDoesNotHave() {
validation.expectValidationException(getReadPermissionContextKey());
VO vo = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
VO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
setReadPermission(MangoPermission.superadminOnly(), fromDb);
service.update(fromDb.getId(), fromDb);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class DataPointPermissionTest method testDeleteDataPoint.
/**
* Test to ensure an un-used permission is deleted
*/
@Test
public void testDeleteDataPoint() {
// Insert some data points
Set<Role> readRoles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
List<IDataPoint> points = this.createMockDataPoints(1, false, MangoPermission.requireAnyRole(readRoles), new MangoPermission());
DataPointService service = Common.getBean(DataPointService.class);
runAs.runAs(new PermissionHolder() {
@Override
public String getPermissionHolderName() {
return "Test";
}
@Override
public boolean isPermissionHolderDisabled() {
return false;
}
@Override
public Set<Role> getRoles() {
return readRoles;
}
}, () -> {
List<Integer> ids = points.stream().map(dp -> dp.getId()).collect(Collectors.toList());
QueryBuilder<DataPointVO> query = service.buildQuery().in("id", ids.toArray());
List<DataPointVO> vos = query.query();
assertEquals(points.size(), vos.size());
for (DataPointVO vo : vos) {
assertTrue(points.contains(vo));
}
List<Integer> existing = getPermissionIds(null);
// Delete the source and point
DataSourceDao.getInstance().delete(vos.get(0).getDataSourceId());
// We should have removed 1 permission
assertEquals(existing.size() - 1, getPermissionIds(null).size());
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionPersistenceTest method testModifyPermission.
/**
* Modify a permission and ensure that it is retrieved correctly from the database after
*/
@Test
public void testModifyPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// insert some roles
Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
MangoPermission permission = service.findOrCreate(MangoPermission.requireAnyRole(roles));
MangoPermission read = service.get(permission.getId());
assertEquals(2, read.getRoles().size());
Iterator<Set<Role>> it = read.getRoles().iterator();
Role toKeep = it.next().iterator().next();
MangoPermission keep = service.findOrCreate(MangoPermission.requireAnyRole(toKeep));
read = service.get(keep.getId());
assertEquals(1, read.getRoles().size());
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionPersistenceTest method testOrPermission.
@Test
public void testOrPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// Create some roles
Set<Role> roles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
MangoPermission permission = service.findOrCreate(MangoPermission.requireAnyRole(roles));
MangoPermission read = service.get(permission.getId());
assertEquals(2, read.getRoles().size());
Iterator<Set<Role>> it = read.getRoles().iterator();
assertEquals(1, it.next().size());
assertEquals(1, it.next().size());
}
Aggregations