fix(user_ldap): Add OCS endpoint for copying configurations

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Louis Chmn <louis@chmn.me>
pull/55518/head
Côme Chilliet 2025-10-02 15:55:07 +07:00 committed by Louis Chmn
parent e842874a0a
commit 36475f2461
1 changed files with 28 additions and 0 deletions

@ -300,6 +300,34 @@ class ConfigAPIController extends OCSController {
}
}
/**
* Copy a configuration
*
* @return DataResponse<Http::STATUS_OK, array{configID:string}, array{}>
* @throws OCSException An unexpected error happened
* @throws OCSNotFoundException Config not found
*
* 200: Test was run and results are returned
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'POST', url: '/api/v1/config/{configID}/copy')]
public function copyConfiguration(string $configID) {
try {
$this->ensureConfigIDExists($configID);
$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
$newConfig = new Configuration($configPrefix, false);
$originalConfig = new Configuration($configID);
$newConfig->setConfiguration($originalConfig->getConfiguration());
$newConfig->saveConfiguration();
return new DataResponse(['configID' => $configPrefix]);
} catch (OCSException $e) {
throw $e;
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSException('An issue occurred when creating the new config.');
}
}
/**
* If the given config ID is not available, an exception is thrown
*