Skip to content

Commit b2589c8

Browse files
authored
Merge pull request #39776 from nextcloud/backport/39680/stable27
2 parents 946305d + 71db3ff commit b2589c8

File tree

79 files changed

+3089
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3089
-55
lines changed

apps/settings/appinfo/info.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<settings>
2020
<admin>OCA\Settings\Settings\Admin\Mail</admin>
2121
<admin>OCA\Settings\Settings\Admin\Overview</admin>
22+
<admin>OCA\Settings\Settings\Admin\ArtificialIntelligence</admin>
2223
<admin>OCA\Settings\Settings\Admin\Server</admin>
2324
<admin>OCA\Settings\Settings\Admin\Sharing</admin>
2425
<admin>OCA\Settings\Settings\Admin\Security</admin>
@@ -27,6 +28,7 @@
2728
<admin-section>OCA\Settings\Sections\Admin\Delegation</admin-section>
2829
<admin-section>OCA\Settings\Sections\Admin\Groupware</admin-section>
2930
<admin-section>OCA\Settings\Sections\Admin\Overview</admin-section>
31+
<admin-section>OCA\Settings\Sections\Admin\ArtificialIntelligence</admin-section>
3032
<admin-section>OCA\Settings\Sections\Admin\Security</admin-section>
3133
<admin-section>OCA\Settings\Sections\Admin\Server</admin-section>
3234
<admin-section>OCA\Settings\Sections\Admin\Sharing</admin-section>

