use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class AbstractVOServiceWithPermissionsTest 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(readUser);
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 AbstractBasicVOServiceWithPermissionsTestBase method addRoleToCreatePermission.
void addRoleToCreatePermission(Role vo) {
String permissionType = getCreatePermissionType();
if (permissionType != null) {
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
Set<Set<Role>> roleSet = def.getPermission().getRoles();
Set<Set<Role>> newRoles = new HashSet<>();
newRoles.add(Collections.singleton(vo));
for (Set<Role> roles : roleSet) {
newRoles.add(new HashSet<>(roles));
}
Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
}
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
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.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasSingleRoleOKHasPerm.
@Test
public void ensureHasSingleRoleOKHasPerm() {
Set<Role> roles = this.randomRoles(2);
User testUser = this.createTestUser(roles);
for (Role role : testUser.getRoles()) {
permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(role));
}
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method ensureHasAnyRoleOKHasOne.
@Test
public void ensureHasAnyRoleOKHasOne() {
Role perm1 = this.randomRole();
Role perm2 = this.randomRole();
Role perm3 = this.randomRole();
User testUser = this.createTestUser(Sets.newHashSet(perm1, perm2));
permissionService.ensurePermission(testUser, MangoPermission.requireAnyRole(perm1, perm3));
}
Aggregations