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

Improve the accesss denied error message. #159

Merged
merged 3 commits into from
Jun 14, 2017
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 classes/DataWarehouse/Query/Exceptions/AccessDeniedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
*/
class AccessDeniedException extends QueryException
{
/**
* The message used by this exception if none is provided.
*/
const defaultMessage = 'The role to which you are assigned does not have access to the information you requested.';
/**
* The message used by this exception if none is provided.
*/
const DEFAULT_MESSAGE = <<<EOF
Your user account does not have permission to view the requested data. If you
believe that you should be able to see this information, then please select
"Submit Support Request" in the "Contact Us" menu to request access.
EOF;

/**
/**
* The code used by this exception if none is provided.
*/
const defaultCode = \XDError::QueryAccessDenied;
const DEFAULT_CODE = \XDError::QueryAccessDenied;

public function __construct($message = self::defaultMessage, $code = self::defaultCode, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
public function __construct($message = self::DEFAULT_MESSAGE, $code = self::DEFAULT_CODE, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);

$this->httpCode = 403;
}
$this->httpCode = 403;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,35 @@ public function testGetTabs()
$this->assertTrue(count($tabdata) > 0);
}
}

/*
* Check that the System Username plots are not available to the public user
*/
public function testSystemUsernameAccess()
{
$defaultJson = <<<EOF
{
"public_user": "true",
"realm": "Jobs",
"group_by": "username",
"statistic": "job_count",
"start_date": "2017-05-01",
"end_date": "2017-05-31",
"operation": "get_charts",
"controller_module": "user_interface"
}
EOF;

$response = $this->helper->post('/controllers/user_interface.php', null, json_decode($defaultJson, true));

$expectedErrorMessage = <<<EOF
Your user account does not have permission to view the requested data. If you
believe that you should be able to see this information, then please select
"Submit Support Request" in the "Contact Us" menu to request access.
EOF;

$this->assertEquals($response[1]['content_type'], 'application/json');
$this->assertEquals($response[1]['http_code'], 403);
$this->assertEquals($response[0]['message'], $expectedErrorMessage);
}
}