use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class SystemSettingsImporter method importImpl.
@Override
protected void importImpl() {
try {
Map<String, Object> settings = new HashMap<String, Object>();
// Finish reading it in.
for (String key : json.keySet()) {
JsonValue value = json.get(key);
// Don't import null values or database schemas
if ((value != null) && (!key.startsWith(SystemSettingsDao.DATABASE_SCHEMA_VERSION))) {
Object o = value.toNative();
if (o instanceof String) {
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(key);
if (def != null) {
// Legacy permission import
try {
Set<String> xids = PermissionService.explodeLegacyPermissionGroups((String) o);
Set<Set<Role>> roles = new HashSet<>();
for (String xid : xids) {
RoleVO role = roleService.get(xid);
if (role != null) {
roles.add(Collections.singleton(role.getRole()));
} else {
roles.add(Collections.singleton(new Role(Common.NEW_ID, xid)));
}
}
permissionService.update(new MangoPermission(roles), def);
addSuccessMessage(false, "emport.permission.prefix", key);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.permission.prefix", key);
return;
}
} else {
// Could be an export code so try and convert it
Integer id = SystemSettingsDao.getInstance().convertToValueFromCode(key, (String) o);
if (id != null)
settings.put(key, id);
else
settings.put(key, o);
}
} else {
settings.put(key, o);
}
}
}
// Now validate it. Use a new response object so we can distinguish errors in this vo
// from
// other errors.
ProcessResult voResponse = new ProcessResult();
SystemSettingsDao.getInstance().validate(settings, voResponse, user);
if (voResponse.getHasMessages())
setValidationMessages(voResponse, "emport.systemSettings.prefix", new TranslatableMessage("header.systemSettings").translate(Common.getTranslations()));
else {
SystemSettingsDao.getInstance().updateSettings(settings);
addSuccessMessage(false, "emport.systemSettings.prefix", new TranslatableMessage("header.systemSettings").translate(Common.getTranslations()));
}
} catch (Exception e) {
addFailureMessage("emport.systemSettings.prefix", new TranslatableMessage("header.systemSettings").translate(Common.getTranslations()), e.getMessage());
}
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class JsonDataImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
JsonDataVO vo = null;
boolean isNew = false;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
isNew = true;
vo = new JsonDataVO();
vo.setXid(xid);
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
// Ensure we have a default permission since null is valid in Mango 3.x
if (vo.getReadPermission() == null) {
vo.setReadPermission(new MangoPermission());
}
if (vo.getEditPermission() == null) {
vo.setEditPermission(new MangoPermission());
}
if (isNew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isNew, "emport.jsondata.prefix", xid);
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.jsondata.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerServiceTest method addRoleToCreatePermission.
void addRoleToCreatePermission(Role vo) {
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(EventHandlerCreatePermission.PERMISSION);
Set<Set<Role>> roleSet = def.getPermission().getRoles();
Set<Set<Role>> newRoles = new HashSet<>();
newRoles.add(Collections.singleton(vo));
for (Set<Role> roles : roleSet) {
newRoles.add(new HashSet<>(roles));
}
Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class AbstractVOServiceWithPermissionsTest method removeRoleFromCreatePermission.
void removeRoleFromCreatePermission(Role vo) {
String permissionType = getCreatePermissionType();
if (permissionType != null) {
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
MangoPermission permission = def.getPermission();
Common.getBean(SystemPermissionService.class).update(new MangoPermission(permission.withoutRole(vo).getRoles()), def);
}
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class AbstractBasicVOServiceWithPermissionsTestBase method addRoleToCreatePermission.
void addRoleToCreatePermission(Role vo) {
String permissionType = getCreatePermissionType();
if (permissionType != null) {
PermissionDefinition def = ModuleRegistry.getPermissionDefinition(getCreatePermissionType());
Set<Set<Role>> roleSet = def.getPermission().getRoles();
Set<Set<Role>> newRoles = new HashSet<>();
newRoles.add(Collections.singleton(vo));
for (Set<Role> roles : roleSet) {
newRoles.add(new HashSet<>(roles));
}
Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
}
}
Aggregations