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 index route for the OC10 integration #5201

Merged
merged 4 commits into from
Jun 9, 2021
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
8 changes: 8 additions & 0 deletions changelog/unreleased/bugfix-oc10-index-route
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Add index route for the OC10 integration

Added an index route for the OC10 integration which gets called when opening http://your-server/index.php/apps/web.
The route basically redirects to the same URL while appending /index.html, as this is the correct URL for
accessing the Web UI. Setting Web as default layout would result in an endless redirect loop otherwise.

https://github.com/owncloud/web/pull/5201
https://github.com/owncloud/core/issues/38799
3 changes: 2 additions & 1 deletion packages/web-integration-oc10/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
$this,
[
'routes' => [
['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'],
['name' => 'Index#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'],
[
'name' => 'Files#getFile',
'url' => '/{path}',
Expand Down
92 changes: 92 additions & 0 deletions packages/web-integration-oc10/lib/Controller/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* @author Jannik Stehle <jstehle@owncloud.com>
* @author Jan Ackermann <jackermann@owncloud.com>
*
* @copyright Copyright (c) 2021, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Web\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;

/**
* Class IndexController
*
* @package OCA\Web\Controller
*/
class IndexController extends Controller {

/**
* @var IConfig
*/
private $config;
/**
* @var IL10N
*/
private $l10n;

/**
* IndexController constructor.
*
* @param string $appName
* @param IRequest $request
* @param IConfig $config
* @param IL10N $l10n
*/
public function __construct(string $appName, IRequest $request, IConfig $config, IL10N $l10n) {
parent::__construct($appName, $request);
$this->config = $config;
$this->l10n = $l10n;
}

/**
* Loads the WebUI index page according to the web.baseUrl config.
* Then appends "/index.html" to the URL as this is needed to load the page properly.
*
* @PublicPage
* @NoCSRFRequired
*
* @return RedirectResponse | TemplateResponse
*/
public function index(): Response {
$webBaseUrl = $this->config->getSystemValue('web.baseUrl', null);
if (!$webBaseUrl) {
// Check the old phoenix.baseUrl system key to provide compatibility across
// the name change from phoenix to web.
$webBaseUrl = \OC::$server->getConfig()->getSystemValue('phoenix.baseUrl', null);
}

if ($webBaseUrl) {
$webBaseUrl = \rtrim($webBaseUrl, '/') . '/index.html';
return new RedirectResponse($webBaseUrl);
}

return new TemplateResponse(
'core', 'error',
[
"errors" => [["error" => $this->l10n->t('Unable to reach the WebURL. Please contact your administrator.')]]
], 'guest'
);
}
}