diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-01-19 11:09:04 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-01-19 11:09:04 +0100 |
commit | 01d469dfea5c3a3db4ddd449b322f3f9f5ae98b9 (patch) | |
tree | 6159aedc9f7feba01dd3d503ff61605ee2a83708 /apps/user_ldap/lib | |
parent | 18a75bec0d87b847790e0c5b695e3d02993ca710 (diff) | |
download | nextcloud-server-01d469dfea5c3a3db4ddd449b322f3f9f5ae98b9.tar.gz nextcloud-server-01d469dfea5c3a3db4ddd449b322f3f9f5ae98b9.zip |
add LDAP OCS Api for modifying a configuration
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.php | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index bfdce302af5..8aeb771608d 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -145,7 +145,7 @@ class ConfigAPIController extends OCSController { * <data/> * </ocs> * - * @param $configID + * @param string $configID * @return DataResponse * @throws OCSBadRequestException * @throws OCSException @@ -158,10 +158,7 @@ class ConfigAPIController extends OCSController { } try { - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); - if(!in_array($configID, $prefixes)) { - throw new OCSNotFoundException('Config ID not found'); - } + $this->ensureConfigIDExists($configID); if(!$this->ldapHelper->deleteServerConfiguration($configID)) { throw new OCSException('Could not delete configuration'); } @@ -174,4 +171,66 @@ class ConfigAPIController extends OCSController { return new DataResponse(); } + + /** + * modifies a configuration + * + * Example: + * curl -X PUT -d "key=ldapHost&value=ldaps://my.ldap.server" \ + * -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 string $configID + * @param string $key + * @param string $value + * @return DataResponse + * @throws OCSException + */ + public function modify($configID, $key, $value) { + $this->ensureConfigIDExists($configID); + + try { + $config = new Configuration($configID); + + $configKeys = $config->getConfigTranslationArray(); + if(!isset($configKeys[$key]) && !in_array($key, $configKeys, true)) { + throw new OCSBadRequestException('Invalid config key'); + } + + $config->$key = $value; + $config->saveConfiguration(); + } catch(OCSException $e) { + throw $e; + } catch (\Exception $e) { + $this->logger->logException($e); + throw new OCSException('An issue occurred when modifying the config.'); + } + + return new DataResponse(); + } + + /** + * if the given config ID is not available, an exception is thrown + * + * @param string $configID + * @throws OCSNotFoundException + */ + private function ensureConfigIDExists($configID) { + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); + if(!in_array($configID, $prefixes)) { + throw new OCSNotFoundException('Config ID not found'); + } + } } |