1414use OC \AppFramework \Bootstrap \Coordinator ;
1515use OCP \Config \Exceptions \IncorrectTypeException ;
1616use OCP \Config \Exceptions \TypeConflictException ;
17+ use OCP \Config \Exceptions \UnacceptableValueException ;
1718use OCP \Config \Exceptions \UnknownKeyException ;
1819use OCP \Config \IUserConfig ;
1920use OCP \Config \Lexicon \Entry ;
@@ -1082,6 +1083,7 @@ public function setValueArray(
10821083 * @param ValueType $type value type
10831084 *
10841085 * @return bool TRUE if value was updated in database
1086+ * @throws UnacceptableValueException if lexicon does not validate value
10851087 * @throws TypeConflictException if type from database is not VALUE_MIXED and different from the requested one
10861088 * @see IUserConfig for explanation about lazy loading
10871089 */
@@ -1100,12 +1102,19 @@ private function setTypedValue(
11001102 }
11011103
11021104 $ this ->assertParams ($ userId , $ app , $ key );
1103- if (!$ this ->matchAndApplyLexiconDefinition ($ userId , $ app , $ key , $ lazy , $ type , $ flags )) {
1105+ /** @var ?Entry $lexiconEntry */
1106+ $ lexiconEntry = null ;
1107+ if (!$ this ->matchAndApplyLexiconDefinition ($ userId , $ app , $ key , $ lazy , $ type , $ flags , lexiconEntry: $ lexiconEntry )) {
11041108 // returns false as database is not updated
11051109 return false ;
11061110 }
11071111 $ this ->loadConfig ($ userId , $ lazy );
11081112
1113+ // lexicon entry might have requested a check on the value
1114+ if ($ lexiconEntry ?->onSetConfirmation() !== null && !$ lexiconEntry ->onSetConfirmation ()($ value )) {
1115+ return false ;
1116+ }
1117+
11091118 $ inserted = $ refreshCache = false ;
11101119 $ origValue = $ value ;
11111120 $ sensitive = $ this ->isFlagged (self ::FLAG_SENSITIVE , $ flags );
@@ -1937,6 +1946,7 @@ private function matchAndApplyLexiconDefinition(
19371946 ValueType &$ type = ValueType::MIXED ,
19381947 int &$ flags = 0 ,
19391948 ?string &$ default = null ,
1949+ ?Entry &$ lexiconEntry = null ,
19401950 ): bool {
19411951 $ configDetails = $ this ->getConfigDetailsFromLexicon ($ app );
19421952 if (array_key_exists ($ key , $ configDetails ['aliases ' ]) && !$ this ->ignoreLexiconAliases ) {
@@ -1953,18 +1963,18 @@ private function matchAndApplyLexiconDefinition(
19531963 return true ;
19541964 }
19551965
1956- /** @var Entry $configValue */
1957- $ configValue = $ configDetails ['entries ' ][$ key ];
1966+ /** @var Entry $lexiconEntry */
1967+ $ lexiconEntry = $ configDetails ['entries ' ][$ key ];
19581968 if ($ type === ValueType::MIXED ) {
19591969 // we overwrite if value was requested as mixed
1960- $ type = $ configValue ->getValueType ();
1961- } elseif ($ configValue ->getValueType () !== $ type ) {
1970+ $ type = $ lexiconEntry ->getValueType ();
1971+ } elseif ($ lexiconEntry ->getValueType () !== $ type ) {
19621972 throw new TypeConflictException ('The user config key ' . $ app . '/ ' . $ key . ' is typed incorrectly in relation to the config lexicon ' );
19631973 }
19641974
1965- $ lazy = $ configValue ->isLazy ();
1966- $ flags = $ configValue ->getFlags ();
1967- if ($ configValue ->isDeprecated ()) {
1975+ $ lazy = $ lexiconEntry ->isLazy ();
1976+ $ flags = $ lexiconEntry ->getFlags ();
1977+ if ($ lexiconEntry ->isDeprecated ()) {
19681978 $ this ->logger ->notice ('User config key ' . $ app . '/ ' . $ key . ' is set as deprecated. ' );
19691979 }
19701980
@@ -1976,7 +1986,7 @@ private function matchAndApplyLexiconDefinition(
19761986
19771987 // only look for default if needed, default from Lexicon got priority if not overwritten by admin
19781988 if ($ default !== null ) {
1979- $ default = $ this ->getSystemDefault ($ app , $ configValue ) ?? $ configValue ->getDefault ($ this ->presetManager ->getLexiconPreset ()) ?? $ default ;
1989+ $ default = $ this ->getSystemDefault ($ app , $ lexiconEntry ) ?? $ lexiconEntry ->getDefault ($ this ->presetManager ->getLexiconPreset ()) ?? $ default ;
19801990 }
19811991
19821992 // returning false will make get() returning $default and set() not changing value in database
0 commit comments