Skip to content

Conversation

@skjnldsv
Copy link
Member

@skjnldsv skjnldsv commented Apr 6, 2018

Since we store booleans as string in the db, let's check agains it so we also return a boolean in the json and not a string like "true".

Also, I introduced the removal of the "enabled" key when we enable a user since no config = true.

@skjnldsv skjnldsv added bug 3. to review Waiting for reviews labels Apr 6, 2018
@skjnldsv skjnldsv added this to the Nextcloud 14 milestone Apr 6, 2018
@skjnldsv skjnldsv self-assigned this Apr 6, 2018
@skjnldsv skjnldsv mentioned this pull request Apr 6, 2018
34 tasks
if( $this->groupManager->isAdmin($currentLoggedInUser->getUID())
|| $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true');
$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', true) === true;
Copy link
Member

@schiessle schiessle Apr 6, 2018

Choose a reason for hiding this comment

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

getUserValue will return a string, right?
So you need to compare the string in order to return a bool:
$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';

Copy link
Member Author

@skjnldsv skjnldsv Apr 6, 2018

Choose a reason for hiding this comment

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

It will return a string or the fallback which is a boolean, so true===true?true:false :)

Copy link
Member

Choose a reason for hiding this comment

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

and if the string is 'true' your statement will be evaluated to false.

Copy link
Member Author

@skjnldsv skjnldsv Apr 6, 2018

Choose a reason for hiding this comment

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

it won't be true since we're not storing the enabled state in the database anymore if true.
Nonetheless, I need to think about the old config! So, fair point! :)

Copy link
Member

@schiessle schiessle Apr 6, 2018

Choose a reason for hiding this comment

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

so if the user set it to true we remove the complete row in the database and if the user set it to false we add it again with the value 'false'? Does this makes sense, sounds totally confusing to me. But maybe I miss some context here.

(Now I saw the second part of the code and re-read the headline, so my assumption was correct. It is probably to late for me to do reviews 😉 But I still think it is totally confusing and inconsistent with all other settings. I would just continue to store 'true' and 'false' and compare the strings to convert it back to bool)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, a freshly created user is enabled, but doesn't have a userValue 'enabled' set.
It makes sense to create an entry when we disable one. But If we still keeps the userValue to 'true' in the db, it's where it gets confusing. We have users enabled without a userValue in the db and user enabled WITH a userValue in the db.

I say, let's put only one state, disabled: true or enabled by default

Copy link
Member

@schiessle schiessle Apr 7, 2018

Choose a reason for hiding this comment

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

We already discussed in the past that maybe apps (and the server) should write all config settings with the default value to the database on first start. I think this is still something we should explore. Because defining the default value in multiple areas in the code is super error prone. But that's a side topic.

Regarding this PR my opinion is that a database entry should be able to contain all supported values. If someone looks at the db (or the config.php by the way), sees a value 'false' and switched it to 'true', it should work. Having dark magic that any entry is false by comparing strings with bool in the code and having no entry at all is true is highly confusing and not consistent across Nextcloud. Already the idea comparing a string with a bool is a really bad one. Because X years down the road someone will look at the code, come to the conclusion that this is a bug (rightfully), fix it and break anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I can do the other way around :)
Your point is good. My goal was not to have two different states for the enabled.

So, adding the config on user creation seems good to you?

@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Apr 6, 2018
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv skjnldsv force-pushed the use-proper-bool-user-disabled-state branch from 444a667 to eae5576 Compare April 9, 2018 09:26
@codecov
Copy link

codecov bot commented Apr 9, 2018

Codecov Report

Merging #9111 into master will decrease coverage by 20.36%.
The diff coverage is 33.33%.

@@              Coverage Diff              @@
##             master    #9111       +/-   ##
=============================================
- Coverage     51.94%   31.57%   -20.37%     
- Complexity    25297    25298        +1     
=============================================
  Files          1604     1604               
  Lines         95095    95087        -8     
  Branches       1388     1388               
=============================================
- Hits          49397    30026    -19371     
- Misses        45698    65061    +19363
Impacted Files Coverage Δ Complexity Δ
lib/private/User/User.php 32.91% <0%> (-55.77%) 62 <3> (ø)
apps/provisioning_api/lib/Controller/AUserData.php 61.84% <100%> (ø) 14 <0> (ø) ⬇️
...s/dav/lib/Connector/Sabre/Exception/FileLocked.php 0% <0%> (-100%) 3% <0%> (ø)
lib/private/SystemTag/ManagerFactory.php 0% <0%> (-100%) 3% <0%> (ø)
lib/private/Repair/NC11/FixMountStorages.php 0% <0%> (-100%) 5% <0%> (ø)
apps/files_sharing/lib/External/MountProvider.php 0% <0%> (-100%) 4% <0%> (ø)
lib/private/Route/CachingRouter.php 0% <0%> (-100%) 3% <0%> (ø)
apps/files_versions/lib/AppInfo/Application.php 0% <0%> (-100%) 2% <0%> (ø)
apps/files_versions/lib/Command/Expire.php 0% <0%> (-100%) 3% <0%> (ø)
lib/private/Files/Cache/Wrapper/JailPropagator.php 0% <0%> (-100%) 1% <0%> (ø)
... and 369 more

@skjnldsv skjnldsv requested a review from schiessle April 9, 2018 09:32
@skjnldsv
Copy link
Member Author

skjnldsv commented Apr 9, 2018

Here you go @schiessle :)

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv skjnldsv force-pushed the use-proper-bool-user-disabled-state branch from 4979188 to 8b9bd37 Compare April 9, 2018 13:13
@MorrisJobke MorrisJobke merged commit acbcc60 into master Apr 9, 2018
@MorrisJobke MorrisJobke deleted the use-proper-bool-user-disabled-state branch April 9, 2018 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants