use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class DataPointDwr method dojoQuery.
/**
* Load a list of VOs
*
* Overridden to provide security
*
* @return
*/
@Override
@DwrPermission(user = true)
public ProcessResult dojoQuery(Map<String, String> query, List<SortOption> sort, Integer start, Integer count, boolean or) {
ProcessResult response = new ProcessResult();
ResultsWithTotal results = dao.dojoQuery(query, sort, start, count, or);
List<DataPointVO> vos = new ArrayList<>();
@SuppressWarnings("unchecked") List<DataPointVO> filteredPoints = (List<DataPointVO>) results.getResults();
// Filter list on User Permissions
User user = Common.getUser();
for (DataPointVO vo : filteredPoints) {
if (Permissions.hasDataSourcePermission(user, vo.getDataSourceId())) {
// .hasDataPointReadPermission(user, vo)) {
vos.add(vo);
}
}
// Since we have removed some, we need to review our totals here,,
// this will be a bit buggy because we don't know how many of the remaining items
// are actually viewable by this user.
int total = results.getTotal() - (filteredPoints.size() - vos.size());
response.addData("list", vos);
response.addData("total", total);
return response;
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class DataSourceDwr method getNew.
@DwrPermission(user = true)
public ProcessResult getNew(String type) {
ProcessResult response = new ProcessResult();
DataSourceVO<?> vo = null;
DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition(type);
if (def == null) {
// TODO Add message to response about unknown type or invalid type
} else {
try {
vo = def.baseCreateDataSourceVO();
vo.setId(Common.NEW_ID);
vo.setXid(DataSourceDao.instance.generateUniqueXid());
User user = Common.getUser();
if (!Permissions.hasAdmin(user))
// Default the permissions of the data source to that of the user so that
// the user can access the thing.
vo.setEditPermission(Common.getUser().getPermissions());
response.addData("vo", vo);
// Setup the page info
response.addData("editPagePath", def.getModule().getWebPath() + "/" + def.getEditPagePath());
response.addData("statusPagePath", def.getModule().getWebPath() + "/" + def.getStatusPagePath());
} catch (Exception e) {
LOG.error(e.getMessage());
response.addMessage(new TranslatableMessage("table.error.dwr", e.getMessage()));
}
}
return response;
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class DataSourceDwr method dojoQuery.
/**
* Load a list of VOs
*
* Overridden to provide security
*
* @return
*/
@Override
@DwrPermission(user = true)
public ProcessResult dojoQuery(Map<String, String> query, List<SortOption> sort, Integer start, Integer count, boolean or) {
ProcessResult response = new ProcessResult();
ResultsWithTotal results = dao.dojoQuery(query, sort, start, count, or);
List<DataSourceVO<?>> vos = new ArrayList<>();
@SuppressWarnings("unchecked") List<DataSourceVO<?>> filtered = (List<DataSourceVO<?>>) results.getResults();
// Filter list on User Permissions
User user = Common.getUser();
for (DataSourceVO<?> vo : filtered) {
if (Permissions.hasDataSourcePermission(user, vo))
vos.add(vo);
}
// Since we have removed some, we need to review our totals here,,
// this will be a bit buggy because we don't know how many of the remaining items
// are actually viewable by this user.
int total = results.getTotal() - (filtered.size() - vos.size());
response.addData("list", vos);
response.addData("total", total);
return response;
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class DataSourceDwr method jsonExportUsingFilter.
/**
* Export VOs based on a filter
*
* @param id
* @return
*/
@SuppressWarnings("unchecked")
@DwrPermission(user = true)
public String jsonExportUsingFilter(Map<String, String> query, List<SortOption> sort, Integer start, Integer count, boolean or) {
Map<String, Object> data = new LinkedHashMap<>();
List<DataSourceVO<?>> vos = new ArrayList<>();
ResultsWithTotal results = dao.dojoQuery(query, sort, start, count, or);
List<DataSourceVO<?>> filtered = (List<DataSourceVO<?>>) results.getResults();
// Filter list on User Permissions
User user = Common.getUser();
for (DataSourceVO<?> vo : filtered) {
if (Permissions.hasDataSourcePermission(user, vo)) {
vos.add(vo);
// Not doing this yet, might look weird to user
// data.put(EmportDwr.DATA_POINTS, DataPointDao.instance.getDataPoints(vo.getId(), null));
}
}
// Get the Full VO for the export
data.put(keyName, vos);
return EmportDwr.export(data, 3);
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class EventHandlersDwr method saveEmailEventHandler.
@DwrPermission(user = true)
public ProcessResult saveEmailEventHandler(String eventType, String eventSubtype, int eventTypeRef1, int eventTypeRef2, int handlerId, String xid, String alias, boolean disabled, List<RecipientListEntryBean> activeRecipients, String customTemplate, boolean sendEscalation, boolean repeatEscalations, int escalationDelayType, int escalationDelay, List<RecipientListEntryBean> escalationRecipients, boolean sendInactive, boolean inactiveOverride, List<RecipientListEntryBean> inactiveRecipients, boolean includeSystemInfo, int includePointValueCount, boolean includeLogfile, List<IntStringPair> additionalContext, ScriptPermissions permissions, String script) {
EmailEventHandlerVO handler = new EmailEventHandlerVO();
handler.setDefinition(ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME));
handler.setActiveRecipients(activeRecipients);
handler.setCustomTemplate(customTemplate);
handler.setSendEscalation(sendEscalation);
handler.setRepeatEscalations(repeatEscalations);
handler.setEscalationDelayType(escalationDelayType);
handler.setEscalationDelay(escalationDelay);
handler.setEscalationRecipients(escalationRecipients);
handler.setSendInactive(sendInactive);
handler.setInactiveOverride(inactiveOverride);
handler.setInactiveRecipients(inactiveRecipients);
handler.setIncludeSystemInfo(includeSystemInfo);
handler.setIncludePointValueCount(includePointValueCount);
handler.setIncludeLogfile(includeLogfile);
handler.setAdditionalContext(additionalContext);
handler.setScriptPermissions(permissions);
handler.setScript(script);
return save(eventType, eventSubtype, eventTypeRef1, eventTypeRef2, handler, handlerId, xid, alias, disabled);
}
Aggregations