use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-modules-public by infiniteautomation.
the class SetPointEventHandlerModel method readInto.
@Override
public void readInto(SetPointEventHandlerVO vo) {
super.readInto(vo);
Integer targetId = DataPointDao.getInstance().getIdByXid(targetPointXid);
if (targetId != null)
vo.setTargetPointId(targetId);
vo.setActiveAction(SetPointEventHandlerVO.SET_ACTION_CODES.getId(activeAction));
if (activeValueToSet != null)
vo.setActiveValueToSet(activeValueToSet.toString());
if (activePointXid != null) {
Integer activePointId = DataPointDao.getInstance().getIdByXid(activePointXid);
if (activePointId != null)
vo.setActivePointId(activePointId);
}
vo.setActiveScript(activeScript);
vo.setInactiveAction(SetPointEventHandlerVO.SET_ACTION_CODES.getId(inactiveAction));
if (inactiveValueToSet != null)
vo.setInactiveValueToSet(inactiveValueToSet.toString());
if (inactivePointXid != null) {
Integer inactivePointId = DataPointDao.getInstance().getIdByXid(inactivePointXid);
if (inactivePointId != null)
vo.setInactivePointId(inactivePointId);
}
vo.setInactiveScript(inactiveScript);
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);
}
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class ScriptPermissionConverter method jsonWrite.
@Override
public void jsonWrite(JsonWriter writer, Object value) throws IOException, JsonException {
ScriptPermissions permission = (ScriptPermissions) value;
JsonArray roles = new JsonArray();
for (Role role : permission.getRoles()) {
roles.add(role.getXid());
}
writer.writeObject(roles);
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
the class ScriptPermissionConverter method jsonWrite.
@Override
public JsonValue jsonWrite(JsonTypeWriter writer, Object value) throws JsonException {
ScriptPermissions permission = (ScriptPermissions) value;
JsonArray roles = new JsonArray();
for (Role role : permission.getRoles()) {
roles.add(role.getXid());
}
return roles;
}
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;
}
}
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by infiniteautomation.
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