use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by MangoAutomation.
the class EventInstanceServiceTest method testQueryReadPermissionEnforcement.
@Override
@Test
public void testQueryReadPermissionEnforcement() {
EventInstanceVO vo = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(editRole), vo);
EventInstanceVO saved = service.insert(vo);
runAs.runAs(readUser, () -> {
ConditionSortLimit conditions = new ConditionSortLimit(null, null, 1, 0);
AtomicInteger count = new AtomicInteger();
getService().customizedQuery(conditions, (item) -> {
count.getAndIncrement();
});
assertEquals(0, count.get());
});
runAs.runAs(editUser, () -> {
Condition c = getDao().getIdField().eq(saved.getId());
ConditionSortLimit conditions = new ConditionSortLimit(c, null, null, null);
AtomicInteger count = new AtomicInteger();
getService().customizedQuery(conditions, (item) -> {
count.getAndIncrement();
assertEquals(saved.getId(), item.getId());
});
assertEquals(1, count.get());
});
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by MangoAutomation.
the class AbstractVOServiceWithPermissionsTest method countForName.
public int countForName(String name) {
Condition c = getDao().getNameField().eq(name);
ConditionSortLimit conditions = new ConditionSortLimit(c, null, null, 0);
return getService().customizedCount(conditions);
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by MangoAutomation.
the class AbstractBasicVOServiceWithPermissionsTestBase method testCountQueryEditPermissionEnforcement.
@Test
public void testCountQueryEditPermissionEnforcement() {
VO vo = newVO(readUser);
setEditPermission(MangoPermission.requireAnyRole(editRole), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
ConditionSortLimit conditions = new ConditionSortLimit(null, null, null, 0);
int count = getService().customizedCount(conditions);
assertEquals(0, count);
});
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by MangoAutomation.
the class FileStoreService method getStores.
/**
* List all file-stores that the user has read permission for
*/
public List<FileStore> getStores() {
List<FileStore> stores = new ArrayList<>();
this.customizedQuery(new ConditionSortLimit(null, null, null, null), (item) -> stores.add(item));
PermissionHolder user = Common.getUser();
Collection<FileStoreDefinition> moduleDefs = ModuleRegistry.getFileStoreDefinitions().values();
for (FileStoreDefinition def : moduleDefs) {
if (this.permissionService.hasPermission(user, def.getReadPermission())) {
stores.add(def.toFileStore());
}
}
return stores;
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by MangoAutomation.
the class DataPointTagsDao method getTagValuesForKey.
public Set<String> getTagValuesForKey(String tagKey, PermissionHolder user) {
SelectJoinStep<Record1<String>> query = this.create.selectDistinct(table.tagValue).from(table);
SelectConditionStep<Record1<String>> conditional;
if (!permissionService.hasAdminRole(user)) {
query = query.join(dataPointTable).on(table.dataPointId.eq(dataPointTable.id));
ConditionSortLimit csl = new ConditionSortLimit(table.tagKey.eq(tagKey), null, null, null);
query = DataPointDao.getInstance().joinPermissions(query, user);
conditional = query.where(csl.getCondition());
} else {
conditional = query.where(table.tagKey.eq(tagKey));
}
try (Stream<Record1<String>> stream = conditional.stream()) {
return stream.map(Record1::value1).collect(Collectors.toSet());
}
}
Aggregations