Search in sources :

Example 26 with ScriptPermissions

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;
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) MangoJavaScript(com.infiniteautomation.mango.util.script.MangoJavaScript) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Example 27 with ScriptPermissions

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));
}
Also used : PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) IntStringPair(com.serotonin.db.pair.IntStringPair) ScriptContextVariableModel(com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel) ArrayList(java.util.ArrayList) MailingListRecipient(com.serotonin.m2m2.vo.mailingList.MailingListRecipient) EmailRecipientModel(com.infiniteautomation.mango.rest.latest.model.mailingList.EmailRecipientModel) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Example 28 with ScriptPermissions

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);
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test)

Example 29 with ScriptPermissions

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());
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) Test(org.junit.Test)

Example 30 with ScriptPermissions

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;
}
Also used : SetPointEventHandlerVO(com.serotonin.m2m2.vo.event.SetPointEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions)

Aggregations

ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)45 Test (org.junit.Test)20 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)16 SetPointEventHandlerVO (com.serotonin.m2m2.vo.event.SetPointEventHandlerVO)14 Role (com.serotonin.m2m2.vo.role.Role)12 ExpectValidationException (com.infiniteautomation.mango.rules.ExpectValidationException)8 HashSet (java.util.HashSet)8 IntStringPair (com.serotonin.db.pair.IntStringPair)6 JsonArray (com.serotonin.json.type.JsonArray)6 ArrayList (java.util.ArrayList)6 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)5 EventTypeMatcher (com.serotonin.m2m2.rt.event.type.EventTypeMatcher)4 MockEventType (com.serotonin.m2m2.rt.event.type.MockEventType)4 List (java.util.List)4 Set (java.util.Set)4 ScriptContextVariableModel (com.infiniteautomation.mango.rest.latest.model.javascript.MangoJavaScriptModel.ScriptContextVariableModel)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonValue (com.serotonin.json.type.JsonValue)2 RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)2 ResultSet (java.sql.ResultSet)2