Skip to content
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
260 changes: 0 additions & 260 deletions classes/Models/Services/Acls.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,101 +71,6 @@ public static function getAcl($aclId)
return null;
}

/**
* Attempt to create a database representation of the provided '$acl'. Note,
* the 'aclId' property of '$acl' must not be set. If it is then an
* exception will be thrown.
*
* @param Acl $acl that will be created
* @return Acl with the $aclId populated.
* @throws Exception if the provided acls aclId is not null
*/
public static function createAcl(Acl $acl)
{
if (null != $acl->getAclId()) {
throw new Exception('acl must not have been saved.');
}

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

$query = <<<SQL
INSERT INTO acls(module_id, acl_type_id, name, display, enabled)
VALUES(:module_id, :acl_type_id, :name, :display, :enabled);
SQL;
$aclId = $db->insert($query, array(
':module_id' => $acl->getModuleId(),
':acl_type_id' => $acl->getAclTypeId(),
':name' => $acl->getName(),
':display' => $acl->getDisplay(),
':enabled' => $acl->getEnabled()
));

$acl->setAclId($aclId);

return $acl;
}

/**
* Attempt to update the database representation of the provided '$acl' such
* that the information in the database corresponds to the data in the
* object provided.
*
* @param Acl $acl to be used when updating the database table.
* @return bool true iff the number of rows updated equals 1.
* @throws Exception if the provided acl's aclId is null
*/
public static function updateAcl(Acl $acl)
{
if (null == $acl->getAclId()) {
throw new Exception('Acl must have an id to be updated.');
}

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

$query = <<<SQL
UPDATE acls a
SET
a.module_id = :module_id,
a.acl_type_id = :acl_type_id,
a.name = :name,
a.display = :display,
a.enabled = :enabled
WHERE
a.acl_id = :acl_id
SQL;
$rows = $db->execute($query, array(
':module_id' => $acl->getModuleId(),
':acl_type_id' => $acl->getAclTypeId(),
':name' => $acl->getName(),
':display' => $acl->getDisplay(),
':enabled' => $acl->getEnabled()
));

return $rows === 1;
}

/**
* Attempt to delete the acl identified by the provided '$aclId'.
*
* @param Acl $acl
* @return bool true iff the number of rows deleted = 1.
* @throws Exception if the provided acls aclId is null
*/
public static function deleteAcl(Acl $acl)
{
if (null == $acl->getAclId()) {
throw new Exception('Acl must have an id to be deleted.');
}

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

$query = "DELETE FROM acls WHERE acl_id = :acl_id";
$rows = $db->execute($query, array(
':acl_id' => $acl->getAclId()
));
return $rows === 1;
}

/**
* Retrieve a list of a user's current acls.
*
Expand Down Expand Up @@ -199,171 +104,6 @@ public static function listUserAcls(XDUser $user)
return $db->query($sql, array('user_id' => $userId));
}

/**
* Attempt to relate the provided XDUser to the Acl identified by the $aclId.
*
* @param XDUser $user the user that should have the Acl identified by the
* provided $aclId related to it.
* @param integer $aclId the unique numeric identifier for the Acl to be
* added to the provided user.
*
* @return bool true if the insert was successful else false
*
* @throws Exception if the user's userId is null
* @throws Exception if the aclId is null
*/
public static function addUserAcl(XDUser $user, $aclId)
{
if (null == $user->getUserID()) {
throw new Exception('A valid user id must be provided.');
}

if (null === $aclId) {
throw new Exception('A valid acl id must be provided.');
}
$db = DB::factory('database');
$params = array(
':user_id' => $user->getUserId(),
':acl_id' => $aclId
);
$query = <<<SQL
INSERT INTO user_acls(user_id, acl_id)
SELECT inc.*
FROM (
SELECT
:user_id as user_id,
:acl_id as acl_id
) inc
LEFT JOIN user_acls cur
ON cur.user_id = inc.user_id AND
cur.acl_id = inc.acl_id
WHERE cur.user_acl_id IS NULL;
SQL;
$rows = $db->execute($query, $params);

return $rows === 1;
}

/**
* Attempt to remove the relation between the provided user and acl.
*
* @param XDUser $user the user that will have their relation to acl
* removed.
* @param integer $aclId the unique identifier for the acl that will be removed
* from the provided user.
*
* @return boolean true if 1 or less rows were deleted as a result of this
* action.
*
* @throws Exception if the user's userId is null
* @throws Exception if the aclId is null
**/
public static function deleteUserAcl(XDUser $user, $aclId)
{
if (null == $user->getUserID()) {
throw new Exception('A valid user id must be provided.');
}
if (null === $aclId) {
throw new Exception('A valid acl id must be provided.');
}

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

$query = "DELETE FROM user_acls WHERE user_id = :user_id AND acl_id = :acl_id";
$rows = $db->execute($query, array(
':user_id' => $user->getUserId(),
':acl_id' => $aclId
));
return $rows <= 1;
}

