add admin actions: remove cache, export configuration

This commit is contained in:
Simon Vieille 2020-10-14 16:14:50 +02:00
parent 731d4f826b
commit 5e894f9f08
Signed by: deblan
GPG key ID: 03383D15A1D31745
5 changed files with 128 additions and 6 deletions

View file

@ -19,10 +19,12 @@
return [
'routes' => [
['name' => 'Css#stylesheet', 'url' => '/css/stylesheet', 'verb' => 'GET'],
['name' => 'Js#script', 'url' => '/js/script', 'verb' => 'GET'],
['name' => 'Js#config', 'url' => '/js/config', 'verb' => 'GET'],
['name' => 'Nav#items', 'url' => '/nav/items', 'verb' => 'GET'],
['name' => 'PersonalSetting#valueSet', 'url' => '/personalSetting/valueSet', 'verb' => 'POST'],
['name' => 'Css#stylesheet', 'url' => '/css/stylesheet', 'verb' => 'GET'],
['name' => 'Js#script', 'url' => '/js/script', 'verb' => 'GET'],
['name' => 'Js#config', 'url' => '/js/config', 'verb' => 'GET'],
['name' => 'Nav#items', 'url' => '/nav/items', 'verb' => 'GET'],
['name' => 'PersonalSetting#valueSet', 'url' => '/personalSetting/valueSet', 'verb' => 'POST'],
['name' => 'AdminSetting#removeCache', 'url' => '/admin/cache/remove', 'verb' => 'GET'],
['name' => 'AdminSetting#exportConfiguration', 'url' => '/admin/config/export', 'verb' => 'GET'],
],
];

View file

@ -0,0 +1,92 @@
<?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;
use OCA\SideMenu\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
class AdminSettingController extends Controller
{
/**
* @var IConfig
*/
protected $config;
/**
* @var IURLGenerator
*/
protected $urlGenerator;
public function __construct($appName, IRequest $request, IConfig $config, IURLGenerator $urlGenerator)
{
parent::__construct($appName, $request);
$this->config = $config;
$this->urlGenerator = $urlGenerator;
}
/**
* @NoCSRFRequired
*
* @return RedirectResponse
*/
public function removeCache()
{
$this->config->setAppValue(Application::APP_ID, 'cache-categories', '[]');
return new RedirectResponse($this->urlGenerator->linkToRoute('settings.AdminSettings.index', [
'section' => Application::APP_ID,
]).'#more');
}
/**
* @NoCSRFRequired
*
* @return Response
*/
public function exportConfiguration()
{
$keys = $this->config->getAppKeys(Application::APP_ID);
$config = [];
$excludedKeys = [
'cache',
'cache-categories',
];
foreach ($keys as $key) {
if (in_array($key, $excludedKeys)) {
continue;
}
$config[$key] = $this->config->getAppValue(Application::APP_ID, $key);
}
return new DataDownloadResponse(
json_encode($config, JSON_PRETTY_PRINT),
'config.json',
'text/json'
);
}
}

View file

@ -59,3 +59,5 @@
"Use the avatar instead of the logo": "Verwenden Sie den Avatar anstelle des Logos"
"You do not have permission to change the settings.": "Sie haben keine Berechtigung zum Ändern der Einstellungen."
"Force this configuration to users": "Erzwingen Sie diese Konfiguration für Benutzer"
"Export the configuration": "Exportieren Sie die Konfiguration"
"Remove the cache": "Entfernen Sie den Cache"

View file

@ -59,3 +59,5 @@
"Use the avatar instead of the logo": "Utiliser l'avatar à la place du logo"
"You do not have permission to change the settings.": "Vous n'avez pas la permission de changer les paramètres."
"Force this configuration to users": "Forcer cette configuration aux utilisateurs"
"Export the configuration": "Exporter la configuration"
"Remove the cache": "Supprimer le cache"

View file

@ -16,9 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use OCP\IURLGenerator;
use OCP\IConfig;
use OCA\SideMenu\AppInfo\Application;
script('side_menu', 'admin');
style('side_menu', 'admin');
$urlGenerator = \OC::$server[IURLGenerator::class];
$cacheSize = floor(mb_strlen(\OC::$server[IConfig::class]->getAppValue(Application::APP_ID, 'cache-categories', ''), '8bit') / 1024);
$choicesYesNo = [
'No' => '0',
'Yes' => '1',
@ -30,6 +37,7 @@ $choicesSizes = [
'Normal' => 'normal',
'Big' => 'big',
];
?>
<div id="side-menu-section">
@ -488,9 +496,25 @@ $choicesSizes = [
<input type="hidden" id="side-menu-cache" name="cache" value="<?php print_unescaped($_['cache']); ?>" class="side-menu-setting">
<button id="side-menu-save" class="btn btn-primary"><?php p($l->t('Save')); ?></button>
<button id="side-menu-save" class="btn btn-info">
<?php p($l->t('Save')); ?>
</button>
<span id="side-menu-message" class="msg"></span>
</div>
<div class="section" id="more">
<a href="<?php echo $urlGenerator->linkToRoute('side_menu.AdminSetting.exportConfiguration') ?>" target="_blank">
<button class="btn btn-primary" >
<?php p($l->t('Export the configuration')); ?>
</button>
</a>
<a href="<?php echo $urlGenerator->linkToRoute('side_menu.AdminSetting.removeCache') ?>">
<button class="btn btn-primary" >
<?php p($l->t('Remove the cache')); ?> (<?php echo $cacheSize ?> Kb)
</button>
</a>
<div style="height: 30px"></div>