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

add personal addtional setting section #22144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/settings/appinfo/info.xml
Expand Up @@ -36,6 +36,7 @@
<personal>OCA\Settings\Settings\Personal\Security\Password</personal>
<personal>OCA\Settings\Settings\Personal\Security\TwoFactor</personal>
<personal>OCA\Settings\Settings\Personal\Security\WebAuthn</personal>
<personal-section>OCA\Settings\Sections\Personal\Additional</personal-section>
<personal-section>OCA\Settings\Sections\Personal\PersonalInfo</personal-section>
<personal-section>OCA\Settings\Sections\Personal\Security</personal-section>
<personal-section>OCA\Settings\Sections\Personal\SyncClients</personal-section>
Expand Down
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Expand Up @@ -39,6 +39,7 @@
'OCA\\Settings\\Sections\\Admin\\Security' => $baseDir . '/../lib/Sections/Admin/Security.php',
'OCA\\Settings\\Sections\\Admin\\Server' => $baseDir . '/../lib/Sections/Admin/Server.php',
'OCA\\Settings\\Sections\\Admin\\Sharing' => $baseDir . '/../lib/Sections/Admin/Sharing.php',
'OCA\\Settings\\Sections\\Personal\\Additional' => $baseDir . '/../lib/Sections/Personal/Additional.php',
'OCA\\Settings\\Sections\\Personal\\PersonalInfo' => $baseDir . '/../lib/Sections/Personal/PersonalInfo.php',
'OCA\\Settings\\Sections\\Personal\\Security' => $baseDir . '/../lib/Sections/Personal/Security.php',
'OCA\\Settings\\Sections\\Personal\\SyncClients' => $baseDir . '/../lib/Sections/Personal/SyncClients.php',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_static.php
Expand Up @@ -54,6 +54,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\Sections\\Admin\\Security' => __DIR__ . '/..' . '/../lib/Sections/Admin/Security.php',
'OCA\\Settings\\Sections\\Admin\\Server' => __DIR__ . '/..' . '/../lib/Sections/Admin/Server.php',
'OCA\\Settings\\Sections\\Admin\\Sharing' => __DIR__ . '/..' . '/../lib/Sections/Admin/Sharing.php',
'OCA\\Settings\\Sections\\Personal\\Additional' => __DIR__ . '/..' . '/../lib/Sections/Personal/Additional.php',
'OCA\\Settings\\Sections\\Personal\\PersonalInfo' => __DIR__ . '/..' . '/../lib/Sections/Personal/PersonalInfo.php',
'OCA\\Settings\\Sections\\Personal\\Security' => __DIR__ . '/..' . '/../lib/Sections/Personal/Security.php',
'OCA\\Settings\\Sections\\Personal\\SyncClients' => __DIR__ . '/..' . '/../lib/Sections/Personal/SyncClients.php',
Expand Down
61 changes: 61 additions & 0 deletions apps/settings/lib/Sections/Personal/Additional.php
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Settings\Sections\Personal;

use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;

class Additional implements IIconSection {

/** @var IL10N */
private $l;

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(IL10N $l, IURLGenerator $urlGenerator) {
$this->l = $l;
$this->urlGenerator = $urlGenerator;
}

public function getIcon(): string {
return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg');
}

public function getID(): string {
return 'additional';
}

public function getName(): string {
return $this->l->t('Additional settings');
}

public function getPriority(): int {
return 98;
}
}
22 changes: 14 additions & 8 deletions lib/private/Settings/Manager.php
Expand Up @@ -260,11 +260,6 @@ public function getPersonalSections(): array {

$sections = [];

$legacyForms = \OC_App::getForms('personal');
if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
}

$appSections = $this->getSections('personal');

foreach ($appSections as $section) {
Expand All @@ -275,7 +270,10 @@ public function getPersonalSections(): array {

$sections[$section->getPriority()][] = $section;
}

$legacyForms = \OC_App::getForms('personal');
if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms) && !array_key_exists(98,$sections)) {
$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
}
ksort($sections);

return $sections;
Expand All @@ -301,14 +299,22 @@ private function hasLegacyPersonalSettingsToRender(array $forms): bool {
public function getPersonalSettings($section): array {
$settings = [];
$appSettings = $this->getSettings('personal', $section);


if (count($appSettings) == 1 && strcmp($section,'additional') === 0) {
// only empty addtional settings returned
$legacyForms = \OC_App::getForms('personal');
if (empty($legacyForms) || !$this->hasLegacyPersonalSettingsToRender($legacyForms)) {
// remove empty addtional setting
return [];
}
}

foreach ($appSettings as $setting) {
if (!isset($settings[$setting->getPriority()])) {
$settings[$setting->getPriority()] = [];
}
$settings[$setting->getPriority()][] = $setting;
}

ksort($settings);
return $settings;
}
Expand Down