Skip to content

Commit 7f8475c

Browse files
committed
feat(lexicon): set/get current preset from controller
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent d5417d6 commit 7f8475c

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

apps/settings/appinfo/routes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
['name' => 'TwoFactorSettings#index', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'GET' , 'root' => ''],
5757
['name' => 'TwoFactorSettings#update', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'PUT' , 'root' => ''],
5858
['name' => 'AISettings#update', 'url' => '/settings/api/admin/ai', 'verb' => 'PUT' , 'root' => ''],
59+
5960
['name' => 'Preset#getPreset', 'url' => '/settings/preset', 'verb' => 'GET' , 'root' => ''],
61+
['name' => 'Preset#getCurrentPreset', 'url' => '/settings/preset/current', 'verb' => 'GET' , 'root' => ''],
62+
['name' => 'Preset#setCurrentPreset', 'url' => '/settings/preset/current', 'verb' => 'POST' , 'root' => ''],
6063

6164
['name' => 'Help#help', 'url' => '/settings/help/{mode}', 'verb' => 'GET', 'defaults' => ['mode' => ''] , 'root' => ''],
6265

apps/settings/lib/Controller/PresetController.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCP\AppFramework\Controller;
1414
use OCP\AppFramework\Http\Attribute\OpenAPI;
1515
use OCP\AppFramework\Http\DataResponse;
16+
use OCP\Config\Lexicon\Preset;
1617
use OCP\IRequest;
1718

1819
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
@@ -26,8 +27,26 @@ public function __construct(
2627
parent::__construct($appName, $request);
2728
}
2829

30+
public function getCurrentPreset(): DataResponse {
31+
return new DataResponse($this->presetManager->getLexiconPreset()->name);
32+
}
33+
34+
public function setCurrentPreset(string $presetName): DataResponse {
35+
foreach (Preset::cases() as $case) {
36+
if (strtolower($case->name) === strtolower($presetName)) {
37+
$this->presetManager->setLexiconPreset($case);
38+
}
39+
}
40+
return $this->getCurrentPreset();
41+
}
42+
2943
public function getPreset(): DataResponse {
30-
return new DataResponse($this->presetManager->retrieveLexiconPreset());
44+
return new DataResponse(
45+
[
46+
'preset' => $this->presetManager->retrieveLexiconPreset(),
47+
'apps' => $this->presetManager->retrieveLexiconPresetApps()
48+
]
49+
);
3150
}
3251

3352
}

core/Command/Config/Preset.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected function configure() {
3030
->setDescription('Select a config preset')
3131
->addArgument('preset', InputArgument::OPTIONAL, 'Preset to use for all unset config values', '')
3232
->addOption('list', '', InputOption::VALUE_NONE, 'display available preset')
33+
->addOption('apps', '', InputOption::VALUE_NONE, 'return list of enabled/disabled apps when switching preset')
3334
->addOption('compare', '', InputOption::VALUE_NONE, 'compare preset');
3435
}
3536

@@ -40,6 +41,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4041
return self::SUCCESS;
4142
}
4243

44+
if ($input->getOption('apps')) {
45+
$this->writeArrayInOutputFormat($input, $output, $this->presetManager->retrieveLexiconPresetApps());
46+
return self::SUCCESS;
47+
}
48+
4349
if ($input->getOption('compare')) {
4450
$list = $this->presetManager->retrieveLexiconPreset();
4551
if ($input->getOption('output') === 'plain') {

lib/private/Config/PresetManager.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ private function installApp(string $appId): void {
183183
}
184184
}
185185

186+
/**
187+
* return list of apps that are enabled/disabled when switching current Preset
188+
*
189+
* @return array{CLUB: {enabled: string[], disabled: string[]}, FAMILY: {enabled: string[], disabled: string[]}, LARGE: {enabled: string[], disabled: string[]}, MEDIUM: {enabled: string[], disabled: string[]}, NONE: {enabled: string[], disabled: string[]}, PRIVATE: {enabled: string[], disabled: string[]}, SCHOOL: {enabled: string[], disabled: string[]}, SHARED: {enabled: string[], disabled: string[]}, SMALL: {enabled: string[], disabled: string[]}, UNIVERSITY: {enabled: string[], disabled: string[]}}
190+
*/
191+
public function retrieveLexiconPresetApps(): array {
192+
$apps = [];
193+
foreach (Preset::cases() as $case) {
194+
$apps[$case->name] = $this->getPresetApps($case);
195+
}
196+
197+
return $apps;
198+
}
199+
186200
/**
187201
* get listing of enabled/disabled app from Preset
188202
*

0 commit comments

Comments
 (0)