use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantDisableSelfEvenWithExplicitEditPermission.
@Test
@ExpectValidationException("disabled")
public void cantDisableSelfEvenWithExplicitEditPermission() {
User vo = insertUser(editRole, readRole);
runAs.runAs(vo, () -> {
User self = service.get(vo.getId());
self.setDisabled(true);
service.update(self.getId(), self);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantAddRolesToSelf.
@Test
@ExpectValidationException("roles")
public void cantAddRolesToSelf() {
setEditSelfPermission(MangoPermission.requireAnyRole(PermissionHolder.USER_ROLE));
User vo = newVO(null);
vo.setRoles(Collections.singleton(editRole));
vo.setEditPermission(MangoPermission.superadminOnly());
service.insert(vo);
runAs.runAs(vo, () -> {
User self = service.get(vo.getId());
self.setRoles(Stream.concat(self.getRoles().stream(), Stream.of(readRole)).collect(Collectors.toSet()));
service.update(self.getId(), self);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method testChangeUsernameWithoutPermission.
@Test
@ExpectValidationException("username")
public void testChangeUsernameWithoutPermission() {
setEditSelfPermission(MangoPermission.requireAnyRole(readRole));
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(ChangeOwnUsernamePermissionDefinition.PERMISSION);
Set<Set<Role>> roleSet = def.getPermission().getRoles();
Set<Set<Role>> newRoles = new HashSet<>();
newRoles.add(Collections.singleton(editRole));
for (Set<Role> roles : roleSet) {
if (roles.contains(PermissionHolder.USER_ROLE)) {
// skip the user role
continue;
}
newRoles.add(roles);
}
systemPermissionService.update(new MangoPermission(newRoles), def);
User vo = newVO(readUser);
vo.setRoles(Collections.singleton(readRole));
service.insert(vo);
User saved = service.get(vo.getId());
runAs.runAs(saved, () -> {
saved.setUsername(randomXid());
service.update(saved.getId(), saved);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-core-public by infiniteautomation.
the class UsersServiceTest method cantChangeSessionExpirationOfSelf.
@Test
@ExpectValidationException({ "sessionExpirationOverride", "sessionExpirationPeriods", "sessionExpirationPeriodType" })
public void cantChangeSessionExpirationOfSelf() {
User user = insertUser();
runAs.runAs(user, () -> {
User self = service.get(user.getId());
self.setSessionExpirationOverride(true);
self.setSessionExpirationPeriods(5);
self.setSessionExpirationPeriodType("MINUTES");
service.update(self.getId(), self);
});
}
use of com.infiniteautomation.mango.rules.ExpectValidationException in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsServiceTest method testCannotRemoveToggleAccess.
@Test
@ExpectValidationException("togglePermission")
public void testCannotRemoveToggleAccess() {
MaintenanceEventVO vo = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
MaintenanceEventVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
fromDb.setTogglePermission(MangoPermission.superadminOnly());
service.update(fromDb.getId(), fromDb);
});
}
Aggregations