Skip to content

Commit

Permalink
Less infinite loops (#840)
Browse files Browse the repository at this point in the history
* Less infinite loops

So now that we have a class that handles the merging + extends resolving (
`XdmodConfiguration` ) we no longer need to rely on `Roles::getConfig`.

Usage of this function was replaced in:
  - Tabs.php@58
  - summary3.php@68,75

The one bit of functionality we lose by doing this is that, when a section
cannot be found we no longer attempt to look it up in the `default` acl.

To account for this, it was necessary to add a `summary_charts` section to the
`pub` acl. Which in turn required that this data be added to the expected
output in `artifacts/xdmod/acls/output/roles.json`.

* Removing unused `use` statements

* Reverting roles.json and accounting for that in summary3

So instead of adding additional data to the pub acl we can instead implement the
implicit `default` extension in summary3. This means we don't have to migrate
any configuration files, Hoooray!

This change is per a conversation w/ @jpwhite4 where he talked some sense into
me.

* Updating expected test data

Updated the expected test data so that `pub` no longer has `summary_charts`

* Updating XdmodConfiguration usage w/ `assocArrayFactory`

Just removing boilerplate and replacing it w/
`XdmodConfiguration::assocArrayFactory`.

* Simplifying

* derrr
  • Loading branch information
ryanrath authored Mar 7, 2019
1 parent b25e2b1 commit 0185b09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 42 deletions.
13 changes: 5 additions & 8 deletions classes/Models/Services/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Models\Services;

use CCR\DB;
use User\Roles;
use Configuration\XdmodConfiguration;

class Tabs
{
Expand Down Expand Up @@ -58,14 +58,11 @@ public static function getTabs(\XDUser $user)
':acl_hierarchy_name' => self::DEFAULT_ACL_HIERARCHY
));

$sections = array('display', 'type', 'permitted_modules', 'query_descripters', 'summary_charts');
$acls = array();
$aclConfig = XdmodConfiguration::assocArrayFactory('roles.json', CONFIG_DIR);
$acls = $aclConfig['roles'];

$roleNames = Roles::getRoleNames(array('default'));
foreach ($roleNames as $roleName) {
foreach ($sections as $section) {
$acls[$roleName][$section] = Roles::getConfig($roleName, $section);
}
if (isset($acls['default'])) {
unset($acls['default']);
}

foreach ($rows as $row) {
Expand Down
33 changes: 0 additions & 33 deletions classes/User/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,6 @@ function ($item) use ($blacklist) {
);
}

/**
* Attempt to retrieve the values located in roles.json
* or roles.d/<module>.json that correspond to the provided identifier
* and optional section.
*
* @param string $identifier the first level of information to retrieve
* @param string $section an optional second level of information
*
* @return mixed
*
* @throws \Exception if unable to find data for $identifier.
* @throws \Exception if there is a problem reading / processing the underlying `roles.json`
* configuration data
*/
public static function getConfig($identifier, $section = null)
{
foreach(self::getConfigData() as $key => $data) {
if ($key === $identifier) {
if ($section === null) {
return $data;
} elseif (array_key_exists($section, $data)) {
return $data[$section];
} else {
// If the section is not found then we fall back to the `default` section,
// regardless of whether or not the $identifier actually extends default.
return self::getConfig('default', $section);
}
}
}

throw new \Exception("Unknown role '$identifier'");
}

/**
* Retrieve the 'roles' configuration data. This will include any information provided in the
* `roles.d` local configuration folder in addition to the processing of any `extends`
Expand Down
13 changes: 12 additions & 1 deletion html/controllers/ui_data/summary3.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,25 @@
}
}
$mostPrivilegedAcl = Acls::getMostPrivilegedAcl($logged_in_user);

$rolesConfig = \Configuration\XdmodConfiguration::assocArrayFactory('roles.json', CONFIG_DIR);
$roles = $rolesConfig['roles'];

$mostPrivilegedAclName = $mostPrivilegedAcl->getName();
$mostPrivilegedAclSummaryCharts = $roles['default']['summary_charts'];

if (isset($roles[$mostPrivilegedAclName]['summary_charts'])) {
$mostPrivilegedAclSummaryCharts = $roles[$mostPrivilegedAclName]['summary_charts'];
}

$summaryCharts = array_map(
function ($chart) {
if (!isset($chart['preset'])) {
$chart['preset'] = true;
}
return json_encode($chart);
},
Roles::getConfig($mostPrivilegedAcl->getName(), 'summary_charts')
$mostPrivilegedAclSummaryCharts
);

foreach ($summaryCharts as $i => $summaryChart) {
Expand Down

0 comments on commit 0185b09

Please sign in to comment.