aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-01-18 23:17:58 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-01-18 23:17:58 +0100
commita515de54e7d88c0d82bb9287f2a63ccdcc96b0fb (patch)
treeffea281c79cf6e2658d4ac29f4e3430ac4a36637 /apps/user_ldap/lib
parent689df9a843dd0505088143de039af775a3f92612 (diff)
downloadnextcloud-server-a515de54e7d88c0d82bb9287f2a63ccdcc96b0fb.tar.gz
nextcloud-server-a515de54e7d88c0d82bb9287f2a63ccdcc96b0fb.zip
LDAP OCS Api for delete config
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/Controller/ConfigAPIController.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php
index e136b56cda9..5a18b138c3f 100644
--- a/apps/user_ldap/lib/Controller/ConfigAPIController.php
+++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php
@@ -30,7 +30,9 @@ use OC\Security\IdentityProof\Manager;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
+use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserManager;
@@ -123,4 +125,53 @@ class ConfigAPIController extends OCSController {
}
return new DataResponse(['prefix' => $configPrefix]);
}
+
+ /**
+ * Deletes a LDAP configuration, if present.
+ *
+ * Example:
+ * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \
+ * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config/s60
+ *
+ * <?xml version="1.0"?>
+ * <ocs>
+ * <meta>
+ * <status>ok</status>
+ * <statuscode>100</statuscode>
+ * <message>OK</message>
+ * <totalitems></totalitems>
+ * <itemsperpage></itemsperpage>
+ * </meta>
+ * <data/>
+ * </ocs>
+ *
+ * @param $configID
+ * @return DataResponse
+ * @throws OCSBadRequestException
+ * @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 {
+ $prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
+ if(!in_array($configID, $prefixes)) {
+ throw new OCSNotFoundException('Config ID not found');
+ }
+ if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
+ throw new OCSException('Could not delete configuration');
+ }
+ } catch(OCSException $e) {
+ throw $e;
+ } catch(\Exception $e) {
+ $this->logger->logException($e);
+ throw new OCSException('An issue occurred when deleting the config.');
+ }
+
+ return new DataResponse();
+ }
}