Completed
Push — master ( f8bed8...52aed0 )
by
unknown
24:23
created
core/Controller/WhatsNewController.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -20,84 +20,84 @@
 block discarded – undo
20 20
 use OCP\PreConditionNotMetException;
21 21
 
22 22
 class WhatsNewController extends \OCP\AppFramework\OCSController {
23
-	public function __construct(
24
-		string $appName,
25
-		IRequest $request,
26
-		private IUserSession $userSession,
27
-		private IConfig $config,
28
-		private ChangesCheck $whatsNewService,
29
-		private IFactory $langFactory,
30
-		private Defaults $defaults,
31
-	) {
32
-		parent::__construct($appName, $request);
33
-	}
23
+    public function __construct(
24
+        string $appName,
25
+        IRequest $request,
26
+        private IUserSession $userSession,
27
+        private IConfig $config,
28
+        private ChangesCheck $whatsNewService,
29
+        private IFactory $langFactory,
30
+        private Defaults $defaults,
31
+    ) {
32
+        parent::__construct($appName, $request);
33
+    }
34 34
 
35
-	/**
36
-	 * Get the changes
37
-	 *
38
-	 * @return DataResponse<Http::STATUS_OK, array{changelogURL: string, product: string, version: string, whatsNew?: array{regular: list<string>, admin: list<string>}}, array{}>|DataResponse<Http::STATUS_NO_CONTENT, list<empty>, array{}>
39
-	 *
40
-	 * 200: Changes returned
41
-	 * 204: No changes
42
-	 */
43
-	#[NoAdminRequired]
44
-	#[ApiRoute(verb: 'GET', url: '/whatsnew', root: '/core')]
45
-	public function get():DataResponse {
46
-		$user = $this->userSession->getUser();
47
-		if ($user === null) {
48
-			throw new \RuntimeException('Acting user cannot be resolved');
49
-		}
50
-		$lastRead = $this->config->getUserValue($user->getUID(), 'core', 'whatsNewLastRead', 0);
51
-		$currentVersion = $this->whatsNewService->normalizeVersion($this->config->getSystemValue('version'));
35
+    /**
36
+     * Get the changes
37
+     *
38
+     * @return DataResponse<Http::STATUS_OK, array{changelogURL: string, product: string, version: string, whatsNew?: array{regular: list<string>, admin: list<string>}}, array{}>|DataResponse<Http::STATUS_NO_CONTENT, list<empty>, array{}>
39
+     *
40
+     * 200: Changes returned
41
+     * 204: No changes
42
+     */
43
+    #[NoAdminRequired]
44
+    #[ApiRoute(verb: 'GET', url: '/whatsnew', root: '/core')]
45
+    public function get():DataResponse {
46
+        $user = $this->userSession->getUser();
47
+        if ($user === null) {
48
+            throw new \RuntimeException('Acting user cannot be resolved');
49
+        }
50
+        $lastRead = $this->config->getUserValue($user->getUID(), 'core', 'whatsNewLastRead', 0);
51
+        $currentVersion = $this->whatsNewService->normalizeVersion($this->config->getSystemValue('version'));
52 52
 
53
-		if (version_compare($lastRead, $currentVersion, '>=')) {
54
-			return new DataResponse([], Http::STATUS_NO_CONTENT);
55
-		}
53
+        if (version_compare($lastRead, $currentVersion, '>=')) {
54
+            return new DataResponse([], Http::STATUS_NO_CONTENT);
55
+        }
56 56
 
57
-		try {
58
-			$iterator = $this->langFactory->getLanguageIterator();
59
-			$whatsNew = $this->whatsNewService->getChangesForVersion($currentVersion);
60
-			$resultData = [
61
-				'changelogURL' => $whatsNew['changelogURL'],
62
-				'product' => $this->defaults->getProductName(),
63
-				'version' => $currentVersion,
64
-			];
65
-			do {
66
-				$lang = $iterator->current();
67
-				if (isset($whatsNew['whatsNew'][$lang])) {
68
-					$resultData['whatsNew'] = $whatsNew['whatsNew'][$lang];
69
-					break;
70
-				}
71
-				$iterator->next();
72
-			} while ($lang !== 'en' && $iterator->valid());
73
-			return new DataResponse($resultData);
74
-		} catch (DoesNotExistException $e) {
75
-			return new DataResponse([], Http::STATUS_NO_CONTENT);
76
-		}
77
-	}
57
+        try {
58
+            $iterator = $this->langFactory->getLanguageIterator();
59
+            $whatsNew = $this->whatsNewService->getChangesForVersion($currentVersion);
60
+            $resultData = [
61
+                'changelogURL' => $whatsNew['changelogURL'],
62
+                'product' => $this->defaults->getProductName(),
63
+                'version' => $currentVersion,
64
+            ];
65
+            do {
66
+                $lang = $iterator->current();
67
+                if (isset($whatsNew['whatsNew'][$lang])) {
68
+                    $resultData['whatsNew'] = $whatsNew['whatsNew'][$lang];
69
+                    break;
70
+                }
71
+                $iterator->next();
72
+            } while ($lang !== 'en' && $iterator->valid());
73
+            return new DataResponse($resultData);
74
+        } catch (DoesNotExistException $e) {
75
+            return new DataResponse([], Http::STATUS_NO_CONTENT);
76
+        }
77
+    }
78 78
 
79
-	/**
80
-	 * Dismiss the changes
81
-	 *
82
-	 * @param string $version Version to dismiss the changes for
83
-	 *
84
-	 * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
85
-	 * @throws PreConditionNotMetException
86
-	 * @throws DoesNotExistException
87
-	 *
88
-	 * 200: Changes dismissed
89
-	 */
90
-	#[NoAdminRequired]
91
-	#[ApiRoute(verb: 'POST', url: '/whatsnew', root: '/core')]
92
-	public function dismiss(string $version):DataResponse {
93
-		$user = $this->userSession->getUser();
94
-		if ($user === null) {
95
-			throw new \RuntimeException('Acting user cannot be resolved');
96
-		}
97
-		$version = $this->whatsNewService->normalizeVersion($version);
98
-		// checks whether it's a valid version, throws an Exception otherwise
99
-		$this->whatsNewService->getChangesForVersion($version);
100
-		$this->config->setUserValue($user->getUID(), 'core', 'whatsNewLastRead', $version);
101
-		return new DataResponse();
102
-	}
79
+    /**
80
+     * Dismiss the changes
81
+     *
82
+     * @param string $version Version to dismiss the changes for
83
+     *
84
+     * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
85
+     * @throws PreConditionNotMetException
86
+     * @throws DoesNotExistException
87
+     *
88
+     * 200: Changes dismissed
89
+     */
90
+    #[NoAdminRequired]
91
+    #[ApiRoute(verb: 'POST', url: '/whatsnew', root: '/core')]
92
+    public function dismiss(string $version):DataResponse {
93
+        $user = $this->userSession->getUser();
94
+        if ($user === null) {
95
+            throw new \RuntimeException('Acting user cannot be resolved');
96
+        }
97
+        $version = $this->whatsNewService->normalizeVersion($version);
98
+        // checks whether it's a valid version, throws an Exception otherwise
99
+        $this->whatsNewService->getChangesForVersion($version);
100
+        $this->config->setUserValue($user->getUID(), 'core', 'whatsNewLastRead', $version);
101
+        return new DataResponse();
102
+    }
103 103
 }
