-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a setting to set web as default for oC10 on a user basis
- Loading branch information
1 parent
7647b32
commit 180f8c5
Showing
7 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); | ||
}); |
99 changes: 99 additions & 0 deletions
99
packages/web-integration-oc10/lib/Controller/SettingsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
packages/web-integration-oc10/templates/settings/personal.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |