Search in sources :

Example 6 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

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 7 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

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)

Example 8 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

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

Example 9 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

the class EmailEventHandlerVO method readObject.

@SuppressWarnings({ "unchecked", "deprecation" })
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    // NOTE: after deserialization the recipient lists need to be cleaned of deleted references,
    // See MailingListDao.cleanRecipientsList.  This happens in the DAO
    int ver = in.readInt();
    subject = SUBJECT_INCLUDE_EVENT_MESSAGE;
    if (ver == 1) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = null;
        additionalContext = new ArrayList<IntStringPair>();
        scriptRoles = new ScriptPermissions();
        script = null;
    } else if (ver == 2) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = new ArrayList<IntStringPair>();
        scriptRoles = new ScriptPermissions();
        script = null;
    } else if (ver == 3) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptRoles = new ScriptPermissions();
        script = null;
    } else if (ver == 4) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        com.serotonin.m2m2.rt.script.ScriptPermissions oldPermissions = (com.serotonin.m2m2.rt.script.ScriptPermissions) in.readObject();
        if (oldPermissions != null) {
            // We will be using this in the upgrade so this is temporary and will be used to set
            // the scriptRoles
            legacyScriptRoles = oldPermissions.getAllLegacyPermissions();
            legacyPermissionHolderName = oldPermissions.getPermissionHolderName();
        } else {
            scriptRoles = new ScriptPermissions();
        }
        script = SerializationHelper.readSafeUTF(in);
    } else if (ver == 5) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = in.readBoolean();
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        com.serotonin.m2m2.rt.script.ScriptPermissions oldPermissions = (com.serotonin.m2m2.rt.script.ScriptPermissions) in.readObject();
        if (oldPermissions != null) {
            // We will be using this in the upgrade so this is temporary and will be used to set
            // the scriptRoles
            legacyScriptRoles = oldPermissions.getAllLegacyPermissions();
            legacyPermissionHolderName = oldPermissions.getPermissionHolderName();
        } else {
            scriptRoles = new ScriptPermissions();
        }
        script = SerializationHelper.readSafeUTF(in);
    } else if (ver == 6) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = in.readBoolean();
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptRoles = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
    } else if (ver == 7) {
        List<RecipientListEntryBean> legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            activeRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                activeRecipients.add(b.createEmailRecipient());
            }
        }
        sendEscalation = in.readBoolean();
        repeatEscalations = in.readBoolean();
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            escalationRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                escalationRecipients.add(b.createEmailRecipient());
            }
        }
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        legacy = (List<RecipientListEntryBean>) in.readObject();
        if (legacy != null) {
            inactiveRecipients = new ArrayList<>();
            for (RecipientListEntryBean b : legacy) {
                inactiveRecipients.add(b.createEmailRecipient());
            }
        }
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptRoles = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
        subject = in.readInt();
    } else if (ver == 8) {
        activeRecipients = (List<MailingListRecipient>) in.readObject();
        sendEscalation = in.readBoolean();
        repeatEscalations = in.readBoolean();
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<MailingListRecipient>) in.readObject();
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<MailingListRecipient>) in.readObject();
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptRoles = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
        subject = in.readInt();
    }
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) ArrayList(java.util.ArrayList) List(java.util.List) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Example 10 with ScriptPermissions

use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.

the class SetPointEventHandlerVO method readObject.

@SuppressWarnings({ "unchecked", "deprecation" })
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int ver = in.readInt();
    // Switch on the version of the class so that version changes can be elegantly handled.
    if (ver == 1) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = inactiveScript = null;
        additionalContext = new ArrayList<IntStringPair>();
        scriptRoles = new ScriptPermissions();
    } else if (ver == 2) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = SerializationHelper.readSafeUTF(in);
        inactiveScript = SerializationHelper.readSafeUTF(in);
        additionalContext = new ArrayList<IntStringPair>();
        scriptRoles = new ScriptPermissions();
    } else if (ver == 3) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = SerializationHelper.readSafeUTF(in);
        inactiveScript = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        com.serotonin.m2m2.rt.script.ScriptPermissions oldPermissions = (com.serotonin.m2m2.rt.script.ScriptPermissions) in.readObject();
        if (oldPermissions != null) {
            // We will be using this in the upgrade so this is temporary and will be used to set
            // the scriptRoles
            legacyScriptRoles = oldPermissions.getAllLegacyPermissions();
            legacyPermissionHolderName = oldPermissions.getPermissionHolderName();
        } else {
            scriptRoles = new ScriptPermissions();
        }
    } else if (ver == 4) {
        targetPointId = in.readInt();
        activeAction = in.readInt();
        activeValueToSet = SerializationHelper.readSafeUTF(in);
        activePointId = in.readInt();
        inactiveAction = in.readInt();
        inactiveValueToSet = SerializationHelper.readSafeUTF(in);
        inactivePointId = in.readInt();
        activeScript = SerializationHelper.readSafeUTF(in);
        inactiveScript = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptRoles = (ScriptPermissions) in.readObject();
    }
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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