Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Query Descriptor Visibility #911

Merged
merged 9 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions bin/acl-config
Original file line number Diff line number Diff line change
Expand Up @@ -1599,37 +1599,39 @@ SQL;
foreach ($queryDescriptors as $queryDescriptor) {

$realm = isset($queryDescriptor['realm']) ? $queryDescriptor['realm'] : null;
$groupBy = isset($queryDescriptor['group_by']) ? $queryDescriptor['group_by'] : null;
$disable = isset($queryDescriptor['disable']) ? $queryDescriptor['disable'] : false;

// if we can't find the current realm in the array of available realms
// then just ignore this entry. This is due to the way in which we
// process modules / how the data is represented and is expected.
if (!array_key_exists($realm, $realms)) {
continue;
}

$groupBy = isset($queryDescriptor['group_by']) ? $queryDescriptor['group_by'] : null;
$disable = isset($queryDescriptor['disable']) ? $queryDescriptor['disable'] : false;
$hide = isset($queryDescriptor['hide']) ? $queryDescriptor['hide'] : null;

$realmData = $realms[$realm];
if (!isset($realmData['statistics'])) {
$log->warning("No statistics found for realm $realm. Skipping Query Descriptor for [ $module, $acl, $groupBy ]");
continue;
}
$statistics = $realmData['statistics'];

$statistics = $realmData['statistics'];
foreach ($statistics as $statistic) {

$statisticName = isset($statistic['name']) ? $statistic['name'] : null;
$hide = isset($statistic['hide']) ? $statistic['hide'] : null;
$visible = isset($statistic['visible']) ? $statistic['visible'] : null;

$enabled = null !== $disable ? !$disable : true;

if ($visible === null && $hide !== null) {
$visible = !$hide;
// By default, an entry will be shown.
// If the statistic defines a $visible value, then prefer that.
// Else, if the query descriptor has a hide value, use that.
$shown = true;
if (isset($visible)) {
$shown = $visible;
} elseif (!isset($visible) && isset($hide)) {
$shown = !$hide;
}

$visible = $visible !== null ? $visible : true;

$realmName = strtolower($realm);

$id = "[ $module, $realmName, $acl, $groupBy, $statisticName ]";
Expand All @@ -1640,8 +1642,8 @@ SQL;
':acl_name' => $acl,
':group_by_name' => $groupBy,
':statistic_name' => $statisticName,
':visible' => ( $visible ? 1 : 0 ),
':enabled' => ( $enabled ? 1 : 0 )
':visible' => ( $shown ? 1 : 0 ),
':enabled' => ( !$disable ? 1 : 0 )
);

$log->debug(json_encode($params));
Expand Down
30 changes: 12 additions & 18 deletions classes/Models/Services/Acls.php
Original file line number Diff line number Diff line change
Expand Up @@ -974,26 +974,20 @@ public static function getAclsByTypeName($aclTypeName)
*/
public static function getQueryDescripters(XDUser $user, $realmName = null, $groupByName = null, $statisticName = null)
{
$selectClauses = array(
'r.display as realm',
'gb.name as group_by',
'!agb.enabled as not_enabled'
);

if (isset($statisticName)) {
$selectClauses[] = 'agb.visible';
// This can be removed after we refactor the tables to support more general disabling / hiding.
// The reason it's here is that unless we are specifically filtering on a statistic, having the
// sem* statistics included messes up the results. Specifically, we get duplicate rows
$statisticWhere = '';
if ($statisticName === null) {
$statisticWhere = "\nAND s.name NOT LIKE 'sem%'";
}

// Note: this type of dynamic sql is safe as we're not including any user defined input
// in the sql itself.
$selectClause = implode(
",\n",
$selectClauses
);

$query = <<<SQL
SELECT DISTINCT
$selectClause
r.display as realm,
gb.name as group_by,
!agb.enabled as not_enabled,
agb.visible
FROM group_bys gb
JOIN realms r ON gb.realm_id = r.realm_id
JOIN acl_group_bys agb
Expand Down Expand Up @@ -1038,7 +1032,7 @@ public static function getQueryDescripters(XDUser $user, $realmName = null, $gro
ua3.user_id = :user_id AND
at.name = 'data'
)
WHERE ua.user_id = :user_id
WHERE ua.user_id = :user_id $statisticWhere
SQL;

$params = array(
Expand Down Expand Up @@ -1076,10 +1070,10 @@ public static function getQueryDescripters(XDUser $user, $realmName = null, $gro
);

$descripter->setDisableMenu((bool)$row['not_enabled']);
$descripter->setShowMenu((bool)$row['visible']);

if (isset($statisticName)) {
$descripter->setDefaultStatisticName($statisticName);
$descripter->setShowMenu((bool)$row['visible']);
}

// NOTE: this is done so that the GroupByNone query descripter does not have it's
Expand Down
89 changes: 44 additions & 45 deletions html/controllers/user_interface/get_menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,53 +93,52 @@
$user,
$realm_name
);
foreach($query_descripter_groups as $groupBy => $queryDescriptorData) {
$queryDescriptor = $queryDescriptorData['all'];

foreach($query_descripter_groups as $realm => $query_descripter_group) {
foreach($query_descripter_group as $query_descripter) {
if ($query_descripter->getShowMenu() !== true) {
continue;
}

$nodeId = (
'group_by_'
. $categoryName
. '_'
. $query_descripter->getGroupByName()
);

// Make sure that the nodeText, derived from the query descripters menu
// label, has each instance of $realm_name replaced with $categoryName.
$nodeText = preg_replace(
'/' . preg_quote($realm_name, '/') . '/',
$categoryName,
$query_descripter->getMenuLabel()
);

// If this $nodeId has been seen before but for a different realm. Update
// the list of realms associated with this $nodeId
$nodeRealms = (
isset($categoryReturnData[$nodeId])
? $categoryReturnData[$nodeId]['realm'] . ",${realm_name}"
: $realm_name
);

$categoryReturnData[$nodeId] = array(
'text' => $nodeText,
'id' => $nodeId,
'group_by' => $query_descripter->getGroupByName(),
'query_group' => $query_group_name,
'category' => $categoryName,
'realm' => $nodeRealms,
'defaultChartSettings' => $query_descripter->getChartSettings(true),
'chartSettings' => $query_descripter->getChartSettings(true),
'node_type' => 'group_by',
'iconCls' => 'menu',
'description' => $query_descripter->getGroupByLabel(),
'leaf' => false
);

$hasItems = true;
if ($queryDescriptor->getShowMenu() !== true) {
continue;
}

$nodeId = (
'group_by_'
. $categoryName
. '_'
. $queryDescriptor->getGroupByName()
);

// Make sure that the nodeText, derived from the query descripters menu
// label, has each instance of $realm_name replaced with $categoryName.
$nodeText = preg_replace(
'/' . preg_quote($realm_name, '/') . '/',
$categoryName,
$queryDescriptor->getMenuLabel()
);

// If this $nodeId has been seen before but for a different realm. Update
// the list of realms associated with this $nodeId
$nodeRealms = (
isset($categoryReturnData[$nodeId])
? $categoryReturnData[$nodeId]['realm'] . ",${realm_name}"
: $realm_name
);

$categoryReturnData[$nodeId] = array(
'text' => $nodeText,
'id' => $nodeId,
'group_by' => $queryDescriptor->getGroupByName(),
'query_group' => $query_group_name,
'category' => $categoryName,
'realm' => $nodeRealms,
'defaultChartSettings' => $queryDescriptor->getChartSettings(true),
'chartSettings' => $queryDescriptor->getChartSettings(true),
'node_type' => 'group_by',
'iconCls' => 'menu',
'description' => $queryDescriptor->getGroupByLabel(),
'leaf' => false
);

$hasItems = true;
}
}

Expand Down
32 changes: 32 additions & 0 deletions tests/artifacts/xdmod/acls/input/get_disabled_menus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
[
{
"username": "Public User",
"realm": "Jobs"
}
],
[
{
"username": "centerdirector",
"realm": "Jobs"
}
],
[
{
"username": "centerstaff",
"realm": "Jobs"
}
],
[
{
"username": "principal",
"realm": "Jobs"
}
],
[
{
"username": "normaluser",
"realm": "Jobs"
}
]
]
Loading