use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method canAddOwnRolesWhenUpdating.
@Test
public void canAddOwnRolesWhenUpdating() {
Role createRole = createUsersRole();
User createUser = insertUser(createRole, editRole, readRole);
User otherUser = insertUser();
runAs.runAs(createUser, () -> {
otherUser.setRoles(Collections.singleton(readRole));
service.update(otherUser.getId(), otherUser);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantCreateUserYouCantEdit.
@Test
@ExpectValidationException("editPermission")
public void cantCreateUserYouCantEdit() {
Role createRole = createUsersRole();
User createUser = insertUser(readRole, createRole);
// noinspection Convert2MethodRef
runAs.runAs(createUser, () -> insertUser());
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantAddAdditionalRolesWhenUpdating.
@Test
@ExpectValidationException("roles")
public void cantAddAdditionalRolesWhenUpdating() {
Role roleToAdd = createRole(randomXid(), "Some other role").getRole();
Role createRole = createUsersRole();
User createUser = insertUser(createRole, editRole, readRole);
User otherUser = insertUser();
runAs.runAs(createUser, () -> {
otherUser.setRoles(Collections.singleton(roleToAdd));
service.update(otherUser.getId(), otherUser);
});
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UsersServiceTest method insertUser.
public User insertUser(Role... roles) {
User user = newVO(null);
user.setReadPermission(MangoPermission.requireAnyRole(readRole));
user.setEditPermission(MangoPermission.requireAnyRole(editRole));
user.setRoles(Arrays.stream(roles).collect(Collectors.toSet()));
return service.insert(user);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class AbstractVOServiceWithPermissionsTest method removeRoleFromCreatePermission.
void removeRoleFromCreatePermission(Role vo) {
String permissionType = getCreatePermissionType();
if (permissionType != null) {
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
MangoPermission permission = def.getPermission();
Common.getBean(SystemPermissionService.class).update(new MangoPermission(permission.withoutRole(vo).getRoles()), def);
}
}
Aggregations