Skip to content

Commit

Permalink
fix deletion for configIDs < s10
Browse files Browse the repository at this point in the history
Also move ensureConfigIDExists checks into try, it might throw DB
related exceptions

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jan 20, 2017
1 parent 9ca4065 commit 91ed70f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions apps/user_ldap/lib/Controller/ConfigAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ public function create() {
* @throws OCSException
*/
public function delete($configID) {
$initial = substr($configID, 0, 1);
$number = substr($configID, 1);
if($initial !== 's' || $number !== strval(intval($number))) {
throw new OCSBadRequestException('Not a valid config ID');
}

try {
$this->ensureConfigIDExists($configID);
if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
Expand Down Expand Up @@ -190,13 +184,13 @@ public function delete($configID) {
* @throws OCSException
*/
public function modify($configID, $configData) {
$this->ensureConfigIDExists($configID);
try {
$this->ensureConfigIDExists($configID);

if(!is_array($configData)) {
throw new OCSBadRequestException('configData is not properly set');
}
if(!is_array($configData)) {
throw new OCSBadRequestException('configData is not properly set');
}

try {
$configuration = new Configuration($configID);
$configKeys = $configuration->getConfigTranslationArray();

Expand All @@ -207,6 +201,8 @@ public function modify($configID, $configData) {
}

$configuration->saveConfiguration();
} catch(OCSException $e) {
throw $e;
} catch (\Exception $e) {
$this->logger->logException($e);
throw new OCSException('An issue occurred when modifying the config.');
Expand Down Expand Up @@ -287,9 +283,9 @@ public function modify($configID, $configData) {
* @throws OCSException
*/
public function show($configID, $showPassword = false) {
$this->ensureConfigIDExists($configID);

try {
$this->ensureConfigIDExists($configID);

$config = new Configuration($configID);
$data = $config->getConfiguration();
if(!boolval(intval($showPassword))) {
Expand All @@ -301,6 +297,8 @@ public function show($configID, $showPassword = false) {
$data[$key] = $value;
}
}
} catch(OCSException $e) {
throw $e;
} catch (\Exception $e) {
$this->logger->logException($e);
throw new OCSException('An issue occurred when modifying the config.');
Expand All @@ -317,7 +315,7 @@ public function show($configID, $showPassword = false) {
*/
private function ensureConfigIDExists($configID) {
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
if(!in_array($configID, $prefixes)) {
if(!in_array($configID, $prefixes, true)) {
throw new OCSNotFoundException('Config ID not found');
}
}
Expand Down

0 comments on commit 91ed70f

Please sign in to comment.