Skip to content

Commit fa741df

Browse files
committed
Move help to controller
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 3f3705d commit fa741df

File tree

5 files changed

+109
-12
lines changed

5 files changed

+109
-12
lines changed

apps/settings/appinfo/routes.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@
8989
['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'],
9090
['name' => 'TwoFactorSettings#index', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'GET'],
9191
['name' => 'TwoFactorSettings#update', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'PUT'],
92+
93+
['name' => 'Help#help', 'url' => '/settings/help/{mode}', 'verb' => 'GET', 'defaults' => ['mode' => '']],
9294
]
9395
]);
94-
95-
/** @var $this \OCP\Route\IRouter */
96-
97-
// Settings pages
98-
$this->create('settings_help', '/settings/help')
99-
->actionInclude('settings/help.php');
100-

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'OCA\\Settings\\Controller\\ChangePasswordController' => $baseDir . '/../lib/Controller/ChangePasswordController.php',
2828
'OCA\\Settings\\Controller\\CheckSetupController' => $baseDir . '/../lib/Controller/CheckSetupController.php',
2929
'OCA\\Settings\\Controller\\CommonSettingsTrait' => $baseDir . '/../lib/Controller/CommonSettingsTrait.php',
30+
'OCA\\Settings\\Controller\\HelpController' => $baseDir . '/../lib/Controller/HelpController.php',
3031
'OCA\\Settings\\Controller\\LogSettingsController' => $baseDir . '/../lib/Controller/LogSettingsController.php',
3132
'OCA\\Settings\\Controller\\MailSettingsController' => $baseDir . '/../lib/Controller/MailSettingsController.php',
3233
'OCA\\Settings\\Controller\\PersonalSettingsController' => $baseDir . '/../lib/Controller/PersonalSettingsController.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ComposerStaticInitSettings
4242
'OCA\\Settings\\Controller\\ChangePasswordController' => __DIR__ . '/..' . '/../lib/Controller/ChangePasswordController.php',
4343
'OCA\\Settings\\Controller\\CheckSetupController' => __DIR__ . '/..' . '/../lib/Controller/CheckSetupController.php',
4444
'OCA\\Settings\\Controller\\CommonSettingsTrait' => __DIR__ . '/..' . '/../lib/Controller/CommonSettingsTrait.php',
45+
'OCA\\Settings\\Controller\\HelpController' => __DIR__ . '/..' . '/../lib/Controller/HelpController.php',
4546
'OCA\\Settings\\Controller\\LogSettingsController' => __DIR__ . '/..' . '/../lib/Controller/LogSettingsController.php',
4647
'OCA\\Settings\\Controller\\MailSettingsController' => __DIR__ . '/..' . '/../lib/Controller/MailSettingsController.php',
4748
'OCA\\Settings\\Controller\\PersonalSettingsController' => __DIR__ . '/..' . '/../lib/Controller/PersonalSettingsController.php',
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
4+
*
5+
* @author Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
declare(strict_types=1);
24+
25+
namespace OCA\Settings\Controller;
26+
27+
use OCP\AppFramework\Controller;
28+
use OCP\AppFramework\Http\ContentSecurityPolicy;
29+
use OCP\AppFramework\Http\TemplateResponse;
30+
use OCP\IGroupManager;
31+
use OCP\INavigationManager;
32+
use OCP\IRequest;
33+
use OCP\IURLGenerator;
34+
use OCP\IUserSession;
35+
36+
class HelpController extends Controller {
37+
38+
/** @var INavigationManager */
39+
private $navigationManager;
40+
/** @var IUserSession */
41+
private $urlGenerator;
42+
/** @var IGroupManager */
43+
private $groupManager;
44+
45+
/** @var string */
46+
private $userId;
47+
48+
public function __construct(
49+
string $appName,
50+
IRequest $request,
51+
INavigationManager $navigationManager,
52+
IURLGenerator $urlGenerator,
53+
string $userId,
54+
IGroupManager $groupManager
55+
) {
56+
parent::__construct($appName, $request);
57+
$this->navigationManager = $navigationManager;
58+
$this->urlGenerator = $urlGenerator;
59+
$this->userId = $userId;
60+
$this->groupManager = $groupManager;
61+
}
62+
63+
/**
64+
* @return TemplateResponse
65+
*
66+
* @NoCSRFRequired
67+
* @NoAdminRequired
68+
*/
69+
public function help(string $mode = 'user'): TemplateResponse {
70+
$this->navigationManager->setActiveEntry('help');
71+
72+
if(!isset($mode) || $mode !== 'admin') {
73+
$mode = 'user';
74+
}
75+
76+
$documentationUrl = $this->urlGenerator->getAbsoluteURL(
77+
$this->urlGenerator->linkTo('core', 'doc/' . $mode . '/index.html')
78+
);
79+
80+
$urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
81+
$urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
82+
83+
$response = new TemplateResponse('settings', 'help', [
84+
'admin' => $this->groupManager->isAdmin($this->userId),
85+
'url' => $documentationUrl,
86+
'urlUserDocs' => $urlUserDocs,
87+
'urlAdminDocs' => $urlAdminDocs,
88+
'mode' => $mode,
89+
]);
90+
$policy = new ContentSecurityPolicy();
91+
$policy->addAllowedFrameDomain('\'self\'');
92+
$response->setContentSecurityPolicy($policy);
93+
return $response;
94+
95+
}
96+
97+
}

apps/settings/templates/help.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
<?php
2+
\OC_Util::addStyle( 'settings', "settings" );
3+
?>
14
<div id="app-navigation">
25
<ul>
3-
<?php if($_['admin']) { ?>
46
<li>
5-
<a class="icon-user <?php p($_['style1']); ?>"
6-
href="<?php print_unescaped($_['url1']); ?> class= "">
7+
<a class="icon-user <?php if ($_['mode'] === 'user') { p('active'); } ?>"
8+
href="<?php print_unescaped($_['urlUserDocs']); ?>">
79
<?php p($l->t('User documentation')); ?>
810
</a>
911
</li>
12+
<?php if($_['admin']) { ?>
1013
<li>
11-
<a class="icon-user-admin <?php p($_['style2']); ?>"
12-
href="<?php print_unescaped($_['url2']); ?>">
14+
<a class="icon-user-admin <?php if ($_['mode'] === 'admin') { p('active'); } ?>"
15+
href="<?php print_unescaped($_['urlAdminDocs']); ?>">
1316
<?php p($l->t('Administrator documentation')); ?>
1417
</a>
1518
</li>

0 commit comments

Comments
 (0)