Please login to merge, or discard this patch.
core/Controller/OCSController.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -25,99 +25,99 @@
 block discarded – undo
25 25
  * Please use {@see \OCP\AppFramework\OCSController}!
26 26
  */
27 27
 final class OCSController extends \OCP\AppFramework\OCSController {
28
-	public function __construct(
29
-		string $appName,
30
-		IRequest $request,
31
-		private CapabilitiesManager $capabilitiesManager,
32
-		private IUserSession $userSession,
33
-		private IUserManager $userManager,
34
-		private Manager $keyManager,
35
-		private ServerVersion $serverVersion,
36
-	) {
37
-		parent::__construct($appName, $request);
38
-	}
28
+    public function __construct(
29
+        string $appName,
30
+        IRequest $request,
31
+        private CapabilitiesManager $capabilitiesManager,
32
+        private IUserSession $userSession,
33
+        private IUserManager $userManager,
34
+        private Manager $keyManager,
35
+        private ServerVersion $serverVersion,
36
+    ) {
37
+        parent::__construct($appName, $request);
38
+    }
39 39
 
40
-	#[PublicPage]
41
-	#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
42
-	#[ApiRoute(verb: 'GET', url: '/config', root: '')]
43
-	public function getConfig(): DataResponse {
44
-		$data = [
45
-			'version' => '1.7',
46
-			'website' => 'Nextcloud',
47
-			'host' => $this->request->getServerHost(),
48
-			'contact' => '',
49
-			'ssl' => 'false',
50
-		];
40
+    #[PublicPage]
41
+    #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
42
+    #[ApiRoute(verb: 'GET', url: '/config', root: '')]
43
+    public function getConfig(): DataResponse {
44
+        $data = [
45
+            'version' => '1.7',
46
+            'website' => 'Nextcloud',
47
+            'host' => $this->request->getServerHost(),
48
+            'contact' => '',
49
+            'ssl' => 'false',
50
+        ];
51 51
 
52
-		return new DataResponse($data);
53
-	}
52
+        return new DataResponse($data);
53
+    }
54 54
 
55
-	/**
56
-	 * Get the capabilities
57
-	 *
58
-	 * @return DataResponse<Http::STATUS_OK, array{version: array{major: int, minor: int, micro: int, string: string, edition: '', extendedSupport: bool}, capabilities: array<string, mixed>}, array{}>
59
-	 *
60
-	 * 200: Capabilities returned
61
-	 */
62
-	#[PublicPage]
63
-	#[ApiRoute(verb: 'GET', url: '/capabilities', root: '/cloud')]
64
-	public function getCapabilities(): DataResponse {
65
-		$result = [];
66
-		$result['version'] = [
67
-			'major' => $this->serverVersion->getMajorVersion(),
68
-			'minor' => $this->serverVersion->getMinorVersion(),
69
-			'micro' => $this->serverVersion->getPatchVersion(),
70
-			'string' => $this->serverVersion->getVersionString(),
71
-			'edition' => '',
72
-			'extendedSupport' => Util::hasExtendedSupport()
73
-		];
55
+    /**
56
+     * Get the capabilities
57
+     *
58
+     * @return DataResponse<Http::STATUS_OK, array{version: array{major: int, minor: int, micro: int, string: string, edition: '', extendedSupport: bool}, capabilities: array<string, mixed>}, array{}>
59
+     *
60
+     * 200: Capabilities returned
61
+     */
62
+    #[PublicPage]
63
+    #[ApiRoute(verb: 'GET', url: '/capabilities', root: '/cloud')]
64
+    public function getCapabilities(): DataResponse {
65
+        $result = [];
66
+        $result['version'] = [
67
+            'major' => $this->serverVersion->getMajorVersion(),
68
+            'minor' => $this->serverVersion->getMinorVersion(),
69
+            'micro' => $this->serverVersion->getPatchVersion(),
70
+            'string' => $this->serverVersion->getVersionString(),
71
+            'edition' => '',
72
+            'extendedSupport' => Util::hasExtendedSupport()
73
+        ];
74 74
 
75
-		if ($this->userSession->isLoggedIn()) {
76
-			$result['capabilities'] = $this->capabilitiesManager->getCapabilities();
77
-		} else {
78
-			$result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
79
-		}
75
+        if ($this->userSession->isLoggedIn()) {
76
+            $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
77
+        } else {
78
+            $result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
79
+        }
80 80
 
81
-		$response = new DataResponse($result);
82
-		$response->setETag(md5(json_encode($result)));
83
-		return $response;
84
-	}
81
+        $response = new DataResponse($result);
82
+        $response->setETag(md5(json_encode($result)));
83
+        return $response;
84
+    }
85 85
 
86
-	#[PublicPage]
87
-	#[BruteForceProtection(action: 'login')]
88
-	#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
89
-	#[ApiRoute(verb: 'POST', url: '/check', root: '/person')]
90
-	public function personCheck(string $login = '', string $password = ''): DataResponse {
91
-		if ($login !== '' && $password !== '') {
92
-			if ($this->userManager->checkPassword($login, $password)) {
93
-				return new DataResponse([
94
-					'person' => [
95
-						'personid' => $login
96
-					]
97
-				]);
98
-			}
86
+    #[PublicPage]
87
+    #[BruteForceProtection(action: 'login')]
88
+    #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
89
+    #[ApiRoute(verb: 'POST', url: '/check', root: '/person')]
90
+    public function personCheck(string $login = '', string $password = ''): DataResponse {
91
+        if ($login !== '' && $password !== '') {
92
+            if ($this->userManager->checkPassword($login, $password)) {
93
+                return new DataResponse([
94
+                    'person' => [
95
+                        'personid' => $login
96
+                    ]
97
+                ]);
98
+            }
99 99
 
100
-			$response = new DataResponse([], 102);
101
-			$response->throttle();
102
-			return $response;
103
-		}
104
-		return new DataResponse([], 101);
105
-	}
100
+            $response = new DataResponse([], 102);
101
+            $response->throttle();
102
+            return $response;
103
+        }
104
+        return new DataResponse([], 101);
105
+    }
106 106
 
107
-	#[PublicPage]
108
-	#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
109
-	#[ApiRoute(verb: 'GET', url: '/key/{cloudId}', root: '/identityproof')]
110
-	public function getIdentityProof(string $cloudId): DataResponse {
111
-		$userObject = $this->userManager->get($cloudId);
107
+    #[PublicPage]
108
+    #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
109
+    #[ApiRoute(verb: 'GET', url: '/key/{cloudId}', root: '/identityproof')]
110
+    public function getIdentityProof(string $cloudId): DataResponse {
111
+        $userObject = $this->userManager->get($cloudId);
112 112
 
113
-		if ($userObject !== null) {
114
-			$key = $this->keyManager->getKey($userObject);
115
-			$data = [
116
-				'public' => $key->getPublic(),
117
-			];
118
-			return new DataResponse($data);
119
-		}
113
+        if ($userObject !== null) {
114
+            $key = $this->keyManager->getKey($userObject);
115
+            $data = [
116
+                'public' => $key->getPublic(),
117
+            ];
118
+            return new DataResponse($data);
119
+        }
120 120
 
121
-		return new DataResponse(['Account not found'], 404);
122
-	}
121
+        return new DataResponse(['Account not found'], 404);
122
+    }
123 123
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Controller/ConfigAPIController.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -22,222 +22,222 @@
 block discarded – undo
22 22
 use Psr\Log\LoggerInterface;
23 23
 
24 24
 class ConfigAPIController extends OCSController {
25
-	public function __construct(
26
-		string $appName,
27
-		IRequest $request,
28
-		private Helper $ldapHelper,
29
-		private LoggerInterface $logger,
30
-		private ConnectionFactory $connectionFactory,
31
-	) {
32
-		parent::__construct($appName, $request);
33
-	}
34
-
35
-	/**
36
-	 * Create a new (empty) configuration and return the resulting prefix
37
-	 *
38
-	 * @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}>
39
-	 * @throws OCSException
40
-	 *
41
-	 * 200: Config created successfully
42
-	 */
43
-	#[AuthorizedAdminSetting(settings: Admin::class)]
44
-	#[ApiRoute(verb: 'POST', url: '/api/v1/config')]
45
-	public function create() {
46
-		try {
47
-			$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
48
-			$configHolder = new Configuration($configPrefix);
49
-			$configHolder->ldapConfigurationActive = false;
50
-			$configHolder->saveConfiguration();
51
-		} catch (\Exception $e) {
52
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
53
-			throw new OCSException('An issue occurred when creating the new config.');
54
-		}
55
-		return new DataResponse(['configID' => $configPrefix]);
56
-	}
57
-
58
-	/**
59
-	 * Delete a LDAP configuration
60
-	 *
61
-	 * @param string $configID ID of the config
62
-	 * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
63
-	 * @throws OCSException
64
-	 * @throws OCSNotFoundException Config not found
65
-	 *
66
-	 * 200: Config deleted successfully
67
-	 */
68
-	#[AuthorizedAdminSetting(settings: Admin::class)]
69
-	#[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')]
70
-	public function delete($configID) {
71
-		try {
72
-			$this->ensureConfigIDExists($configID);
73
-			if (!$this->ldapHelper->deleteServerConfiguration($configID)) {
74
-				throw new OCSException('Could not delete configuration');
75
-			}
76
-		} catch (OCSException $e) {
77
-			throw $e;
78
-		} catch (\Exception $e) {
79
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
80
-			throw new OCSException('An issue occurred when deleting the config.');
81
-		}
82
-
83
-		return new DataResponse();
84
-	}
85
-
86
-	/**
87
-	 * Modify a configuration
88
-	 *
89
-	 * @param string $configID ID of the config
90
-	 * @param array<string, mixed> $configData New config
91
-	 * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
92
-	 * @throws OCSException
93
-	 * @throws OCSBadRequestException Modifying config is not possible
94
-	 * @throws OCSNotFoundException Config not found
95
-	 *
96
-	 * 200: Config returned
97
-	 */
98
-	#[AuthorizedAdminSetting(settings: Admin::class)]
99
-	#[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')]
100
-	public function modify($configID, $configData) {
101
-		try {
102
-			$this->ensureConfigIDExists($configID);
103
-
104
-			if (!is_array($configData)) {
105
-				throw new OCSBadRequestException('configData is not properly set');
106
-			}
107
-
108
-			$configuration = new Configuration($configID);
109
-			$configKeys = $configuration->getConfigTranslationArray();
110
-
111
-			foreach ($configKeys as $i => $key) {
112
-				if (isset($configData[$key])) {
113
-					$configuration->$key = $configData[$key];
114
-				}
115
-			}
116
-
117
-			$configuration->saveConfiguration();
118
-			$this->connectionFactory->get($configID)->clearCache();
119
-		} catch (OCSException $e) {
120
-			throw $e;
121
-		} catch (\Exception $e) {
122
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
123
-			throw new OCSException('An issue occurred when modifying the config.');
124
-		}
125
-
126
-		return $this->show($configID, false);
127
-	}
128
-
129
-	/**
130
-	 * Get a configuration
131
-	 *
132
-	 * Output can look like this:
133
-	 * <?xml version="1.0"?>
134
-	 * <ocs>
135
-	 *   <meta>
136
-	 *     <status>ok</status>
137
-	 *     <statuscode>200</statuscode>
138
-	 *     <message>OK</message>
139
-	 *   </meta>
140
-	 *   <data>
141
-	 *     <ldapHost>ldaps://my.ldap.server</ldapHost>
142
-	 *     <ldapPort>7770</ldapPort>
143
-	 *     <ldapBackupHost></ldapBackupHost>
144
-	 *     <ldapBackupPort></ldapBackupPort>
145
-	 *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
146
-	 *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
147
-	 *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
148
-	 *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
149
-	 *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
150
-	 *     <ldapTLS>1</ldapTLS>
151
-	 *     <turnOffCertCheck>0</turnOffCertCheck>
152
-	 *     <ldapIgnoreNamingRules/>
153
-	 *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
154
-	 *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
155
-	 *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
156
-	 *     <ldapUserFilterGroups></ldapUserFilterGroups>
157
-	 *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
158
-	 *     <ldapUserFilterMode>1</ldapUserFilterMode>
159
-	 *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
160
-	 *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
161
-	 *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
162
-	 *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
163
-	 *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
164
-	 *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
165
-	 *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
166
-	 *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
167
-	 *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
168
-	 *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
169
-	 *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
170
-	 *     <ldapQuotaAttribute></ldapQuotaAttribute>
171
-	 *     <ldapQuotaDefault></ldapQuotaDefault>
172
-	 *     <ldapEmailAttribute>mail</ldapEmailAttribute>
173
-	 *     <ldapCacheTTL>20</ldapCacheTTL>
174
-	 *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
175
-	 *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
176
-	 *     <ldapOverrideMainServer></ldapOverrideMainServer>
177
-	 *     <ldapConfigurationActive>1</ldapConfigurationActive>
178
-	 *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
179
-	 *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
180
-	 *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
181
-	 *     <homeFolderNamingRule></homeFolderNamingRule>
182
-	 *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
183
-	 *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
184
-	 *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
185
-	 *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
186
-	 *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
187
-	 *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
188
-	 *     <ldapNestedGroups>0</ldapNestedGroups>
189
-	 *     <ldapPagingSize>500</ldapPagingSize>
190
-	 *     <turnOnPasswordChange>1</turnOnPasswordChange>
191
-	 *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
192
-	 *   </data>
193
-	 * </ocs>
194
-	 *
195
-	 * @param string $configID ID of the config
196
-	 * @param bool $showPassword Whether to show the password
197
-	 * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
198
-	 * @throws OCSException
199
-	 * @throws OCSNotFoundException Config not found
200
-	 *
201
-	 * 200: Config returned
202
-	 */
203
-	#[AuthorizedAdminSetting(settings: Admin::class)]
204
-	#[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')]
205
-	public function show($configID, $showPassword = false) {
206
-		try {
207
-			$this->ensureConfigIDExists($configID);
208
-
209
-			$config = new Configuration($configID);
210
-			$data = $config->getConfiguration();
211
-			if (!$showPassword) {
212
-				$data['ldapAgentPassword'] = '***';
213
-			}
214
-			foreach ($data as $key => $value) {
215
-				if (is_array($value)) {
216
-					$value = implode(';', $value);
217
-					$data[$key] = $value;
218
-				}
219
-			}
220
-		} catch (OCSException $e) {
221
-			throw $e;
222
-		} catch (\Exception $e) {
223
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
224
-			throw new OCSException('An issue occurred when modifying the config.');
225
-		}
226
-
227
-		return new DataResponse($data);
228
-	}
229
-
230
-	/**
231
-	 * If the given config ID is not available, an exception is thrown
232
-	 *
233
-	 * @param string $configID
234
-	 * @throws OCSNotFoundException
235
-	 */
236
-	#[AuthorizedAdminSetting(settings: Admin::class)]
237
-	private function ensureConfigIDExists($configID): void {
238
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
239
-		if (!in_array($configID, $prefixes, true)) {
240
-			throw new OCSNotFoundException('Config ID not found');
241
-		}
242
-	}
25
+    public function __construct(
26
+        string $appName,
27
+        IRequest $request,
28
+        private Helper $ldapHelper,
29
+        private LoggerInterface $logger,
30
+        private ConnectionFactory $connectionFactory,
31
+    ) {
32
+        parent::__construct($appName, $request);
33
+    }
34
+
35
+    /**
36
+     * Create a new (empty) configuration and return the resulting prefix
37
+     *
38
+     * @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}>
39
+     * @throws OCSException
40
+     *
41
+     * 200: Config created successfully
42
+     */
43
+    #[AuthorizedAdminSetting(settings: Admin::class)]
44
+    #[ApiRoute(verb: 'POST', url: '/api/v1/config')]
45
+    public function create() {
46
+        try {
47
+            $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
48
+            $configHolder = new Configuration($configPrefix);
49
+            $configHolder->ldapConfigurationActive = false;
50
+            $configHolder->saveConfiguration();
51
+        } catch (\Exception $e) {
52
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
53
+            throw new OCSException('An issue occurred when creating the new config.');
54
+        }
55
+        return new DataResponse(['configID' => $configPrefix]);
56
+    }
57
+
58
+    /**
59
+     * Delete a LDAP configuration
60
+     *
61
+     * @param string $configID ID of the config
62
+     * @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
63
+     * @throws OCSException
64
+     * @throws OCSNotFoundException Config not found
65
+     *
66
+     * 200: Config deleted successfully
67
+     */
68
+    #[AuthorizedAdminSetting(settings: Admin::class)]
69
+    #[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')]
70
+    public function delete($configID) {
71
+        try {
72
+            $this->ensureConfigIDExists($configID);
73
+            if (!$this->ldapHelper->deleteServerConfiguration($configID)) {
74
+                throw new OCSException('Could not delete configuration');
75
+            }
76
+        } catch (OCSException $e) {
77
+            throw $e;
78
+        } catch (\Exception $e) {
79
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
80
+            throw new OCSException('An issue occurred when deleting the config.');
81
+        }
82
+
83
+        return new DataResponse();
84
+    }
85
+
86
+    /**
87
+     * Modify a configuration
88
+     *
89
+     * @param string $configID ID of the config
90
+     * @param array<string, mixed> $configData New config
91
+     * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
92
+     * @throws OCSException
93
+     * @throws OCSBadRequestException Modifying config is not possible
94
+     * @throws OCSNotFoundException Config not found
95
+     *
96
+     * 200: Config returned
97
+     */
98
+    #[AuthorizedAdminSetting(settings: Admin::class)]
99
+    #[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')]
100
+    public function modify($configID, $configData) {
101
+        try {
102
+            $this->ensureConfigIDExists($configID);
103
+
104
+            if (!is_array($configData)) {
105
+                throw new OCSBadRequestException('configData is not properly set');
106
+            }
107
+
108
+            $configuration = new Configuration($configID);
109
+            $configKeys = $configuration->getConfigTranslationArray();
110
+
111
+            foreach ($configKeys as $i => $key) {
112
+                if (isset($configData[$key])) {
113
+                    $configuration->$key = $configData[$key];
114
+                }
115
+            }
116
+
117
+            $configuration->saveConfiguration();
118
+            $this->connectionFactory->get($configID)->clearCache();
119
+        } catch (OCSException $e) {
120
+            throw $e;
121
+        } catch (\Exception $e) {
122
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
123
+            throw new OCSException('An issue occurred when modifying the config.');
124
+        }
125
+
126
+        return $this->show($configID, false);
127
+    }
128
+
129
+    /**
130
+     * Get a configuration
131
+     *
132
+     * Output can look like this:
133
+     * <?xml version="1.0"?>
134
+     * <ocs>
135
+     *   <meta>
136
+     *     <status>ok</status>
137
+     *     <statuscode>200</statuscode>
138
+     *     <message>OK</message>
139
+     *   </meta>
140
+     *   <data>
141
+     *     <ldapHost>ldaps://my.ldap.server</ldapHost>
142
+     *     <ldapPort>7770</ldapPort>
143
+     *     <ldapBackupHost></ldapBackupHost>
144
+     *     <ldapBackupPort></ldapBackupPort>
145
+     *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
146
+     *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
147
+     *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
148
+     *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
149
+     *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
150
+     *     <ldapTLS>1</ldapTLS>
151
+     *     <turnOffCertCheck>0</turnOffCertCheck>
152
+     *     <ldapIgnoreNamingRules/>
153
+     *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
154
+     *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
155
+     *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
156
+     *     <ldapUserFilterGroups></ldapUserFilterGroups>
157
+     *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
158
+     *     <ldapUserFilterMode>1</ldapUserFilterMode>
159
+     *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
160
+     *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
161
+     *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
162
+     *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
163
+     *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
164
+     *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
165
+     *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
166
+     *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
167
+     *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
168
+     *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
169
+     *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
170
+     *     <ldapQuotaAttribute></ldapQuotaAttribute>
171
+     *     <ldapQuotaDefault></ldapQuotaDefault>
172
+     *     <ldapEmailAttribute>mail</ldapEmailAttribute>
173
+     *     <ldapCacheTTL>20</ldapCacheTTL>
174
+     *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
175
+     *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
176
+     *     <ldapOverrideMainServer></ldapOverrideMainServer>
177
+     *     <ldapConfigurationActive>1</ldapConfigurationActive>
178
+     *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
179
+     *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
180
+     *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
181
+     *     <homeFolderNamingRule></homeFolderNamingRule>
182
+     *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
183
+     *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
184
+     *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
185
+     *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
186
+     *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
187
+     *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
188
+     *     <ldapNestedGroups>0</ldapNestedGroups>
189
+     *     <ldapPagingSize>500</ldapPagingSize>
190
+     *     <turnOnPasswordChange>1</turnOnPasswordChange>
191
+     *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
192
+     *   </data>
193
+     * </ocs>
194
+     *
195
+     * @param string $configID ID of the config
196
+     * @param bool $showPassword Whether to show the password
197
+     * @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>
198
+     * @throws OCSException
199
+     * @throws OCSNotFoundException Config not found
200
+     *
201
+     * 200: Config returned
202
+     */
203
+    #[AuthorizedAdminSetting(settings: Admin::class)]
204
+    #[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')]
205
+    public function show($configID, $showPassword = false) {
206
+        try {
207
+            $this->ensureConfigIDExists($configID);
208
+
209
+            $config = new Configuration($configID);
210
+            $data = $config->getConfiguration();
211
+            if (!$showPassword) {
212
+                $data['ldapAgentPassword'] = '***';
213
+            }
214
+            foreach ($data as $key => $value) {
215
+                if (is_array($value)) {
216
+                    $value = implode(';', $value);
217
+                    $data[$key] = $value;
218
+                }
219
+            }
220
+        } catch (OCSException $e) {
221
+            throw $e;
222
+        } catch (\Exception $e) {
223
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
224
+            throw new OCSException('An issue occurred when modifying the config.');
225
+        }
226
+
227
+        return new DataResponse($data);
228
+    }
229
+
230
+    /**
231
+     * If the given config ID is not available, an exception is thrown
232
+     *
233
+     * @param string $configID
234
+     * @throws OCSNotFoundException
235
+     */
236
+    #[AuthorizedAdminSetting(settings: Admin::class)]
237
+    private function ensureConfigIDExists($configID): void {
238
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
239
+        if (!in_array($configID, $prefixes, true)) {
240
+            throw new OCSNotFoundException('Config ID not found');
241
+        }
242
+    }
243 243
 }
Please login to merge, or discard this patch.