side_menu/lib/Controller/PersonalSettingController.php

131 lines
3.2 KiB
PHP
Raw Normal View History

<?php
/**
* @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\SideMenu\Controller;
2021-02-03 10:15:59 +01:00
use OCA\SideMenu\AppInfo\Application;
use OCA\SideMenu\Service\ConfigProxy;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
class PersonalSettingController extends Controller
{
/**
2020-09-29 11:25:31 +02:00
* @var IConfig
*/
protected $config;
2020-09-29 11:25:31 +02:00
/**
* @var ConfigProxy
*/
protected $configProxy;
/**
* @var IUserSession
*/
2020-09-29 11:25:31 +02:00
protected $userSession;
public function __construct($appName, IRequest $request, IConfig $config, ConfigProxy $configProxy, IUserSession $userSession)
{
parent::__construct($appName, $request);
$this->config = $config;
$this->configProxy = $configProxy;
$this->userSession = $userSession;
}
/**
* @NoAdminRequired
2021-11-14 19:37:14 +01:00
* @NoCSRFRequired
*
2020-08-13 11:21:59 +02:00
* @param mixed $name
* @param mixed $value
*
* @return Response
*/
public function valueSet($name, $value)
{
$doSave = false;
$user = $this->userSession->getUser();
2020-08-13 11:21:59 +02:00
if ('enabled' === $name) {
$doSave = true;
if (!in_array($value, ['0', '1'])) {
$value = '1';
}
}
if ('target-blank-mode' === $name) {
2020-09-11 13:03:37 +02:00
$doSave = true;
if (!in_array($value, ['1', '2'])) {
$value = '1';
}
}
if ('target-blank-apps' === $name) {
$doSave = true;
$data = json_decode($value, true);
if (!is_array($data)) {
$doSave = false;
} else {
foreach ($data as $v) {
if (!is_string($v)) {
$doSave = false;
}
}
2020-09-11 13:03:37 +02:00
}
}
2020-08-13 11:21:59 +02:00
if ('top-menu-apps' === $name) {
$doSave = true;
$data = json_decode($value, true);
if (!is_array($data)) {
$doSave = false;
} else {
foreach ($data as $v) {
if (!is_string($v)) {
$doSave = false;
}
}
}
}
if ($this->configProxy->getAppValueBool('force', '0')) {
$doSave = false;
}
if ($doSave) {
$this->config->setUserValue($user->getUid(), Application::APP_ID, $name, $value);
return [
'name' => $name,
'value' => $value,
];
}
return [];
}
}