use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerServiceTest method testCannotUpdateUnauthorizedScriptRole.
@Test
@ExpectValidationException("scriptRoles")
public void testCannotUpdateUnauthorizedScriptRole() {
addRoleToCreatePermission(editRole);
SetPointEventHandlerVO vo = newVO(editUser);
vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(editRole));
vo.setScriptRoles(permissions);
runAs.runAs(editUser, () -> {
SetPointEventHandlerVO fromDb = (SetPointEventHandlerVO) service.insert(vo);
ScriptPermissions newPermissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
fromDb.setScriptRoles(newPermissions);
service.update(fromDb.getId(), fromDb);
});
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method testDelete.
@Test(expected = NotFoundException.class)
@Override
public void testDelete() {
EmailEventHandlerVO vo = newVO(readUser);
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
vo.setScriptRoles(permissions);
service.update(vo.getXid(), vo);
EmailEventHandlerVO fromDb = (EmailEventHandlerVO) service.get(vo.getId());
assertVoEqual(vo, fromDb);
service.delete(vo.getId());
service.get(vo.getId());
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method newVO.
@Override
EmailEventHandlerVO newVO(User user) {
EmailEventHandlerVO vo = (EmailEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
vo.setXid(UUID.randomUUID().toString());
vo.setName(UUID.randomUUID().toString());
ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
vo.setScriptRoles(permissions);
List<EventTypeMatcher> eventTypes = Collections.singletonList(new EventTypeMatcher(new MockEventType(readRole)));
vo.setEventTypes(eventTypes);
return vo;
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method testCannotInsertUnauthorizedScriptRole.
@Test
@ExpectValidationException("scriptRoles")
public void testCannotInsertUnauthorizedScriptRole() {
addRoleToCreatePermission(editRole);
EmailEventHandlerVO vo = newVO(editUser);
vo.setReadPermission(MangoPermission.requireAnyRole(editRole));
vo.setEditPermission(MangoPermission.requireAnyRole(editRole));
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
vo.setScriptRoles(permissions);
runAs.runAs(editUser, () -> {
service.insert(vo);
});
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerDefinition method handleRoleEvent.
@Override
public void handleRoleEvent(SetPointEventHandlerVO vo, DaoEvent<? extends RoleVO> event) {
// Remove and re-serialize our handler's script roles if it has a role that was deleted
if (vo.getScriptRoles().getRoles().contains(event.getVo().getRole())) {
switch(event.getType()) {
case UPDATE:
break;
case DELETE:
Set<Role> updated = new HashSet<>(vo.getScriptRoles().getRoles());
updated.remove(event.getVo().getRole());
Set<Role> allRoles = new HashSet<>();
for (Role role : updated) {
allRoles.addAll(service.getAllInheritedRoles(role));
}
ScriptPermissions permission = new ScriptPermissions(allRoles, vo.getScriptRoles().getPermissionHolderName());
vo.setScriptRoles(permission);
eventHandlerService.update(vo.getId(), vo);
break;
default:
break;
}
}
}
Aggregations