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 <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-09-17 14:41:25 +02:00
Родитель fe9981fad7
Коммит f5b73d2c77
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 45FAE7268762B400
5 изменённых файлов: 6 добавлений и 116 удалений

Просмотреть файл

@ -20,7 +20,6 @@ use OCP\IUser;
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 @@ class AdminSettingsController extends Controller {
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('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
$sectionName = str_replace('</h2>', '', $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();
}
}

Просмотреть файл

@ -75,7 +75,7 @@ trait CommonSettingsTrait {
/** @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;
}

Просмотреть файл

@ -18,7 +18,6 @@ use OCP\IRequest;
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 @@ class PersonalSettingsController extends Controller {
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('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
$sectionName = str_replace('</h2>', '', $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();
}
}

Просмотреть файл

@ -260,9 +260,7 @@ class Manager implements IManager {
$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 @@ class Manager implements IManager {
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
*/

Просмотреть файл

@ -26,12 +26,10 @@ use function OCP\Log\logger;
/**
* 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 @@ class OC_App {
* @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 @@ class OC_App {
}
}
/**
* @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 @@ class OC_App {
}
/**
* 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 @@ class OC_App {
* 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