Skip to content

Commit

Permalink
Add a setting to set web as default for oC10 on a user basis
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Dec 20, 2021
1 parent 7647b32 commit 180f8c5
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ endif
.PHONY: ocx-app-config
ocx-app-config:
cp -R packages/web-integration-oc10/appinfo $(dist_dir)
cp -R packages/web-integration-oc10/js $(dist_dir)
cp -R packages/web-integration-oc10/lib $(dist_dir)
cp -R packages/web-integration-oc10/templates $(dist_dir)

.PHONY: ocx-app-bundle
ocx-app-bundle:
Expand Down
3 changes: 3 additions & 0 deletions packages/web-integration-oc10/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ For feedback and bug reports, please use the [public issue tracker](https://gith
<dependencies>
<owncloud min-version="10.8" max-version="10" />
</dependencies>
<settings>
<personal>OCA\Web\Settings\Personal</personal>
</settings>
<screenshot>https://raw.githubusercontent.com/owncloud/screenshots/master/web/oc_web.png</screenshot>
</info>
2 changes: 2 additions & 0 deletions packages/web-integration-oc10/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'routes' => [
['name' => 'Index#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'],
['name' => 'Settings#getWebDefaultConfig', 'url' => '/settings/default', 'verb' => 'GET'],
['name' => 'Settings#setWebDefaultConfig', 'url' => '/settings/default', 'verb' => 'POST'],
[
'name' => 'Files#getFile',
'url' => '/{path}',
Expand Down
20 changes: 20 additions & 0 deletions packages/web-integration-oc10/js/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$(document).ready(function () {
$.get(OC.generateUrl('/apps/web/settings/default'), function(data){
$('#newDesignDefault').prop('checked', data.isDefault);
});

$('#newDesignDefault').change(function() {
var that = this;

$.post(OC.generateUrl('/apps/web/settings/default'), { isDefault: this.checked }, function(data, status){
if (status === 'success' && that.checked) {
var text = t(
'web',
'The new design has been set as default. Click <a href="{url}">here</a> to go to your files.',
{ url: OC.getProtocol() + '://' + OC.getHost() + OC.getRootPath() }
);
OC.Notification.showHtml(text);
}
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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\JSONResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;

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

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

/**
* @var IUserSession
*/
private $userSession;

/**
* @param string $appName
* @param IRequest $request an instance of the request
* @param IUserSession $userSession
* @param IConfig $config
*/
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
IConfig $config
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->userSession = $userSession;
}


/**
* Get the web default config.
*
* @NoAdminRequired
*
* @return JSONResponse
*/
public function getWebDefaultConfig() {
$user = $this->userSession->getUser();
$defaultAppSetting = $this->config->getUserValue($user->getUID(), 'core', 'defaultapp', null);
$webIsDefault = $defaultAppSetting === 'web';
return new JSONResponse(['isDefault' => $webIsDefault]);
}

/**
* Set the web default config.
*
* @NoAdminRequired
*
* @return JSONResponse
*/
public function setWebDefaultConfig() {
$value = \filter_var($this->request->getParam('isDefault'), FILTER_VALIDATE_BOOLEAN);
$user = $this->userSession->getUser();
$configToSet = $value === true ? 'web' : null;
if (!$configToSet) {
$this->config->deleteUserValue($user->getUID(), 'core', 'defaultapp');
} else {
$this->config->setUserValue($user->getUID(), 'core', 'defaultapp', $configToSet);
}

return new JSONResponse([]);
}
}
57 changes: 57 additions & 0 deletions packages/web-integration-oc10/lib/Settings/Personal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* @author Jannik Stehle <jstehle@owncloud.com>
* @author Jan Ackermann <jackermann@owncloud.com>
*
* @copyright Copyright (c) 2021, ownCloud GmbH
* @license GPL-2.0
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Web\Settings;

use OCP\Settings\ISettings;
use OCP\Template;

class Personal implements ISettings {

/**
* The panel controller method that returns a template to the UI
*
* @return \OCP\AppFramework\Http\TemplateResponse | \OCP\Template
*/
public function getPanel() {
return new Template('web', 'settings/personal');
}

/**
* A string to identify the section in the UI / HTML and URL
*
* @return string
*/
public function getSectionID() {
return 'additional';
}

/**
* The number used to order the section in the UI.
*
* @return int between 0 and 100, with 100 being the highest priority
*/
public function getPriority() {
return 0;
}
}
31 changes: 31 additions & 0 deletions packages/web-integration-oc10/templates/settings/personal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @author Jannik Stehle <jstehle@owncloud.com>
* @author Jan Ackermann <jackermann@owncloud.com>
*
* @copyright Copyright (c) 2021, ownCloud GmbH
* @license GPL-2.0
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
script('web', 'settings');
/** @var $l OC_L10N */
?>
<div class="section" id="guests">
<h2>Web</h2>
<div>
<input type="checkbox" id="newDesignDefault"/><label for="newDesignDefault"><?php p($l->t('Set new design as default'));?></label>
</div>
</div>

0 comments on commit 180f8c5

Please sign in to comment.