use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-modules-public by infiniteautomation.
the class MangoJavaScriptModel method toVO.
public MangoJavaScript toVO() {
MangoJavaScript vo = new MangoJavaScript();
vo.setWrapInFunction(wrapInFunction);
vo.setContext(convertContext());
vo.setLogLevel(logLevel);
PermissionService service = Common.getBean(PermissionService.class);
vo.setPermissions(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(permissions)));
if (resultDataType != null)
vo.setResultDataType(DataType.fromName(resultDataType));
vo.setScript(script);
vo.setAdditionalContext(additionalContext);
return vo;
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-modules-public by infiniteautomation.
the class EmailEventHandlerModel method readInto.
@Override
public void readInto(EmailEventHandlerVO vo) {
super.readInto(vo);
if (activeRecipients != null) {
List<MailingListRecipient> beans = new ArrayList<>();
for (EmailRecipientModel model : activeRecipients) beans.add(model.fromModel());
vo.setActiveRecipients(beans);
}
vo.setSendEscalation(sendEscalation);
vo.setRepeatEscalations(repeatEscalations);
vo.setEscalationDelayType(Common.TIME_PERIOD_CODES.getId(escalationDelayType));
vo.setEscalationDelay(escalationDelay);
if (escalationRecipients != null) {
List<MailingListRecipient> beans = new ArrayList<>();
for (EmailRecipientModel model : escalationRecipients) beans.add(model.fromModel());
vo.setEscalationRecipients(beans);
}
vo.setSendInactive(sendInactive);
vo.setInactiveOverride(inactiveOverride);
if (inactiveRecipients != null) {
List<MailingListRecipient> beans = new ArrayList<>();
for (EmailRecipientModel model : inactiveRecipients) beans.add(model.fromModel());
vo.setInactiveRecipients(beans);
}
vo.setIncludeSystemInfo(includeSystemInfo);
if (includePointValueCount != null)
vo.setIncludePointValueCount(includePointValueCount);
vo.setIncludeLogfile(includeLogfile);
vo.setCustomTemplate(customTemplate);
vo.setScript(script);
PermissionService service = Common.getBean(PermissionService.class);
vo.setScriptRoles(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(scriptPermissions)));
if (scriptContext != null) {
List<IntStringPair> additionalContext = new ArrayList<>();
for (ScriptContextVariableModel var : scriptContext) {
Integer id = DataPointDao.getInstance().getIdByXid(var.getXid());
if (id != null) {
additionalContext.add(new IntStringPair(id, var.getVariableName()));
} else {
additionalContext.add(new IntStringPair(Common.NEW_ID, var.getVariableName()));
}
}
vo.setAdditionalContext(additionalContext);
}
vo.setSubject(EmailEventHandlerVO.SUBJECT_INCLUDE_CODES.getId(subject));
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerServiceTest method testDeleteRoleUpdateVO.
@Test
public void testDeleteRoleUpdateVO() {
SetPointEventHandlerVO vo = newVO(readUser);
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
vo.setScriptRoles(permissions);
service.insert(vo);
SetPointEventHandlerVO fromDb = (SetPointEventHandlerVO) service.get(vo.getId());
assertVoEqual(vo, fromDb);
roleService.delete(editRole.getId());
roleService.delete(readRole.getId());
SetPointEventHandlerVO updated = (SetPointEventHandlerVO) service.get(fromDb.getId());
fromDb.setScriptRoles(new ScriptPermissions(Collections.emptySet()));
assertVoEqual(fromDb, updated);
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerServiceTest method testDelete.
@Test(expected = NotFoundException.class)
@Override
public void testDelete() {
SetPointEventHandlerVO vo = newVO(readUser);
ScriptPermissions permissions = new ScriptPermissions(Sets.newHashSet(readRole, editRole));
vo.setScriptRoles(permissions);
service.update(vo.getXid(), vo);
SetPointEventHandlerVO fromDb = (SetPointEventHandlerVO) 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 SetPointEventHandlerServiceTest method newVO.
@Override
SetPointEventHandlerVO newVO(User owner) {
SetPointEventHandlerVO vo = (SetPointEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(SetPointEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
vo.setXid(UUID.randomUUID().toString());
vo.setName(UUID.randomUUID().toString());
ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
vo.setScriptRoles(permissions);
vo.setActiveScript("return true;");
vo.setInactiveScript("return true;");
vo.setTargetPointId(activeDataPoint.getId());
vo.setActivePointId(activeDataPoint.getId());
vo.setActiveAction(SetPointEventHandlerVO.SET_ACTION_POINT_VALUE);
vo.setInactivePointId(inactiveDataPoint.getId());
vo.setInactiveAction(SetPointEventHandlerVO.SET_ACTION_POINT_VALUE);
return vo;
}
Aggregations