apps/settings/appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST' , 'root' => ''],
7676
['name' => 'TwoFactorSettings#index', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'GET' , 'root' => ''],
7777
['name' => 'TwoFactorSettings#update', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'PUT' , 'root' => ''],
78+
['name' => 'AISettings#update', 'url' => '/settings/api/admin/ai', 'verb' => 'PUT' , 'root' => ''],
7879

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

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'OCA\\Settings\\Activity\\Setting' => $baseDir . '/../lib/Activity/Setting.php',
1717
'OCA\\Settings\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
1818
'OCA\\Settings\\BackgroundJobs\\VerifyUserData' => $baseDir . '/../lib/BackgroundJobs/VerifyUserData.php',
19+
'OCA\\Settings\\Controller\\AISettingsController' => $baseDir . '/../lib/Controller/AISettingsController.php',
1920
'OCA\\Settings\\Controller\\AdminSettingsController' => $baseDir . '/../lib/Controller/AdminSettingsController.php',
2021
'OCA\\Settings\\Controller\\AppSettingsController' => $baseDir . '/../lib/Controller/AppSettingsController.php',
2122
'OCA\\Settings\\Controller\\AuthSettingsController' => $baseDir . '/../lib/Controller/AuthSettingsController.php',
@@ -42,6 +43,7 @@
4243
'OCA\\Settings\\Search\\AppSearch' => $baseDir . '/../lib/Search/AppSearch.php',
4344
'OCA\\Settings\\Search\\SectionSearch' => $baseDir . '/../lib/Search/SectionSearch.php',
4445
'OCA\\Settings\\Sections\\Admin\\Additional' => $baseDir . '/../lib/Sections/Admin/Additional.php',
46+
'OCA\\Settings\\Sections\\Admin\\ArtificialIntelligence' => $baseDir . '/../lib/Sections/Admin/ArtificialIntelligence.php',
4547
'OCA\\Settings\\Sections\\Admin\\Delegation' => $baseDir . '/../lib/Sections/Admin/Delegation.php',
4648
'OCA\\Settings\\Sections\\Admin\\Groupware' => $baseDir . '/../lib/Sections/Admin/Groupware.php',
4749
'OCA\\Settings\\Sections\\Admin\\Overview' => $baseDir . '/../lib/Sections/Admin/Overview.php',
@@ -56,6 +58,7 @@
5658
'OCA\\Settings\\Service\\AuthorizedGroupService' => $baseDir . '/../lib/Service/AuthorizedGroupService.php',
5759
'OCA\\Settings\\Service\\NotFoundException' => $baseDir . '/../lib/Service/NotFoundException.php',
5860
'OCA\\Settings\\Service\\ServiceException' => $baseDir . '/../lib/Service/ServiceException.php',
61+
'OCA\\Settings\\Settings\\Admin\\ArtificialIntelligence' => $baseDir . '/../lib/Settings/Admin/ArtificialIntelligence.php',
5962
'OCA\\Settings\\Settings\\Admin\\Delegation' => $baseDir . '/../lib/Settings/Admin/Delegation.php',
6063
'OCA\\Settings\\Settings\\Admin\\Mail' => $baseDir . '/../lib/Settings/Admin/Mail.php',
6164
'OCA\\Settings\\Settings\\Admin\\Overview' => $baseDir . '/../lib/Settings/Admin/Overview.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ComposerStaticInitSettings
3131
'OCA\\Settings\\Activity\\Setting' => __DIR__ . '/..' . '/../lib/Activity/Setting.php',
3232
'OCA\\Settings\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
3333
'OCA\\Settings\\BackgroundJobs\\VerifyUserData' => __DIR__ . '/..' . '/../lib/BackgroundJobs/VerifyUserData.php',
34+
'OCA\\Settings\\Controller\\AISettingsController' => __DIR__ . '/..' . '/../lib/Controller/AISettingsController.php',
3435
'OCA\\Settings\\Controller\\AdminSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AdminSettingsController.php',
3536
'OCA\\Settings\\Controller\\AppSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AppSettingsController.php',
3637
'OCA\\Settings\\Controller\\AuthSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AuthSettingsController.php',
@@ -57,6 +58,7 @@ class ComposerStaticInitSettings
5758
'OCA\\Settings\\Search\\AppSearch' => __DIR__ . '/..' . '/../lib/Search/AppSearch.php',
5859
'OCA\\Settings\\Search\\SectionSearch' => __DIR__ . '/..' . '/../lib/Search/SectionSearch.php',
5960
'OCA\\Settings\\Sections\\Admin\\Additional' => __DIR__ . '/..' . '/../lib/Sections/Admin/Additional.php',
61+
'OCA\\Settings\\Sections\\Admin\\ArtificialIntelligence' => __DIR__ . '/..' . '/../lib/Sections/Admin/ArtificialIntelligence.php',
6062
'OCA\\Settings\\Sections\\Admin\\Delegation' => __DIR__ . '/..' . '/../lib/Sections/Admin/Delegation.php',
6163
'OCA\\Settings\\Sections\\Admin\\Groupware' => __DIR__ . '/..' . '/../lib/Sections/Admin/Groupware.php',
6264
'OCA\\Settings\\Sections\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Sections/Admin/Overview.php',
@@ -71,6 +73,7 @@ class ComposerStaticInitSettings
7173
'OCA\\Settings\\Service\\AuthorizedGroupService' => __DIR__ . '/..' . '/../lib/Service/AuthorizedGroupService.php',
7274
'OCA\\Settings\\Service\\NotFoundException' => __DIR__ . '/..' . '/../lib/Service/NotFoundException.php',
7375
'OCA\\Settings\\Service\\ServiceException' => __DIR__ . '/..' . '/../lib/Service/ServiceException.php',
76+
'OCA\\Settings\\Settings\\Admin\\ArtificialIntelligence' => __DIR__ . '/..' . '/../lib/Settings/Admin/ArtificialIntelligence.php',
7477
'OCA\\Settings\\Settings\\Admin\\Delegation' => __DIR__ . '/..' . '/../lib/Settings/Admin/Delegation.php',
7578
'OCA\\Settings\\Settings\\Admin\\Mail' => __DIR__ . '/..' . '/../lib/Settings/Admin/Mail.php',
7679
'OCA\\Settings\\Settings\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Settings/Admin/Overview.php',

