Skip to content

Commit a60f71b

Browse files
Merge pull request #49727 from nextcloud/feat/make-tasks-types-toggleable
Feat: make taskprocessing task types toggleable
2 parents d2923aa + 75e64e2 commit a60f71b

File tree

13 files changed

+201
-17
lines changed

13 files changed

+201
-17
lines changed

apps/settings/lib/Controller/AISettingsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
*/
3939
#[AuthorizedAdminSetting(settings: ArtificialIntelligence::class)]
4040
public function update($settings) {
41-
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
41+
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences','ai.taskprocessing_type_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
4242
foreach ($keys as $key) {
4343
if (!isset($settings[$key])) {
4444
continue;

apps/settings/lib/Settings/Admin/ArtificialIntelligence.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Psr\Container\ContainerExceptionInterface;
2525
use Psr\Container\ContainerInterface;
2626
use Psr\Container\NotFoundExceptionInterface;
27+
use Psr\Log\LoggerInterface;
2728

2829
class ArtificialIntelligence implements IDelegatedSettings {
2930
public function __construct(
@@ -36,6 +37,7 @@ public function __construct(
3637
private ContainerInterface $container,
3738
private \OCP\TextToImage\IManager $text2imageManager,
3839
private \OCP\TaskProcessing\IManager $taskProcessingManager,
40+
private LoggerInterface $logger,
3941
) {
4042
}
4143

@@ -113,12 +115,14 @@ public function getForm() {
113115
}
114116
}
115117
$taskProcessingTaskTypes = [];
116-
foreach ($this->taskProcessingManager->getAvailableTaskTypes() as $taskTypeId => $taskTypeDefinition) {
118+
$taskProcessingTypeSettings = [];
119+
foreach ($this->taskProcessingManager->getAvailableTaskTypes(true) as $taskTypeId => $taskTypeDefinition) {
117120
$taskProcessingTaskTypes[] = [
118121
'id' => $taskTypeId,
119122
'name' => $taskTypeDefinition['name'],
120123
'description' => $taskTypeDefinition['description'],
121124
];
125+
$taskProcessingTypeSettings[$taskTypeId] = true;
122126
}
123127

124128
$this->initialState->provideInitialState('ai-stt-providers', $sttProviders);
@@ -135,14 +139,29 @@ public function getForm() {
135139
'ai.textprocessing_provider_preferences' => $textProcessingSettings,
136140
'ai.text2image_provider' => count($text2imageProviders) > 0 ? $text2imageProviders[0]['id'] : null,
137141
'ai.taskprocessing_provider_preferences' => $taskProcessingSettings,
142+
'ai.taskprocessing_type_preferences' => $taskProcessingTypeSettings,
138143
];
139144
foreach ($settings as $key => $defaultValue) {
140145
$value = $defaultValue;
141146
$json = $this->config->getAppValue('core', $key, '');
142147
if ($json !== '') {
143-
$value = json_decode($json, true);
148+
try {
149+
$value = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
150+
} catch (\JsonException $e) {
151+
$this->logger->error('Failed to get settings. JSON Error in ' . $key, ['exception' => $e]);
152+
if ($key === 'ai.taskprocessing_type_preferences') {
153+
$value = [];
154+
foreach ($taskProcessingTypeSettings as $taskTypeId => $taskTypeValue) {
155+
$value[$taskTypeId] = false;
156+
}
157+
$settings[$key] = $value;
158+
}
159+
continue;
160+
}
161+
144162
switch ($key) {
145163
case 'ai.taskprocessing_provider_preferences':
164+
case 'ai.taskprocessing_type_preferences':
146165
case 'ai.textprocessing_provider_preferences':
147166
// fill $value with $defaultValue values
148167
$value = array_merge($defaultValue, $value);

apps/settings/src/components/AdminAI.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
<div :key="type">
1111
<h3>{{ t('settings', 'Task:') }} {{ type.name }}</h3>
1212
<p>{{ type.description }}</p>
13-
<p>&nbsp;</p>
13+
<NcCheckboxRadioSwitch v-model="settings['ai.taskprocessing_type_preferences'][type.id]"
14+
type="switch"
15+
@update:modelValue="saveChanges">
16+
{{ t('settings', 'Enable') }}
17+
</NcCheckboxRadioSwitch>
1418
<NcSelect v-model="settings['ai.taskprocessing_provider_preferences'][type.id]"
1519
class="provider-select"
1620
:clearable="false"
21+
:disabled="!settings['ai.taskprocessing_type_preferences'][type.id]"
1722
:options="taskProcessingProviders.filter(p => p.taskType === type.id).map(p => p.id)"
1823
@input="saveChanges">
1924
<template #option="{label}">
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-License-Identifier: AGPL-3.0-or-later
5+
*/
6+
namespace OC\Core\Command\TaskProcessing;
7+
8+
use OC\Core\Command\Base;
9+
use OCP\IConfig;
10+
use OCP\TaskProcessing\IManager;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
class EnabledCommand extends Base {
16+
public function __construct(
17+
protected IManager $taskProcessingManager,
18+
private IConfig $config,
19+
) {
20+
parent::__construct();
21+
}
22+
23+
protected function configure() {
24+
$this
25+
->setName('taskprocessing:task-type:set-enabled')
26+
->setDescription('Enable or disable a task type')
27+
->addArgument(
28+
'task-type-id',
29+
InputArgument::REQUIRED,
30+
'ID of the task type to configure'
31+
)
32+
->addArgument(
33+
'enabled',
34+
InputArgument::REQUIRED,
35+
'status of the task type availability. Set 1 to enable and 0 to disable.'
36+
);
37+
parent::configure();
38+
}
39+
40+
protected function execute(InputInterface $input, OutputInterface $output): int {
41+
$enabled = (bool)$input->getArgument('enabled');
42+
$taskType = $input->getArgument('task-type-id');
43+
$json = $this->config->getAppValue('core', 'ai.taskprocessing_type_preferences');
44+
try {
45+
if ($json === '') {
46+
$taskTypeSettings = [];
47+
} else {
48+
$taskTypeSettings = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
49+
}
50+
51+
$taskTypeSettings[$taskType] = $enabled;
52+
53+
$this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskTypeSettings));
54+
$this->writeArrayInOutputFormat($input, $output, $taskTypeSettings);
55+
return 0;
56+
} catch (\JsonException $e) {
57+
throw new \JsonException('Error in TaskType DB entry');
58+
}
59+
60+
}
61+
}

core/register_command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
$application->add(Server::get(Command\FilesMetadata\Get::class));
148148

149149
$application->add(Server::get(Command\TaskProcessing\GetCommand::class));
150+
$application->add(Server::get(Command\TaskProcessing\EnabledCommand::class));
150151
$application->add(Server::get(Command\TaskProcessing\ListCommand::class));
151152
$application->add(Server::get(Command\TaskProcessing\Statistics::class));
152153

dist/settings-vue-settings-admin-ai.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-admin-ai.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@
12671267
'OC\\Core\\Command\\SystemTag\\Delete' => $baseDir . '/core/Command/SystemTag/Delete.php',
12681268
'OC\\Core\\Command\\SystemTag\\Edit' => $baseDir . '/core/Command/SystemTag/Edit.php',
12691269
'OC\\Core\\Command\\SystemTag\\ListCommand' => $baseDir . '/core/Command/SystemTag/ListCommand.php',
1270+
'OC\\Core\\Command\\TaskProcessing\\EnabledCommand' => $baseDir . '/core/Command/TaskProcessing/EnabledCommand.php',
12701271
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => $baseDir . '/core/Command/TaskProcessing/GetCommand.php',
12711272
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => $baseDir . '/core/Command/TaskProcessing/ListCommand.php',
12721273
'OC\\Core\\Command\\TaskProcessing\\Statistics' => $baseDir . '/core/Command/TaskProcessing/Statistics.php',

lib/composer/composer/autoload_psr4.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
'OC\\' => array($baseDir . '/lib/private'),
1111
'OCP\\' => array($baseDir . '/lib/public'),
1212
'NCU\\' => array($baseDir . '/lib/unstable'),
13+
'Bamarni\\Composer\\Bin\\' => array($vendorDir . '/bamarni/composer-bin-plugin/src'),
1314
'' => array($baseDir . '/lib/private/legacy'),
1415
);

lib/composer/composer/autoload_static.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
2121
array (
2222
'NCU\\' => 4,
2323
),
24+
'B' =>
25+
array (
26+
'Bamarni\\Composer\\Bin\\' => 21,
27+
),
2428
);
2529

2630
public static $prefixDirsPsr4 = array (
@@ -40,6 +44,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
4044
array (
4145
0 => __DIR__ . '/../../..' . '/lib/unstable',
4246
),
47+
'Bamarni\\Composer\\Bin\\' =>
48+
array (
49+
0 => __DIR__ . '/..' . '/bamarni/composer-bin-plugin/src',
50+
),
4351
);
4452

4553
public static $fallbackDirsPsr4 = array (
@@ -1308,6 +1316,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
13081316
'OC\\Core\\Command\\SystemTag\\Delete' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Delete.php',
13091317
'OC\\Core\\Command\\SystemTag\\Edit' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Edit.php',
13101318
'OC\\Core\\Command\\SystemTag\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/SystemTag/ListCommand.php',
1319+
'OC\\Core\\Command\\TaskProcessing\\EnabledCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/EnabledCommand.php',
13111320
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/GetCommand.php',
13121321
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/ListCommand.php',
13131322
'OC\\Core\\Command\\TaskProcessing\\Statistics' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/Statistics.php',

0 commit comments

Comments
 (0)