use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
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());
}
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
the class EventDao method joinPermissions.
public <R extends Record> SelectJoinStep<R> joinPermissions(SelectJoinStep<R> select, ConditionSortLimit conditions, PermissionHolder user) {
if (!permissionService.hasAdminRole(user)) {
List<Integer> roleIds = permissionService.getAllInheritedRoles(user).stream().map(r -> r.getId()).collect(Collectors.toList());
Condition roleIdsIn = MintermsRoles.MINTERMS_ROLES.roleId.in(roleIds);
Table<?> mintermsGranted = this.create.select(MintermsRoles.MINTERMS_ROLES.mintermId).from(MintermsRoles.MINTERMS_ROLES).groupBy(MintermsRoles.MINTERMS_ROLES.mintermId).having(DSL.count().eq(DSL.count(DSL.case_().when(roleIdsIn, DSL.inline(1)).else_(DSL.inline((Integer) null))))).asTable("mintermsGranted");
Table<?> permissionsGranted = this.create.selectDistinct(PermissionsMinterms.PERMISSIONS_MINTERMS.permissionId).from(PermissionsMinterms.PERMISSIONS_MINTERMS).join(mintermsGranted).on(mintermsGranted.field(MintermsRoles.MINTERMS_ROLES.mintermId).eq(PermissionsMinterms.PERMISSIONS_MINTERMS.mintermId)).asTable("permissionsGranted");
select = select.join(permissionsGranted).on(permissionsGranted.field(PermissionsMinterms.PERMISSIONS_MINTERMS.permissionId).in(table.readPermissionId));
}
return select;
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
the class AbstractBasicVOService method customizedQuery.
/**
* Query for VOs, filtering within the database is supported
* by the conditions input, if DAO does not use database filtering you must manually filter on permissions
*
* @param condition SQL conditions to restrict results
* @return list of results
*/
public List<T> customizedQuery(Condition condition) {
List<T> list = new ArrayList<>();
customizedQuery(new ConditionSortLimit(condition, null, null, null), list::add);
return list;
}
use of com.infiniteautomation.mango.db.query.ConditionSortLimit in project ma-core-public by infiniteautomation.
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 infiniteautomation.
the class AbstractBasicVOServiceWithPermissionsTestBase method testCountQueryReadPermissionEnforcement.
@Test
public void testCountQueryReadPermissionEnforcement() {
VO vo = newVO(editUser);
setReadPermission(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);
});
VO vo2 = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(editRole), vo2);
service.insert(vo2);
runAs.runAs(editUser, () -> {
ConditionSortLimit conditions = new ConditionSortLimit(null, null, null, 0);
int count = getService().customizedCount(conditions);
assertEquals(2, count);
});
}
Aggregations