apps/settings/img/ai.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Marcel Klehr <[email protected]>
7+
*
8+
* @license AGPL-3.0
9+
*
10+
* This code is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License, version 3,
12+
* as published by the Free Software Foundation.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License, version 3,
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>
21+
*
22+
*/
23+
namespace OCA\Settings\Controller;
24+
25+
use OCP\AppFramework\Controller;
26+
use OCP\AppFramework\Http;
27+
use OCP\AppFramework\Http\DataResponse;
28+
use OCP\IConfig;
29+
use OCP\IL10N;
30+
use OCP\IRequest;
31+
use OCP\IURLGenerator;
32+
use OCP\IUserSession;
33+
use OCP\Mail\IMailer;
34+
use function GuzzleHttp\Promise\queue;
35+
36+
class AISettingsController extends Controller {
37+
38+
/**
39+
* @param string $appName
40+
* @param IRequest $request
41+
* @param IConfig $config
42+
*/
43+
public function __construct(
44+
$appName,
45+
IRequest $request,
46+
private IConfig $config,
47+
) {
48+
parent::__construct($appName, $request);
49+
}
50+
51+
/**
52+
* Sets the email settings
53+
*
54+
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence)
55+
*
56+
* @param array $settings
57+
* @return DataResponse
58+
*/
59+
public function update($settings) {
60+
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.translation_provider_preferences'];
61+
foreach ($keys as $key) {
62+
if (!isset($settings[$key])) {
63+
continue;
64+
}
65+
$this->config->setAppValue('core', $key, json_encode($settings[$key]));
66+
}
67+
68+
return new DataResponse();
69+
}
70+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Marcel Klehr <[email protected]>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
namespace OCA\Settings\Sections\Admin;
25+
26+
use OCP\IL10N;
27+
use OCP\IURLGenerator;
28+
use OCP\Settings\IIconSection;
29+
30+
class ArtificialIntelligence implements IIconSection {
31+
32+
/** @var IL10N */
33+
private $l;
34+
35+
/** @var IURLGenerator */
36+
private $urlGenerator;
37+
38+
public function __construct(IL10N $l, IURLGenerator $urlGenerator) {
39+
$this->l = $l;
40+
$this->urlGenerator = $urlGenerator;
41+
}
42+
43+
public function getIcon(): string {
44+
return $this->urlGenerator->imagePath('settings', 'ai.svg');
45+
}
46+
47+
public function getID(): string {
48+
return 'ai';
49+
}
50+
51+
public function getName(): string {
52+
return $this->l->t('Artificial Intelligence');
53+
}
54+
55+
public function getPriority(): int {
56+
return 40;
57+
}
58+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Marcel Klehr <[email protected]>
7+
*
8+
* @author Marcel Klehr <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCA\Settings\Settings\Admin;
27+
28+
use OCP\AppFramework\Http\TemplateResponse;
29+
use OCP\AppFramework\Services\IInitialState;
30+
use OCP\IConfig;
31+
use OCP\IL10N;
32+
use OCP\Settings\IDelegatedSettings;
33+
use OCP\SpeechToText\ISpeechToTextManager;
34+
use OCP\TextProcessing\IManager;
35+
use OCP\TextProcessing\IProvider;
36+
use OCP\TextProcessing\ITaskType;
37+
use OCP\Translation\ITranslationManager;
38+
use Psr\Container\ContainerExceptionInterface;
39+
use Psr\Container\ContainerInterface;
40+
use Psr\Container\NotFoundExceptionInterface;
41+
42+
class ArtificialIntelligence implements IDelegatedSettings {
43+
public function __construct(
44+
private IConfig $config,
45+
private IL10N $l,
46+
private IInitialState $initialState,
47+
private ITranslationManager $translationManager,
48+
private ISpeechToTextManager $sttManager,
49+
private IManager $textProcessingManager,
50+
private ContainerInterface $container,
51+
) {
52+
}
53+
54+
/**
55+
* @return TemplateResponse
56+
*/
57+
public function getForm() {
58+
$translationProviders = [];
59+
$translationPreferences = [];
60+
foreach ($this->translationManager->getProviders() as $provider) {
61+
$translationProviders[] = [
62+
'class' => $provider::class,
63+
'name' => $provider->getName(),
64+
];
65+
$translationPreferences[] = $provider::class;
66+
}
67+
68+
$sttProviders = [];
69+
foreach ($this->sttManager->getProviders() as $provider) {
70+
$sttProviders[] = [
71+
'class' => $provider::class,
72+
'name' => $provider->getName(),
73+
];
74+
}
75+
76+
$textProcessingProviders = [];
77+
/** @var array<class-string<ITaskType>, class-string<IProvider>> $textProcessingSettings */
78+
$textProcessingSettings = [];
79+
foreach ($this->textProcessingManager->getProviders() as $provider) {
80+
$textProcessingProviders[] = [
81+
'class' => $provider::class,
82+
'name' => $provider->getName(),
83+
'taskType' => $provider->getTaskType(),
84+
];
85+
$textProcessingSettings[$provider->getTaskType()] = $provider::class;
86+
}
87+
$textProcessingTaskTypes = [];
88+
foreach ($textProcessingSettings as $taskTypeClass => $providerClass) {
89+
/** @var ITaskType $taskType */
90+
try {
91+
$taskType = $this->container->get($taskTypeClass);
92+
} catch (NotFoundExceptionInterface $e) {
93+
continue;
94+
} catch (ContainerExceptionInterface $e) {
95+
continue;
96+
}
97+
$textProcessingTaskTypes[] = [
98+
'class' => $taskTypeClass,
99+
'name' => $taskType->getName(),
100+
'description' => $taskType->getDescription(),
101+
];
102+
}
103+
104+
$this->initialState->provideInitialState('ai-stt-providers', $sttProviders);
105+
$this->initialState->provideInitialState('ai-translation-providers', $translationProviders);
106+
$this->initialState->provideInitialState('ai-text-processing-providers', $textProcessingProviders);
107+
$this->initialState->provideInitialState('ai-text-processing-task-types', $textProcessingTaskTypes);
108+
109+
$settings = [
110+
'ai.stt_provider' => count($sttProviders) > 0 ? $sttProviders[0]['class'] : null,
111+
'ai.textprocessing_provider_preferences' => $textProcessingSettings,
112+
'ai.translation_provider_preferences' => $translationPreferences,
113+
];
114+
foreach ($settings as $key => $defaultValue) {
115+
$value = $defaultValue;
116+
$json = $this->config->getAppValue('core', $key, '');
117+
if ($json !== '') {
118+
$value = json_decode($json, true);
119+
switch($key) {
120+
case 'ai.textprocessing_provider_preferences':
121+
// fill $value with $defaultValue values
122+
$value = array_merge($defaultValue, $value);
123+
break;
124+
case 'ai.translation_provider_preferences':
125+
$value += array_diff($defaultValue, $value); // Add entries from $defaultValue that are not in $value to the end of $value
126+
break;
127+
default:
128+
break;
129+
}
130+
}
131+
$settings[$key] = $value;
132+
}
133+
134+
$this->initialState->provideInitialState('ai-settings', $settings);
135+
136+
return new TemplateResponse('settings', 'settings/admin/ai');
137+
}
138+
139+
/**
140+
* @return string the section ID, e.g. 'sharing'
141+
*/
142+
public function getSection() {
143+
return 'ai';
144+
}
145+
146+
/**
147+
* @return int whether the form should be rather on the top or bottom of
148+
* the admin section. The forms are arranged in ascending order of the
149+
* priority values. It is required to return a value between 0 and 100.
150+
*
151+
* E.g.: 70
152+
*/
153+
public function getPriority() {
154+
return 10;
155+
}
156+
157+
public function getName(): ?string {
158+
return $this->l->t('Artificial Intelligence');
159+
}
160+
161+
public function getAuthorizedAppConfig(): array {
162+
return [
163+
'core' => ['/ai..*/'],
164+
];
165+
}
166+
}

apps/settings/src/admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ window.addEventListener('DOMContentLoaded', () => {
227227
OC.SetupChecks.checkSetup(),
228228
OC.SetupChecks.checkGeneric(),
229229
OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), OC.theme.docPlaceholderUrl),
230-
OC.SetupChecks.checkDataProtected()
230+
OC.SetupChecks.checkDataProtected(),
231231
).then((check1, check2, check3, check4, check5, check6, check7, check8, check9, check10, check11) => {
232232
const messages = [].concat(check1, check2, check3, check4, check5, check6, check7, check8, check9, check10, check11)
233233
const $el = $('#postsetupchecks')

0 commit comments

Comments
 (0)