Skip to content

Commit

Permalink
Novice User Interface - Center Report Card: Support (#943)
Browse files Browse the repository at this point in the history
* Initial Prototype of Novice User Portal

* Initial Commit

* Removing unrelated files

These files belong in the `appkernels` module and have been moved there.

* Linting Cleanup

Just cleaning things up to appease the linter.

* Removing unused file

This should not have been committed.

* Removing unused code

This change is included in the appkernels module branch `novice_appkernels`.

* Unneeded code

The inclusion of these files should be via AppKernels assets.d file.

* Update classes/Rest/Controllers/SummaryControllerProvider.php

Updates per @jpwhite4 code review comments

Co-Authored-By: Joe White <jpwhite4@buffalo.edu>

* Adding a new `includePub` function parameter

This is so that we can control when `$user->getAllRoles()` includes the public
acl. The default value for all arguments has been set to `true` as that was the
behavior pre-change. This will be used in the `AppKernels` module to help filter
appropriately for the Center Report Card Portlet.

* Removing unused function

We're no longer using this function so it is being removed.

* Added missing function parameter

Was missing a parameter from the `checkDataAccess` function call.

* Re-Adding the `getResources` function

After much research and discussion w/ @jpwhite4, this function is being re-added w/ some
additional documentation && an authorization check to ensure that it is only
called for Center [Director|Staff] users. In addition, the REST endpoint that
uses this function ( in the `appkernel` module )is also being updated to require
users who request it to be Center [Director|Staff] as well.

* Updated `getResources` sql

Just needed to update the sql so that it returns data in the same format as
`MetricExplorer::getDimensionValues` as that is what `AppKernels/PerformanceMap`
is currently setup to process.
  • Loading branch information
ryanrath authored Jun 13, 2019
1 parent b3af450 commit bc90988
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 409 deletions.
12 changes: 8 additions & 4 deletions classes/DataWarehouse/Access/MetricExplorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,10 @@ public static function checkDataAccess(
$query_groupname,
$realm_name = null,
$group_by_name = null,
$statistic_name = null
$statistic_name = null,
$includePub = true
) {
$userRoles = $user->getAllRoles(true);
$userRoles = $user->getAllRoles($includePub);

$authorizedRoles = array();
foreach ($userRoles as $userRole) {
Expand Down Expand Up @@ -701,7 +702,8 @@ public static function getDimensionValues(
$offset = 0,
$limit = null,
$searchText = null,
array $selectedFilterIds = null
array $selectedFilterIds = null,
$includePub = true
) {
// Check if the realms were specified, and if not, use all realms.
$realmsSpecified = !empty($realms);
Expand Down Expand Up @@ -741,7 +743,9 @@ public static function getDimensionValues(
$user,
'tg_usage',
$realm,
$dimension_id
$dimension_id,
null,
$includePub
);
} catch (AccessDeniedException $e) {
// Only throw an exception that the user is not authorized if
Expand Down
3 changes: 1 addition & 2 deletions classes/Rest/Controllers/SummaryControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DataWarehouse\Query\Exceptions\BadRequestException;

use Models\Services\Acls;
use User\Roles;

class SummaryControllerProvider extends BaseControllerProvider
{
Expand Down Expand Up @@ -115,7 +114,7 @@ public function getPortlets(Request $request, Application $app)

$queryConfig = json_decode($query['config']);

if (!$queryConfig->featured) {
if (!isset($queryConfig->featured) || !$queryConfig->featured) {
continue;
}

Expand Down
56 changes: 56 additions & 0 deletions classes/XDUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2606,4 +2606,60 @@ public function isSticky()
{
return $this->sticky;
}

/**
* Retrieves the resources that this user has access to. Specifically, it retrieves the resources
* that are associated with this User's `organization_id`.
*
* **NOTE:** This function does not utilize the standard method of retrieving / filtering data,
* i.e. via a code path that ends up utilizing `Query.php` because we do not currently restrict
* access to resources. Also, the methods of filtering used in conjunction with `Query.php` are
* either hard coded in the `GroupBy` classes, or are indirectly setup via the `modw_filters`
* tables && the roles.json::acl::dimensions property ( via the `FilterListBuilder` class ).
*
* @param array $resourceNames [optional|default array()] an array of resourcefact.code values
* that should optionally further constrain the resources returned.
* @return integer[] an array of the resourcefact.id values
*
* @throws Exception if there is a problem connecting to / querying the database.
* @throws Exception if the user this function is called for is not a Center [Director|Staff]
*/
public function getResources($resourceNames = array())
{
// We need to make sure that this function is only called for Center [Director|Staff]
if (!$this->hasAcl(ROLE_ID_CENTER_DIRECTOR) ||
!$this->hasAcl(ROLE_ID_CENTER_STAFF)) {
throw new Exception('Unable to complete action. User is not authorized.');
}

$db = DB::factory('database');

$query = <<<SQL
SELECT rf.id,
replace(rf.code, '-', ' ') as name,
replace(rf.code, '-', ' ') as short_name
FROM modw.resourcefact rf
WHERE rf.organization_id = :organization_id
SQL;
$params = array(':organization_id' => $this->getOrganizationID());

// If we have resource names then update the query / params accordingly
if (count($resourceNames) > 0) {
$query .= "AND rf.code IN (:resource_codes)";

$handle = $db->handle();
$resourceNames = array_map(
function ($value) use ($handle) {
return $handle->quote($value);
},
$resourceNames
);
$params[':resource_codes'] = implode(
',',
$resourceNames
);
} // if (count($resourceNames) > 0) {

return $db->query($query, $params);
} // public function getResources($resourceNames = array())
}//XDUser
Loading

0 comments on commit bc90988

Please sign in to comment.