/**
* Attempt to determine if the provided user has a relation to the acl
* identified by the provided aclId.
*
* @param XDUser $user the user checked for a relation to aclId
* @param integer $aclId the id of the acl checked for a relation to user
*
* @return boolean true if there is one or more results returned
*
* @throws Exception if the users userId is null
* @throws Exception if the aclId provided is null
*/
public static function userHasAcl(XDUser $user, $aclId)
{
if (null == $user->getUserID()) {
throw new Exception('A valid user id must be provided.');
}

if (null === $aclId) {
throw new Exception('A valid acl id must be provided.');
}
$db = DB::factory('database');

$userId = $user->getUserID();

$sql = <<<SQL
SELECT 1
FROM user_acls ua
JOIN acls a
ON a.acl_id = ua.acl_id
WHERE
ua.acl_id = :acl_id
AND ua.user_id = :user_id
AND a.enabled = TRUE
SQL;

$results = $db->query($sql, array('acl_id' => $aclId, 'user_id' => $userId));

return count($results) > 0;
}


/**
* Similar to userHasAcl but instead of checking if the user has a relation
* to a single acl, we instead check if they have a relation to each acl
* provided in the array acls.
*
* @param XDUser $user the user being interrogated for relations to the
* provided acls
* @param array $acls the array of acls being checked for a relation to
* user
*
* @return boolean true if the user has all of the provided acls
*
* @throws Exception if the provided user's userId is null
**/
public static function userHasAcls(XDUser $user, array $acls)
{
if (null === $user->getUserID()) {
throw new Exception('A valid user id must be provided.');
}
$db = DB::factory('database');
if (count($acls) < 1) {
return false;
}

$handle = $db->handle();
$userId = $user->getUserID();
$aclIds = array_reduce($acls, function ($carry, Acl $item) use ($handle) {
$carry [] = $handle->quote($item->getAclId(), PDO::PARAM_INT);
}, array());

$sql = <<<SQL
SELECT 1
FROM user_acls ua
JOIN acls a
ON a.acl_id = ua.acl_id
WHERE
ua.acl_id IN (:acl_ids)
AND ua.user_id = :user_id
AND a.enabled = TRUE
SQL;
$results = $db->query($sql, array('user_id' => $userId, 'acl_ids' => $aclIds));

return count($results) > 0;
}

/**
* Attempt to retrieve an array that will be used by the front end to disable particular
* menu options on a user by user basis.
Expand Down
40 changes: 0 additions & 40 deletions classes/XDReportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,46 +880,6 @@ public function getReportUserName($report_id)
return $results[0]['first_name'] . " " . $results[0]['last_name'];
}

public function getReportUserFirstName($report_id)
{
$results = $this->_pdo->query(
"
SELECT u.first_name
FROM Users AS u,
Reports AS r
WHERE r.user_id = :user_id
AND r.report_id = :report_id
AND r.user_id = u.id
",
array(
'user_id' => $this->_user_id,
'report_id' => $report_id,
)
);

return $results[0]['first_name'];
}

public function getReportUserLastName($report_id)
{
$results = $this->_pdo->query(
"
SELECT u.last_name
FROM Users AS u,
Reports AS r
WHERE r.user_id = :user_id
AND r.report_id = :report_id
AND r.user_id = u.id
",
array(
'user_id' => $this->_user_id,
'report_id' => $report_id,
)
);

return $results[0]['last_name'];
}

public function getReportUserEmailAddress($report_id)
{
$results = $this->_pdo->query(
Expand Down
20 changes: 0 additions & 20 deletions html/internal_dashboard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,6 @@ function (&$v) {
</script>

<script type="text/javascript" src="js/dashboard.js"></script>

<?php /* App Kernel code. */ ?>
<?php if (xd_utilities\getConfiguration('features', 'appkernels') == 'on'): ?>
<?php
if(isset($_GET['op']))
{
if($_GET['op']=='ak_instance')
{
$instance_id=$_GET['instance_id'];
echo <<< END
<script type="text/javascript">
Ext.onReady(function () {
new XDMoD.AppKernel.InstanceWindow({instanceId:$instance_id}).show();
}, window, true);
</script>
END;
}
}
?>
<?php endif; ?>
</head>
<body></body>
</html>