use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class RoleServiceTest method testGetAll.
@Override
@Test
public void testGetAll() {
List<RoleVO> all = service.dao.getAll();
for (RoleVO vo : all) {
if (!StringUtils.equals(PermissionHolder.SUPERADMIN_ROLE_XID, vo.getXid()) && !StringUtils.equals(PermissionHolder.USER_ROLE_XID, vo.getXid()) && !StringUtils.equals(PermissionHolder.ANONYMOUS_ROLE_XID, vo.getXid())) {
service.delete(vo.getId());
}
}
List<RoleVO> vos = new ArrayList<>();
vos.add(service.get(PermissionHolder.SUPERADMIN_ROLE_XID));
vos.add(service.get(PermissionHolder.USER_ROLE_XID));
vos.add(service.get(PermissionHolder.ANONYMOUS_ROLE_XID));
for (int i = 0; i < 5; i++) {
vos.add(insertNewVO(readUser));
}
all = service.dao.getAll();
for (RoleVO vo : all) {
RoleVO expected = null;
for (RoleVO e : vos) {
if (e.getId() == vo.getId()) {
expected = e;
}
}
assertNotNull("Didn't find expected VO", expected);
assertVoEqual(expected, vo);
}
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class RoleServiceTest method userCanOnlySeeOwnRoles.
@Test
public void userCanOnlySeeOwnRoles() {
RoleVO inheritedRole = insertNewVO(readUser);
RoleVO directlyAssignedRole = newVO(readUser);
directlyAssignedRole.setInherited(Collections.singleton(inheritedRole.getRole()));
service.insert(directlyAssignedRole);
RoleVO roleUserDoesNotHave = insertNewVO(readUser);
User testUser = createUser("test-user@example.com", "test-user@example.com", "test-user@example.com", "test-user@example.com", directlyAssignedRole.getRole());
runAs.runAs(testUser, () -> {
Set<String> roleXids = service.list().stream().map(AbstractVO::getXid).collect(Collectors.toSet());
Assert.assertTrue("Should see anonymous role", roleXids.contains(PermissionHolder.ANONYMOUS_ROLE_XID));
Assert.assertTrue("Should see user role", roleXids.contains(PermissionHolder.USER_ROLE_XID));
Assert.assertTrue("Should see directly assigned role", roleXids.contains(directlyAssignedRole.getXid()));
Assert.assertTrue("Should see inherited role", roleXids.contains(inheritedRole.getXid()));
Assert.assertFalse("Should not see role that user does not have", roleXids.contains(roleUserDoesNotHave.getXid()));
});
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class RoleServiceTest method cannotModifySuperadminRole.
@Test
@ExpectValidationException("xid")
public void cannotModifySuperadminRole() {
RoleVO vo = service.get(PermissionHolder.SUPERADMIN_ROLE_XID);
RoleVO updated = new RoleVO(Common.NEW_ID, vo.getXid(), "Superadmin default changed");
service.update(vo.getXid(), updated);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class PermissionServiceTest method randomRole.
Role randomRole() {
RoleVO vo = new RoleVO(Common.NEW_ID, UUID.randomUUID().toString(), "Random permission");
roleService.insert(vo);
return new Role(vo);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class RoleDao method saveRelationalData.
@Override
public void saveRelationalData(RoleVO existing, RoleVO vo) {
if (existing != null) {
// Drop the mappings
this.create.deleteFrom(RoleInheritance.ROLE_INHERITANCE).where(RoleInheritance.ROLE_INHERITANCE.roleId.eq(vo.getId())).execute();
}
if (vo.getInherited() != null && vo.getInherited().size() > 0) {
List<Query> inserts = new ArrayList<>();
for (Role role : vo.getInherited()) {
inserts.add(DSL.insertInto(RoleInheritance.ROLE_INHERITANCE).columns(RoleInheritance.ROLE_INHERITANCE.roleId, RoleInheritance.ROLE_INHERITANCE.inheritedRoleId).values(vo.getId(), role.getId()));
}
create.batch(inserts).execute();
}
}
Aggregations