1010
1111use OCA \Settings \Settings \Admin \ArtificialIntelligence ;
1212use OCP \AppFramework \Controller ;
13+ use OCP \AppFramework \Http ;
1314use OCP \AppFramework \Http \Attribute \AuthorizedAdminSetting ;
1415use OCP \AppFramework \Http \DataResponse ;
1516use OCP \EventDispatcher \IEventDispatcher ;
@@ -30,7 +31,7 @@ public function __construct(
3031 }
3132
3233 /**
33- * Sets the email settings
34+ * Sets the AI settings
3435 *
3536 * @param array $settings
3637 * @return DataResponse
@@ -42,11 +43,16 @@ public function update($settings) {
4243 if (!isset ($ settings [$ key ])) {
4344 continue ;
4445 }
45- $ changed = $ this ->appConfig ->setValueString ('core ' , $ key , json_encode ($ settings [$ key ]), lazy: in_array ($ key , \OC \TaskProcessing \Manager::LAZY_CONFIG_KEYS , true ));
46+ try {
47+ $ value = json_encode ($ settings [$ key ], flags: \JSON_THROW_ON_ERROR );
48+ } catch (\JsonException ) {
49+ return new DataResponse (['error ' => "Setting value for ' $ key' must be JSON-compatible " ], Http::STATUS_BAD_REQUEST );
50+ }
51+ $ changed = $ this ->appConfig ->setValueString ('core ' , $ key , $ value , lazy: in_array ($ key , \OC \TaskProcessing \Manager::LAZY_CONFIG_KEYS , true ));
4652 if ($ changed ) {
4753 $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent (
4854 'AI configuration was changed by user %s: %s was set to %s ' ,
49- [$ this ->userId , $ key , json_encode ( $ settings [ $ key ]) ]
55+ [$ this ->userId , $ key , $ value ]
5056 ));
5157 }
5258 }
0 commit comments