mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Merged feature/CE-1654-warehouse-security-key-all-access-left-join into dev
This commit is contained in:
@ -82,7 +82,7 @@ public class JoinsContext
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// we will get a TON of more output if this gets turned up, so be cautious //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private Level logLevel = Level.OFF;
|
||||
private Level logLevel = Level.OFF;
|
||||
private Level logLevelForFilter = Level.OFF;
|
||||
|
||||
|
||||
@ -404,6 +404,12 @@ public class JoinsContext
|
||||
chainIsInner = false;
|
||||
}
|
||||
|
||||
if(hasAllAccessKey(recordSecurityLock))
|
||||
{
|
||||
queryJoin.withType(QueryJoin.Type.LEFT);
|
||||
chainIsInner = false;
|
||||
}
|
||||
|
||||
addQueryJoin(queryJoin, "forRecordSecurityLock (non-flipped)", "- ");
|
||||
addedQueryJoins.add(queryJoin);
|
||||
tmpTable = instance.getTable(join.getRightTable());
|
||||
@ -423,6 +429,12 @@ public class JoinsContext
|
||||
chainIsInner = false;
|
||||
}
|
||||
|
||||
if(hasAllAccessKey(recordSecurityLock))
|
||||
{
|
||||
queryJoin.withType(QueryJoin.Type.LEFT);
|
||||
chainIsInner = false;
|
||||
}
|
||||
|
||||
addQueryJoin(queryJoin, "forRecordSecurityLock (flipped)", "- ");
|
||||
addedQueryJoins.add(queryJoin);
|
||||
tmpTable = instance.getTable(join.getLeftTable());
|
||||
@ -456,44 +468,53 @@ public class JoinsContext
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
private boolean hasAllAccessKey(RecordSecurityLock recordSecurityLock)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// check if the key type has an all-access key, and if so, if it's set to true for the current user/session //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QSecurityKeyType securityKeyType = instance.getSecurityKeyType(recordSecurityLock.getSecurityKeyType());
|
||||
if(StringUtils.hasContent(securityKeyType.getAllAccessKeyName()))
|
||||
{
|
||||
QSession session = QContext.getQSession();
|
||||
if(session.hasSecurityKeyValue(securityKeyType.getAllAccessKeyName(), true, QFieldType.BOOLEAN))
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void addSubFilterForRecordSecurityLock(RecordSecurityLock recordSecurityLock, QTableMetaData table, String tableNameOrAlias, boolean isOuter, QueryJoin sourceQueryJoin)
|
||||
{
|
||||
QSession session = QContext.getQSession();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// check if the key type has an all-access key, and if so, if it's set to true for the current user/session //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QSecurityKeyType securityKeyType = instance.getSecurityKeyType(recordSecurityLock.getSecurityKeyType());
|
||||
boolean haveAllAccessKey = false;
|
||||
if(StringUtils.hasContent(securityKeyType.getAllAccessKeyName()))
|
||||
boolean haveAllAccessKey = hasAllAccessKey(recordSecurityLock);
|
||||
if(haveAllAccessKey)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// if we have all-access on this key, then we don't need a criterion for it (as long as we're in an AND filter) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if(session.hasSecurityKeyValue(securityKeyType.getAllAccessKeyName(), true, QFieldType.BOOLEAN))
|
||||
if(sourceQueryJoin != null)
|
||||
{
|
||||
haveAllAccessKey = true;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// in case the queryJoin object is re-used between queries, and its security criteria need to be different (!!), reset it //
|
||||
// this can be exposed in tests - maybe not entirely expected in real-world, but seems safe enough //
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sourceQueryJoin.withSecurityCriteria(new ArrayList<>());
|
||||
}
|
||||
|
||||
if(sourceQueryJoin != null)
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// in case the queryJoin object is re-used between queries, and its security criteria need to be different (!!), reset it //
|
||||
// this can be exposed in tests - maybe not entirely expected in real-world, but seems safe enough //
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sourceQueryJoin.withSecurityCriteria(new ArrayList<>());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// if we're in an AND filter, then we don't need a criteria for this lock, so return. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
boolean inAnAndFilter = securityFilterCursor.getBooleanOperator() == QQueryFilter.BooleanOperator.AND;
|
||||
if(inAnAndFilter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// if we're in an AND filter, then we don't need a criteria for this lock, so return. //
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
boolean inAnAndFilter = securityFilterCursor.getBooleanOperator() == QQueryFilter.BooleanOperator.AND;
|
||||
if(inAnAndFilter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,7 +566,7 @@ public class JoinsContext
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Serializable> securityKeyValues = session.getSecurityKeyValues(recordSecurityLock.getSecurityKeyType(), type);
|
||||
List<Serializable> securityKeyValues = QContext.getQSession().getSecurityKeyValues(recordSecurityLock.getSecurityKeyType(), type);
|
||||
if(CollectionUtils.nullSafeIsEmpty(securityKeyValues))
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user