use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.
the class EmailEventHandlerDaoTest method newVO.
@Override
EmailEventHandlerVO newVO() {
EmailEventHandlerVO vo = (EmailEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
vo.setXid(UUID.randomUUID().toString());
vo.setName(UUID.randomUUID().toString());
ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
vo.setScriptRoles(permissions);
List<EventTypeMatcher> eventTypes = Collections.singletonList(new EventTypeMatcher(new MockEventType(readRole)));
vo.setEventTypes(eventTypes);
return vo;
}
use of com.infiniteautomation.mango.util.script.ScriptPermissions in project ma-core-public by MangoAutomation.
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 MangoAutomation.
the class EmailEventHandlerDefinition method handleRoleEvent.
@Override
public void handleRoleEvent(EmailEventHandlerVO 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 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;
}
Aggregations