mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Fixed test (was a copy-paste job, hadn't been finished) and fixed to filter tables in the query method
This commit is contained in:
@ -23,6 +23,7 @@ package com.kingsrook.qqq.backend.core.model.tables;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionCheckResult;
|
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionCheckResult;
|
||||||
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionsHelper;
|
import com.kingsrook.qqq.backend.core.actions.permissions.PermissionsHelper;
|
||||||
@ -79,7 +80,18 @@ public class QQQTableCustomPossibleValueProvider extends BasicCustomPossibleValu
|
|||||||
@Override
|
@Override
|
||||||
protected List<QRecord> getAllSourceObjects() throws QException
|
protected List<QRecord> getAllSourceObjects() throws QException
|
||||||
{
|
{
|
||||||
return (QueryAction.execute(QQQTable.TABLE_NAME, null));
|
List<QRecord> records = QueryAction.execute(QQQTable.TABLE_NAME, null);
|
||||||
|
ArrayList<QRecord> rs = new ArrayList<>();
|
||||||
|
for(QRecord record : records)
|
||||||
|
{
|
||||||
|
QTableMetaData table = QContext.getQInstance().getTable(record.getValueString("name"));
|
||||||
|
if(isTableAllowed(table))
|
||||||
|
{
|
||||||
|
rs.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,8 +34,6 @@ import com.kingsrook.qqq.backend.core.model.metadata.permissions.PermissionLevel
|
|||||||
import com.kingsrook.qqq.backend.core.model.metadata.permissions.QPermissionRules;
|
import com.kingsrook.qqq.backend.core.model.metadata.permissions.QPermissionRules;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
|
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.TablesCustomPossibleValueProvider;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.TablesPossibleValueSourceMetaDataProvider;
|
|
||||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -91,9 +89,8 @@ class QQQTableCustomPossibleValueProviderTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testGetPossibleValue() throws QException
|
void testGetPossibleValue() throws QException
|
||||||
{
|
{
|
||||||
Integer personTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), TestUtils.TABLE_NAME_PERSON);
|
Integer personTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), TestUtils.TABLE_NAME_PERSON);
|
||||||
|
QQQTableCustomPossibleValueProvider provider = new QQQTableCustomPossibleValueProvider();
|
||||||
QQQTableCustomPossibleValueProvider provider = new QQQTableCustomPossibleValueProvider();
|
|
||||||
|
|
||||||
QPossibleValue<Integer> possibleValue = provider.getPossibleValue(personTableId);
|
QPossibleValue<Integer> possibleValue = provider.getPossibleValue(personTableId);
|
||||||
assertEquals(personTableId, possibleValue.getId());
|
assertEquals(personTableId, possibleValue.getId());
|
||||||
@ -119,34 +116,39 @@ class QQQTableCustomPossibleValueProviderTest extends BaseTest
|
|||||||
@Test
|
@Test
|
||||||
void testSearchPossibleValue() throws QException
|
void testSearchPossibleValue() throws QException
|
||||||
{
|
{
|
||||||
TablesCustomPossibleValueProvider provider = new TablesCustomPossibleValueProvider();
|
Integer personTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), TestUtils.TABLE_NAME_PERSON);
|
||||||
|
Integer shapeTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), TestUtils.TABLE_NAME_SHAPE);
|
||||||
|
Integer hiddenTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), "hidden");
|
||||||
|
Integer restrictedTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), "restricted");
|
||||||
|
|
||||||
List<QPossibleValue<String>> list = provider.search(new SearchPossibleValueSourceInput()
|
QQQTableCustomPossibleValueProvider provider = new QQQTableCustomPossibleValueProvider();
|
||||||
.withPossibleValueSourceName(TablesPossibleValueSourceMetaDataProvider.NAME));
|
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_PERSON));
|
List<QPossibleValue<Integer>> list = provider.search(new SearchPossibleValueSourceInput()
|
||||||
assertThat(list).noneMatch(p -> p.getId().equals("no-such-table"));
|
.withPossibleValueSourceName(QQQTable.TABLE_NAME));
|
||||||
assertThat(list).noneMatch(p -> p.getId().equals("hidden"));
|
assertThat(list).anyMatch(p -> p.getId().equals(personTableId));
|
||||||
assertThat(list).noneMatch(p -> p.getId().equals("restricted"));
|
assertThat(list).noneMatch(p -> p.getId().equals(-1));
|
||||||
|
assertThat(list).noneMatch(p -> p.getId().equals(hiddenTableId));
|
||||||
|
assertThat(list).noneMatch(p -> p.getId().equals(restrictedTableId));
|
||||||
assertNull(provider.getPossibleValue("restricted"));
|
assertNull(provider.getPossibleValue("restricted"));
|
||||||
|
|
||||||
list = provider.search(new SearchPossibleValueSourceInput()
|
list = provider.search(new SearchPossibleValueSourceInput()
|
||||||
.withPossibleValueSourceName(TablesPossibleValueSourceMetaDataProvider.NAME)
|
.withPossibleValueSourceName(QQQTable.TABLE_NAME)
|
||||||
.withIdList(List.of(TestUtils.TABLE_NAME_PERSON, TestUtils.TABLE_NAME_SHAPE, "hidden")));
|
.withIdList(List.of(personTableId, shapeTableId, hiddenTableId)));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_PERSON));
|
assertThat(list).anyMatch(p -> p.getId().equals(personTableId));
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_SHAPE));
|
assertThat(list).anyMatch(p -> p.getId().equals(shapeTableId));
|
||||||
assertThat(list).noneMatch(p -> p.getId().equals("hidden"));
|
assertThat(list).noneMatch(p -> p.getId().equals(hiddenTableId));
|
||||||
|
|
||||||
list = provider.search(new SearchPossibleValueSourceInput()
|
list = provider.search(new SearchPossibleValueSourceInput()
|
||||||
.withPossibleValueSourceName(TablesPossibleValueSourceMetaDataProvider.NAME)
|
.withPossibleValueSourceName(QQQTable.TABLE_NAME)
|
||||||
.withLabelList(List.of("Person", "Shape", "Restricted")));
|
.withLabelList(List.of("Person", "Shape", "Restricted")));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_PERSON));
|
assertThat(list).anyMatch(p -> p.getId().equals(personTableId));
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_SHAPE));
|
assertThat(list).anyMatch(p -> p.getId().equals(shapeTableId));
|
||||||
assertThat(list).noneMatch(p -> p.getId().equals("restricted"));
|
assertThat(list).noneMatch(p -> p.getId().equals(restrictedTableId));
|
||||||
|
|
||||||
list = provider.search(new SearchPossibleValueSourceInput()
|
list = provider.search(new SearchPossibleValueSourceInput()
|
||||||
.withPossibleValueSourceName(TablesPossibleValueSourceMetaDataProvider.NAME)
|
.withPossibleValueSourceName(QQQTable.TABLE_NAME)
|
||||||
.withSearchTerm("restricted"));
|
.withSearchTerm("restricted"));
|
||||||
assertEquals(0, list.size());
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
@ -155,17 +157,17 @@ class QQQTableCustomPossibleValueProviderTest extends BaseTest
|
|||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
QContext.getQSession().withPermission("restricted.hasAccess");
|
QContext.getQSession().withPermission("restricted.hasAccess");
|
||||||
list = provider.search(new SearchPossibleValueSourceInput()
|
list = provider.search(new SearchPossibleValueSourceInput()
|
||||||
.withPossibleValueSourceName(TablesPossibleValueSourceMetaDataProvider.NAME)
|
.withPossibleValueSourceName(QQQTable.TABLE_NAME)
|
||||||
.withSearchTerm("restricted"));
|
.withSearchTerm("restricted"));
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
list = provider.search(new SearchPossibleValueSourceInput()
|
list = provider.search(new SearchPossibleValueSourceInput()
|
||||||
.withPossibleValueSourceName(TablesPossibleValueSourceMetaDataProvider.NAME)
|
.withPossibleValueSourceName(QQQTable.TABLE_NAME)
|
||||||
.withLabelList(List.of("Person", "Shape", "Restricted")));
|
.withLabelList(List.of("Person", "Shape", "Restricted")));
|
||||||
assertEquals(3, list.size());
|
assertEquals(3, list.size());
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_PERSON));
|
assertThat(list).anyMatch(p -> p.getId().equals(personTableId));
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals(TestUtils.TABLE_NAME_SHAPE));
|
assertThat(list).anyMatch(p -> p.getId().equals(shapeTableId));
|
||||||
assertThat(list).anyMatch(p -> p.getId().equals("restricted"));
|
assertThat(list).anyMatch(p -> p.getId().equals(restrictedTableId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user