diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-07-24 14:47:15 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2023-08-02 12:37:35 +0200 |
commit | a840e8c6e5a0d7b7c3a371776fd395976b2c2fdf (patch) | |
tree | 07e234084db1ffd1323289dbefa3f503de7f2b72 /apps | |
parent | 8ec1926aba549eeaea872d7dd2fcb69592b3a3bc (diff) | |
download | nextcloud-server-a840e8c6e5a0d7b7c3a371776fd395976b2c2fdf.tar.gz nextcloud-server-a840e8c6e5a0d7b7c3a371776fd395976b2c2fdf.zip |
AI admin settings: Add save mechanism
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings/appinfo/routes.php | 1 | ||||
-rw-r--r-- | apps/settings/lib/Controller/AISettingsController.php | 66 | ||||
-rw-r--r-- | apps/settings/lib/Settings/Admin/ArtificialIntelligence.php | 2 | ||||
-rw-r--r-- | apps/settings/src/components/AdminAI.vue | 45 |
4 files changed, 39 insertions, 75 deletions
diff --git a/apps/settings/appinfo/routes.php b/apps/settings/appinfo/routes.php index 938842dd576..e238510b1a7 100644 --- a/apps/settings/appinfo/routes.php +++ b/apps/settings/appinfo/routes.php @@ -75,6 +75,7 @@ return [ ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST' , 'root' => ''], ['name' => 'TwoFactorSettings#index', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'GET' , 'root' => ''], ['name' => 'TwoFactorSettings#update', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'PUT' , 'root' => ''], + ['name' => 'AISettings#update', 'url' => '/settings/api/admin/ai', 'verb' => 'PUT' , 'root' => ''], ['name' => 'Help#help', 'url' => '/settings/help/{mode}', 'verb' => 'GET', 'defaults' => ['mode' => ''] , 'root' => ''], diff --git a/apps/settings/lib/Controller/AISettingsController.php b/apps/settings/lib/Controller/AISettingsController.php index 53aca66c946..2c443c1a771 100644 --- a/apps/settings/lib/Controller/AISettingsController.php +++ b/apps/settings/lib/Controller/AISettingsController.php @@ -1,14 +1,6 @@ <?php /** - * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> + * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net> * * @license AGPL-3.0 * @@ -36,70 +28,40 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Mail\IMailer; +use function GuzzleHttp\Promise\queue; class AISettingsController extends Controller { - /** @var IL10N */ - private $l10n; - /** @var IConfig */ - private $config; - /** @var IUserSession */ - private $userSession; - /** @var IMailer */ - private $mailer; - /** @var IURLGenerator */ - private $urlGenerator; - /** * @param string $appName * @param IRequest $request - * @param IL10N $l10n * @param IConfig $config - * @param IUserSession $userSession - * @param IURLGenerator $urlGenerator, - * @param IMailer $mailer */ - public function __construct($appName, - IRequest $request, - IL10N $l10n, - IConfig $config, - IUserSession $userSession, - IURLGenerator $urlGenerator, - IMailer $mailer) { + public function __construct( + $appName, + IRequest $request, + private IConfig $config, + ) { parent::__construct($appName, $request); - $this->l10n = $l10n; - $this->config = $config; - $this->userSession = $userSession; - $this->urlGenerator = $urlGenerator; - $this->mailer = $mailer; } /** * Sets the email settings * - * @PasswordConfirmationRequired * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence) * * @param array $settings * @return DataResponse */ - public function setAISettings($settings) { - $params = get_defined_vars(); - $configs = []; - foreach ($params as $key => $value) { - $configs[$key] = empty($value) ? null : $value; - } - - // Delete passwords from config in case no auth is specified - if ($params['mail_smtpauth'] !== 1) { - $configs['mail_smtpname'] = null; - $configs['mail_smtppassword'] = null; + public function update($settings) { + $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.translation_provider_preferences']; + foreach ($keys as $key) { + if (!isset($settings[$key])) { + continue; + } + $this->config->setAppValue('core', $key, json_encode($settings[$key])); } - $this->config->setSystemValues($configs); - - $this->config->setAppValue('core', 'emailTestSuccessful', '0'); - return new DataResponse(); } } diff --git a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php index d33802d6c45..ad5425d8ded 100644 --- a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php +++ b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php @@ -157,7 +157,7 @@ class ArtificialIntelligence implements IDelegatedSettings { public function getAuthorizedAppConfig(): array { return [ - 'core' => ['/ai_.*/'], + 'core' => ['/ai..*/'], ]; } } diff --git a/apps/settings/src/components/AdminAI.vue b/apps/settings/src/components/AdminAI.vue index f11cb0c3da0..649c484c70a 100644 --- a/apps/settings/src/components/AdminAI.vue +++ b/apps/settings/src/components/AdminAI.vue @@ -2,8 +2,10 @@ <div> <NcSettingsSection :title="t('settings', 'Machine translation')" :description="t('settings', 'Machine translation can be implemented by different apps. Here you can define the precedence of the machine translation apps you have installed at the moment.')"> - <draggable v-model="settings['ai.translation_provider_preferences']"> - <div v-for="(providerClass, i) in settings['ai.translation_provider_preferences']" :key="providerClass" class="draggable__item"><span class="draggable__number">{{i+1}}</span> {{ translationProviders.find(p => p.class === providerClass)?.name }}</div> + <draggable v-model="settings['ai.translation_provider_preferences']" @change="saveChanges"> + <div v-for="(providerClass, i) in settings['ai.translation_provider_preferences']" :key="providerClass" class="draggable__item"> + <span class="draggable__number">{{ i+1 }}</span> {{ translationProviders.find(p => p.class === providerClass)?.name }} + </div> </draggable> </NcSettingsSection> <NcSettingsSection :title="t('settings', 'Speech-To-Text')" @@ -13,7 +15,8 @@ :checked.sync="settings['ai.stt_provider']" :value="provider.class" name="stt_provider" - type="radio"> + type="radio" + @update:checked="saveChanges"> {{ provider.name }} </NcCheckboxRadioSwitch> </template> @@ -29,9 +32,16 @@ <h3>{{ t('settings', 'Task:') }} {{ getTaskType(type).name }}</h3> <p>{{ getTaskType(type).description }}</p> <p> </p> - <NcSelect v-model="settings['ai.textprocessing_provider_preferences'][type]" :clearable="false" :options="textProcessingProviders.filter(p => p.taskType === type).map(p => p.class)"> - <template #option="{label}">{{ textProcessingProviders.find(p => p.class === label)?.name }}</template> - <template #selected-option="{label}">{{ textProcessingProviders.find(p => p.class === label)?.name }}</template> + <NcSelect v-model="settings['ai.textprocessing_provider_preferences'][type]" + :clearable="false" + :options="textProcessingProviders.filter(p => p.taskType === type).map(p => p.class)" + @change="saveChanges"> + <template #option="{label}"> + {{ textProcessingProviders.find(p => p.class === label)?.name }} + </template> + <template #selected-option="{label}"> + {{ textProcessingProviders.find(p => p.class === label)?.name }} + </template> </NcSelect> <p> </p> </template> @@ -74,24 +84,15 @@ export default { } }, methods: { - saveChanges() { + async saveChanges() { this.loading = true - - const data = { - enforced: this.enforced, - enforcedGroups: this.enforcedGroups, - excludedGroups: this.excludedGroups, + const data = this.settings + try { + await axios.put(generateUrl('/settings/api/admin/ai'), data) + } catch (err) { + console.error('could not save changes', err) } - axios.put(generateUrl('/settings/api/admin/twofactorauth'), data) - .then(resp => resp.data) - .then(state => { - this.state = state - this.dirty = false - }) - .catch(err => { - console.error('could not save changes', err) - }) - .then(() => { this.loading = false }) + this.loading = false }, getTaskType(type) { if (!Array.isArray(this.textProcessingTaskTypes)) { |