From f5b73d2c774c5b8e2aac441d7cf08ec48e42152c Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 17 Sep 2024 14:41:25 +0200 Subject: [PATCH] fix: Remove legacy settings forms `OC_App::getForms` was always returning an empty array, because there were no setter for `adminForms` or `personalForms` anymore. So removed all that legacy settings forms logic. Signed-off-by: Ferdinand Thiessen --- .../Controller/AdminSettingsController.php | 36 ------------------- .../lib/Controller/CommonSettingsTrait.php | 2 +- .../Controller/PersonalSettingsController.php | 34 ------------------ lib/private/Settings/Manager.php | 18 +--------- lib/private/legacy/OC_App.php | 32 +++-------------- 5 files changed, 6 insertions(+), 116 deletions(-) diff --git a/apps/settings/lib/Controller/AdminSettingsController.php b/apps/settings/lib/Controller/AdminSettingsController.php index 9ba1892afafc3..25338f64326a7 100644 --- a/apps/settings/lib/Controller/AdminSettingsController.php +++ b/apps/settings/lib/Controller/AdminSettingsController.php @@ -20,7 +20,6 @@ use OCP\IUserSession; use OCP\Settings\IDeclarativeManager; use OCP\Settings\IManager as ISettingsManager; -use OCP\Template; #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] class AdminSettingsController extends Controller { @@ -65,47 +64,12 @@ public function index(string $section): TemplateResponse { protected function getSettings($section) { /** @var IUser $user */ $user = $this->userSession->getUser(); - $isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user); $settings = $this->settingsManager->getAllowedAdminSettings($section, $user); $declarativeFormIDs = $this->declarativeSettingsManager->getFormIDs($user, 'admin', $section); if (empty($settings) && empty($declarativeFormIDs)) { throw new NotAdminException("Logged in user doesn't have permission to access these settings."); } $formatted = $this->formatSettings($settings); - // Do not show legacy forms for sub admins - if ($section === 'additional' && !$isSubAdmin) { - $formatted['content'] .= $this->getLegacyForms(); - } return $formatted; } - - /** - * @return bool|string - */ - private function getLegacyForms() { - $forms = \OC_App::getForms('admin'); - - $forms = array_map(function ($form) { - if (preg_match('%([^>]*)>.*?)%i', $form, $regs)) { - $sectionName = str_replace('', '', $regs[0]); - $sectionName = str_replace('', '', $sectionName); - $anchor = strtolower($sectionName); - $anchor = str_replace(' ', '-', $anchor); - - return [ - 'anchor' => $anchor, - 'section-name' => $sectionName, - 'form' => $form - ]; - } - return [ - 'form' => $form - ]; - }, $forms); - - $out = new Template('settings', 'settings/additional'); - $out->assign('forms', $forms); - - return $out->fetchPage(); - } } diff --git a/apps/settings/lib/Controller/CommonSettingsTrait.php b/apps/settings/lib/Controller/CommonSettingsTrait.php index eaf8e6c377435..dd307b67fab46 100644 --- a/apps/settings/lib/Controller/CommonSettingsTrait.php +++ b/apps/settings/lib/Controller/CommonSettingsTrait.php @@ -75,7 +75,7 @@ protected function formatSections(array $sections, string $currentSection, strin /** @psalm-suppress PossiblyNullArgument */ $declarativeFormIDs = $this->declarativeSettingsManager->getFormIDs($this->userSession->getUser(), $type, $section->getID()); - if (empty($settings) && empty($declarativeFormIDs) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) { + if (empty($settings) && empty($declarativeFormIDs)) { continue; } diff --git a/apps/settings/lib/Controller/PersonalSettingsController.php b/apps/settings/lib/Controller/PersonalSettingsController.php index db74d26e1f6e9..1a31a20eb0407 100644 --- a/apps/settings/lib/Controller/PersonalSettingsController.php +++ b/apps/settings/lib/Controller/PersonalSettingsController.php @@ -18,7 +18,6 @@ use OCP\IUserSession; use OCP\Settings\IDeclarativeManager; use OCP\Settings\IManager as ISettingsManager; -use OCP\Template; #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] class PersonalSettingsController extends Controller { @@ -61,39 +60,6 @@ public function index(string $section): TemplateResponse { protected function getSettings($section) { $settings = $this->settingsManager->getPersonalSettings($section); $formatted = $this->formatSettings($settings); - if ($section === 'additional') { - $formatted['content'] .= $this->getLegacyForms(); - } return $formatted; } - - /** - * @return bool|string - */ - private function getLegacyForms() { - $forms = \OC_App::getForms('personal'); - - $forms = array_map(function ($form) { - if (preg_match('%([^>]*)>.*?)%i', $form, $regs)) { - $sectionName = str_replace('', '', $regs[0]); - $sectionName = str_replace('', '', $sectionName); - $anchor = strtolower($sectionName); - $anchor = str_replace(' ', '-', $anchor); - - return [ - 'anchor' => $anchor, - 'section-name' => $sectionName, - 'form' => $form - ]; - } - return [ - 'form' => $form - ]; - }, $forms); - - $out = new Template('settings', 'settings/additional'); - $out->assign('forms', $forms); - - return $out->fetchPage(); - } } diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index c96b73474fa90..3d4ea8ea39ff9 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -260,9 +260,7 @@ public function getPersonalSections(): array { $sections = []; - $legacyForms = \OC_App::getForms('personal'); - if ((!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) - || count($this->getPersonalSettings('additional')) > 1) { + if (count($this->getPersonalSettings('additional')) > 1) { $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; } @@ -282,20 +280,6 @@ public function getPersonalSections(): array { return $sections; } - /** - * @param string[] $forms - * - * @return bool - */ - private function hasLegacyPersonalSettingsToRender(array $forms): bool { - foreach ($forms as $form) { - if (trim($form) !== '') { - return true; - } - } - return false; - } - /** * @inheritdoc */ diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index ef84d35d7bca3..0756f274a1192 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -26,12 +26,10 @@ /** * This class manages the apps. It allows them to register and integrate in the - * ownCloud ecosystem. Furthermore, this class is responsible for installing, + * Nextcloud ecosystem. Furthermore, this class is responsible for installing, * upgrading and removing apps. */ class OC_App { - private static $adminForms = []; - private static $personalForms = []; private static $altLogin = []; private static $alreadyRegistered = []; public const supportedApp = 300; @@ -68,7 +66,7 @@ public static function isAppLoaded(string $app): bool { * @param string[] $types * @return bool * - * This function walks through the ownCloud directory and loads all apps + * This function walks through the Nextcloud directory and loads all apps * it can find. A directory contains an app if the file /appinfo/info.xml * exists. * @@ -385,28 +383,6 @@ public static function getCurrentApp(): string { } } - /** - * @param string $type - * @return array - */ - public static function getForms(string $type): array { - $forms = []; - switch ($type) { - case 'admin': - $source = self::$adminForms; - break; - case 'personal': - $source = self::$personalForms; - break; - default: - return []; - } - foreach ($source as $form) { - $forms[] = include $form; - } - return $forms; - } - /** * @param array $entry * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface @@ -611,7 +587,7 @@ private static function adjustVersionParts(string $version1, string $version2): } /** - * Check whether the current ownCloud version matches the given + * Check whether the current Nextcloud version matches the given * application's version requirements. * * The comparison is made based on the number of parts that the @@ -621,7 +597,7 @@ private static function adjustVersionParts(string $version1, string $version2): * This means that it's possible to specify "requiremin" => 6 * and "requiremax" => 6 and it will still match ownCloud 6.0.3. * - * @param string $ocVersion ownCloud version to check against + * @param string $ocVersion Nextcloud version to check against * @param array $appInfo app info (from xml) * * @return boolean true if compatible, otherwise false