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());
}
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;
}
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);
});
}
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();
}
}
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();
}
}
Aggregations