From a840e8c6e5a0d7b7c3a371776fd395976b2c2fdf Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 24 Jul 2023 14:47:15 +0200 Subject: [PATCH] AI admin settings: Add save mechanism Signed-off-by: Marcel Klehr --- apps/settings/appinfo/routes.php | 1 + .../lib/Controller/AISettingsController.php | 66 ++++--------------- .../Settings/Admin/ArtificialIntelligence.php | 2 +- 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 @@ - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst - * @author Daniel Kesselberg - * @author Joas Schilling - * @author Lukas Reschke - * @author Morris Jobke - * @author Roeland Jago Douma + * @copyright Copyright (c) 2023 Marcel Klehr * * @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 @@
- -
{{i+1}} {{ translationProviders.find(p => p.class === providerClass)?.name }}
+ +
+ {{ i+1 }} {{ translationProviders.find(p => p.class === providerClass)?.name }} +
+ type="radio" + @update:checked="saveChanges"> {{ provider.name }} @@ -29,9 +32,16 @@

{{ t('settings', 'Task:') }} {{ getTaskType(type).name }}

{{ getTaskType(type).description }}

 

- - - + + +

 

@@ -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)) { -- 2.39.5