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

fix: Remove legacy settings forms #48138

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
36 changes: 0 additions & 36 deletions apps/settings/lib/Controller/AdminSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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('%(<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();
}
}
2 changes: 1 addition & 1 deletion apps/settings/lib/Controller/CommonSettingsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
34 changes: 0 additions & 34 deletions apps/settings/lib/Controller/PersonalSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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('%(<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();
}
}
18 changes: 1 addition & 17 deletions lib/private/Settings/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))];
}

Expand All @@ -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
*/
Expand Down
32 changes: 4 additions & 28 deletions lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading