Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IUserPreferences #47658

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

IUserPreferences #47658

wants to merge 3 commits into from

Conversation

ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Aug 31, 2024

  • replace IConfig's preferences-related method
  • tests

@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 6d81b97 to a9e2a38 Compare August 31, 2024 22:30
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 8edb1c1 to e510535 Compare September 2, 2024 02:31
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/UserPreferences.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 2 times, most recently from 32c209d to b80315b Compare September 2, 2024 14:57
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl marked this pull request as ready for review September 30, 2024 16:26
@ArtificialOwl ArtificialOwl added the 3. to review Waiting for reviews label Sep 30, 2024
@ArtificialOwl ArtificialOwl added this to the Nextcloud 31 milestone Sep 30, 2024
$value = $cache[$app][$key];
try {
$this->decryptSensitiveValue($userId, $app, $key, $value);
$value = $this->convertTypedValue($value, $typedAs ?? $this->getValueType($userId, (string)$app, $key, $lazy));

Check failure

Code scanning / Psalm

RedundantCast

Redundant cast to string
* @param string $value preference value
* @param bool $caseInsensitive non-case-sensitive search, only works if $value is a string
*
* @return list<string>

Check failure

Code scanning / Psalm

MoreSpecificReturnType

The declared return type 'list<string>' for OC\UserPreferences::searchUsersByValueString is more specific than the inferred return type 'array<array-key, mixed>'
* @since 31.0.0
*/
public function searchUsersByValueString(string $app, string $key, string $value, bool $caseInsensitive = false): array {
return $this->searchUsersByTypedValue($app, $key, $value, $caseInsensitive);

Check failure

Code scanning / Psalm

LessSpecificReturnStatement

The type 'array<array-key, mixed>' is more general than the declared return type 'list<string>' for OC\UserPreferences::searchUsersByValueString
* @param string $key preference key
* @param array $values list of preference values
*
* @return list<string>

Check failure

Code scanning / Psalm

MoreSpecificReturnType

The declared return type 'list<string>' for OC\UserPreferences::searchUsersByValues is more specific than the inferred return type 'array<array-key, mixed>'
* @since 31.0.0
*/
public function searchUsersByValues(string $app, string $key, array $values): array {
return $this->searchUsersByTypedValue($app, $key, $values);

Check failure

Code scanning / Psalm

LessSpecificReturnStatement

The type 'array<array-key, mixed>' is more general than the declared return type 'list<string>' for OC\UserPreferences::searchUsersByValues
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 3 times, most recently from cc4a1ff to da769f0 Compare October 3, 2024 13:52
lib/private/AllConfig.php Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, please split that file before it gets out of hand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I thought about it .. even started to split into 3:

  • IUserPreferences for basic getters/setters on user preferences.
  • IUserPreferencesExtra that extendsIUserPreferences and add all direct value manipulation on the cache like is[Lazy|Sensitive|Indexed], update[Lazy|Sensitive|Indexed], ...
  • IAdvancedUserPreferences for search

but it makes everything bad. I will keep it like this (using a single file) until PHP can define a class from multiple files :-]

Please note that there is a lot of single line method that request 10 lines of PHPDoc ...

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopped at line 1050 of UserPreferences, to be continued…

I dislike the sensitive flag thing, it should be a bool just like lazy so that all types var can be typed to the enum.

lib/private/AllConfig.php Outdated Show resolved Hide resolved
lib/private/AllConfig.php Outdated Show resolved Hide resolved
lib/private/AllConfig.php Outdated Show resolved Hide resolved
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid cluttering OC namespace please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move to \OC\UserPreferences\Manager ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving everything into \OC\Config and \OCP\Config

lib/private/UserPreferences.php Outdated Show resolved Hide resolved
lib/private/UserPreferences.php Outdated Show resolved Hide resolved
lib/private/UserPreferences.php Outdated Show resolved Hide resolved
lib/private/UserPreferences.php Outdated Show resolved Hide resolved
lib/private/UserPreferences.php Outdated Show resolved Hide resolved
lib/private/UserPreferences.php Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's keep it private for one major version to have the flexibility to change the API down the road?

Copy link
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note this somewhere (feel free to ignore):
For me the name if a bit confusing (I know the DB table is called like that),
as we have IConfig and IAppConfig I would expect IUserConfig as the name.

@ArtificialOwl
Copy link
Member Author

Just to note this somewhere (feel free to ignore): For me the name if a bit confusing (I know the DB table is called like that), as we have IConfig and IAppConfig I would expect IUserConfig as the name.

While I think grouping API might happens if we start today to create this API within \[OC|OCP]\Config/` but I am still fine with IUserPreferences

lib/public/UserPreferences/ValueType.php Outdated Show resolved Hide resolved
lib/private/AllConfig.php Outdated Show resolved Hide resolved
lib/private/UserPreferences.php Outdated Show resolved Hide resolved
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving everything into \OC\Config and \OCP\Config

@ArtificialOwl ArtificialOwl force-pushed the enh/noid/user-preferences branch 4 times, most recently from 17eeef9 to 6a3a4a1 Compare October 21, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants