Skip to content

Return proper boolean and do not save enabled state in db - #9111

Merged
MorrisJobke merged 2 commits into
masterfrom
use-proper-bool-user-disabled-state
Apr 9, 2018
Merged

Return proper boolean and do not save enabled state in db#9111
MorrisJobke merged 2 commits into
masterfrom
use-proper-bool-user-disabled-state

Conversation

@skjnldsv

Copy link
Copy Markdown
Member

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.

@skjnldsvskjnldsv added bug 3. to review Waiting for reviews labels Apr 6, 2018
@skjnldsvskjnldsv added this to the Nextcloud 14 milestone Apr 6, 2018
@skjnldsvskjnldsv self-assigned this Apr 6, 2018
@skjnldsvskjnldsv 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;

@schiessleschiessleApr 6, 2018

Copy link
Copy Markdown
Member

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';

@skjnldsvskjnldsvApr 6, 2018

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
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.

@skjnldsvskjnldsvApr 6, 2018

Copy link
Copy Markdown
MemberAuthor

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! :)

@schiessleschiessleApr 6, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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

@schiessleschiessleApr 7, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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?

@skjnldsvskjnldsv 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
skjnldsvforce-pushed the use-proper-bool-user-disabled-state branch from 444a667 to eae5576CompareApril 9, 2018 09:26
@codecov

codecovBot commented Apr 9, 2018

Copy link
Copy Markdown

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 FilesCoverage ΔComplexity Δ
lib/private/User/User.php32.91% <0%> (-55.77%)62 <3> (ø)
apps/provisioning_api/lib/Controller/AUserData.php61.84% <100%> (ø)14 <0> (ø)⬇️
...s/dav/lib/Connector/Sabre/Exception/FileLocked.php0% <0%> (-100%)3% <0%> (ø)
lib/private/SystemTag/ManagerFactory.php0% <0%> (-100%)3% <0%> (ø)
lib/private/Repair/NC11/FixMountStorages.php0% <0%> (-100%)5% <0%> (ø)
apps/files_sharing/lib/External/MountProvider.php0% <0%> (-100%)4% <0%> (ø)
lib/private/Route/CachingRouter.php0% <0%> (-100%)3% <0%> (ø)
apps/files_versions/lib/AppInfo/Application.php0% <0%> (-100%)2% <0%> (ø)
apps/files_versions/lib/Command/Expire.php0% <0%> (-100%)3% <0%> (ø)
lib/private/Files/Cache/Wrapper/JailPropagator.php0% <0%> (-100%)1% <0%> (ø)
... and 369 more

@skjnldsv
skjnldsv requested a review from schiessleApril 9, 2018 09:32
@skjnldsv

Copy link
Copy Markdown
MemberAuthor

Here you go @schiessle :)

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

Labels

2. developingWork in progressbug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@skjnldsv@rullzer@nickvergessen@schiessle@MorrisJobke