Skip to content

Commit

Permalink
Changes to enable reactivating disabled key permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
JaseMK committed Feb 17, 2022
1 parent c2bd265 commit 28b7c7a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/Repository/MKDFKeysRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,57 @@ public function removeKeyUUIDPermission($key_uuid, $dataset_id) {
return true;
}

/*
* DISABLED key permissions remember their original state by becoming an uppercase version of
* their original self. ie a->A r->R w->W
* Restoring original permissions is a case of checking that the current permission is in
* disabled state and converting it to lower case.
*/
public function restoreKeyPermission($keyId, $datasetId) {
$statement = $this->_adapter->createStatement($this->getQuery('findPermission'));
$result = $statement->execute(['dataset_id'=>$datasetId, 'key_id'=>$keyId]);
$found = false;
$existingPermission = null;
if ($result instanceof ResultInterface && $result->isQueryResult()) {
$resultSet = new ResultSet;
$resultSet->initialize($result);
if (count($resultSet) > 0){
$found = true;
$currentResult = $result->current();
$existingPermission = $currentResult['permission'];
}
}
if ($found && (ctype_upper($existingPermission))) {
$newPermission = strtolower($existingPermission);
$this->setKeyPermission($keyId, $datasetId, $newPermission);
return $newPermission;
}
else {
throw new \Exception("Attempted reactive a key that wasn't disabled");
}
}

public function setKeyPermission($keyId, $datasetId, $permission) {
//First check if the key/dataset pairing exists
$statement = $this->_adapter->createStatement($this->getQuery('findPermission'));
$result = $statement->execute(['dataset_id'=>$datasetId, 'key_id'=>$keyId]);
$found = false;
$existingPermission = null;
if ($result instanceof ResultInterface && $result->isQueryResult()) {
$resultSet = new ResultSet;
$resultSet->initialize($result);
if (count($resultSet) > 0){
$found = true;
$currentResult = $result->current();
$existingPermission = $currentResult['permission'];
}
}
//Then either create or amend a key/dataset pairing
if ($found){
//update the permission entry
if ((!is_null($existingPermission)) && ($permission == 'd')) {
$permission = strtoupper($existingPermission);
}
$statement = $this->_adapter->createStatement($this->getQuery('updatePermission'));
$statement->execute(['dataset_id'=>$datasetId, 'key_id'=>$keyId, 'permission'=>$permission]);
}
Expand Down
5 changes: 4 additions & 1 deletion view/mkdf/keys/key/details.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</tr>
<?php foreach ($datasets as $dataset) : ?>
<?php
if ($dataset['permission'] =='d'){
if ($dataset['permission'] =='d' || (ctype_upper($dataset['permission']))){
print('<tr class="table-secondary">');
}
else {
Expand Down Expand Up @@ -80,6 +80,9 @@
echo "Write";
break;
case 'd':
case 'A':
case 'R':
case 'W':
echo "Disabled";
break;
default:
Expand Down

0 comments on commit 28b7c7a

Please sign in to comment.