Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Rewrite LDAP wizard #48065

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions apps/user_ldap/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
->actionInclude('user_ldap/ajax/wizard.php');

$application = new \OCP\AppFramework\App('user_ldap');
$application->registerRoutes($this, [
'ocs' => [
['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'],
['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'],
['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'],
['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'],
]
]);

/** @var \OCA\User_LDAP\AppInfo\Application $application */
$application = \OC::$server->query(\OCA\User_LDAP\AppInfo\Application::class);
Expand Down
6 changes: 5 additions & 1 deletion apps/user_ldap/lib/Controller/ConfigAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\Settings\Admin;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
Expand Down Expand Up @@ -51,12 +51,13 @@
/**
* Create a new (empty) configuration and return the resulting prefix
*
* @return DataResponse<Http::STATUS_OK, array{configID: string}, array{}>

Check failure on line 54 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidTemplateParam

apps/user_ldap/lib/Controller/ConfigAPIController.php:54:13: InvalidTemplateParam: Extended template param S of OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array{configID: string}, array<never, never>> expects type int, type OCA\User_LDAP\Controller\Http::STATUS_OK given (see https://psalm.dev/183)

Check failure on line 54 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

apps/user_ldap/lib/Controller/ConfigAPIController.php:54:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\User_LDAP\Controller\Http does not exist (see https://psalm.dev/200)

Check failure on line 54 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidReturnType

apps/user_ldap/lib/Controller/ConfigAPIController.php:54:13: InvalidReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array{configID: string}, array<never, never>>' for OCA\User_LDAP\Controller\ConfigAPIController::create is incorrect, got 'OCP\AppFramework\Http\DataResponse<200, array{configID: string}, array<never, never>>' (see https://psalm.dev/011)
* @throws OCSException
*
* 200: Config created successfully
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'POST', url: '/api/v1/config')]
public function create() {
try {
$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
Expand All @@ -67,20 +68,21 @@
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSException('An issue occurred when creating the new config.');
}
return new DataResponse(['configID' => $configPrefix]);

Check failure on line 71 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidReturnStatement

apps/user_ldap/lib/Controller/ConfigAPIController.php:71:10: InvalidReturnStatement: The inferred type 'OCP\AppFramework\Http\DataResponse<200, array{configID: string}, array<never, never>>' does not match the declared return type 'OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array{configID: string}, array<never, never>>' for OCA\User_LDAP\Controller\ConfigAPIController::create (see https://psalm.dev/128)
}

/**
* Delete a LDAP configuration
*
* @param string $configID ID of the config
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>

Check failure on line 78 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidTemplateParam

apps/user_ldap/lib/Controller/ConfigAPIController.php:78:13: InvalidTemplateParam: Extended template param S of OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array<array-key, never>, array<never, never>> expects type int, type OCA\User_LDAP\Controller\Http::STATUS_OK given (see https://psalm.dev/183)

Check failure on line 78 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

apps/user_ldap/lib/Controller/ConfigAPIController.php:78:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\User_LDAP\Controller\Http does not exist (see https://psalm.dev/200)

Check failure on line 78 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidReturnType

apps/user_ldap/lib/Controller/ConfigAPIController.php:78:13: InvalidReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array<array-key, never>, array<never, never>>' for OCA\User_LDAP\Controller\ConfigAPIController::delete is incorrect, got 'OCP\AppFramework\Http\DataResponse<200, array<never, never>, array<never, never>>' (see https://psalm.dev/011)
* @throws OCSException
* @throws OCSNotFoundException Config not found
*
* 200: Config deleted successfully
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')]
public function delete($configID) {
try {
$this->ensureConfigIDExists($configID);
Expand All @@ -94,7 +96,7 @@
throw new OCSException('An issue occurred when deleting the config.');
}

return new DataResponse();

Check failure on line 99 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidReturnStatement

apps/user_ldap/lib/Controller/ConfigAPIController.php:99:10: InvalidReturnStatement: The inferred type 'OCP\AppFramework\Http\DataResponse<200, array<never, never>, array<never, never>>' does not match the declared return type 'OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array<array-key, never>, array<never, never>>' for OCA\User_LDAP\Controller\ConfigAPIController::delete (see https://psalm.dev/128)
}

/**
Expand All @@ -102,7 +104,7 @@
*
* @param string $configID ID of the config
* @param array<string, mixed> $configData New config
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>

Check failure on line 107 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidTemplateParam

apps/user_ldap/lib/Controller/ConfigAPIController.php:107:13: InvalidTemplateParam: Extended template param S of OCP\AppFramework\Http\DataResponse<OCA\User_LDAP\Controller\Http::STATUS_OK, array<array-key, never>, array<never, never>> expects type int, type OCA\User_LDAP\Controller\Http::STATUS_OK given (see https://psalm.dev/183)

Check failure on line 107 in apps/user_ldap/lib/Controller/ConfigAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

apps/user_ldap/lib/Controller/ConfigAPIController.php:107:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\User_LDAP\Controller\Http does not exist (see https://psalm.dev/200)
* @throws OCSException
* @throws OCSBadRequestException Modifying config is not possible
* @throws OCSNotFoundException Config not found
Expand All @@ -110,6 +112,7 @@
* 200: Config returned
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')]
public function modify($configID, $configData) {
try {
$this->ensureConfigIDExists($configID);
Expand Down Expand Up @@ -214,6 +217,7 @@
* 200: Config returned
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')]
public function show($configID, $showPassword = false) {
try {
$this->ensureConfigIDExists($configID);
Expand Down
30 changes: 22 additions & 8 deletions apps/user_ldap/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IL10N;
use OCP\Settings\IDelegatedSettings;
use OCP\Template;

class Admin implements IDelegatedSettings {
/** @var IL10N */
private $l;

/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this->l = $l;
public function __construct(
private IL10N $l,
private IInitialState $InitialState
) {
}

/**
Expand All @@ -44,6 +41,7 @@ public function getForm() {
$sControls = new Template('user_ldap', 'part.settingcontrols');
$sControls = $sControls->fetchPage();

// TODO: remove
$parameters['serverConfigurationPrefixes'] = $prefixes;
$parameters['serverConfigurationHosts'] = $hosts;
$parameters['settingControls'] = $sControls;
Expand All @@ -58,6 +56,22 @@ public function getForm() {
$parameters[$key . '_default'] = $default;
}

$ldapConfigs = [];
foreach ($prefixes as $prefix) {
$ldapConfig = new Configuration($prefix);
$rawLdapConfig = $ldapConfig->getConfiguration();
foreach ($rawLdapConfig as $key => $value) {
if (is_array($value)) {
$rawLdapConfig[$key] = implode(';', $value);
}
}

$ldapConfigs[$prefix] = $rawLdapConfig;
}

$this->InitialState->provideInitialState('ldapConfigs', $ldapConfigs);
$this->InitialState->provideInitialState('ldapModuleInstalled', function_exists('ldap_connect'));

return new TemplateResponse('user_ldap', 'settings', $parameters);
}

Expand Down
21 changes: 21 additions & 0 deletions apps/user_ldap/src/LDAPSettingsApp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<Settings />
</template>

<script lang="ts">
import { defineComponent } from 'vue'

import Settings from './views/Settings.vue'

export default defineComponent({
name: 'LDAPSettingsApp',

components: {
Settings,
},
})
</script>
Loading
Loading