LDAP OCS Api for delete config
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
689df9a843
commit
a515de54e7
|
@ -41,5 +41,6 @@ $application = new \OCP\AppFramework\App('user_ldap');
|
|||
$application->registerRoutes($this, [
|
||||
'ocs' => [
|
||||
['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'],
|
||||
['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'],
|
||||
]
|
||||
]);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,3 +5,17 @@ Feature: LDAP
|
|||
When sending "POST" to "/apps/user_ldap/api/v1/config"
|
||||
Then the OCS status code should be "100"
|
||||
And the HTTP status code should be "200"
|
||||
|
||||
Scenario: Delete a non-existing configuration
|
||||
Given As an "admin"
|
||||
When sending "DELETE" to "/apps/user_ldap/api/v1/config/s666"
|
||||
Then the OCS status code should be "404"
|
||||
And the HTTP status code should be "200"
|
||||
|
||||
Scenario: Delete an invalid configuration
|
||||
Given As an "admin"
|
||||
When sending "DELETE" to "/apps/user_ldap/api/v1/config/hack0r"
|
||||
Then the OCS status code should be "400"
|
||||
And the HTTP status code should be "200"
|
||||
|
||||
# TODO: Scenario deleting an existing config ID (needs to be created before)
|
||||
|
|
Loading…
Reference in New Issue