Split replaceAccount from addAccountToCache
ClosedPublic

Authored by valeriymalov on May 12 2018, 3:38 PM.

Details

Summary

We were accidentally overwriting first account in the model with
currently logged in user after polling AccountsService

BUG: 336994

Test Plan

check if kcmshell5 user_manager lists mutliple users on cold boot

Diff Detail

Repository
R128 User Manager
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
valeriymalov created this revision.May 12 2018, 3:38 PM
Restricted Application added a project: Plasma. ยท View Herald TranscriptMay 12 2018, 3:38 PM
Restricted Application added a subscriber: plasma-devel. ยท View Herald Transcript
valeriymalov requested review of this revision.May 12 2018, 3:38 PM

Bulletproof steps to reproduce for me:

  1. System Settings > Account Details > User Manager > Create a new user
  2. Give the new user admin rights
  3. Log out
  4. Log in as that the new user
  5. Go to System Settings > Account Details > User Manager

The user you were just logged in as before isn't listed!

This patch fixes that bug for me. The patch looks sane, but this code seems fragile and really needs an autotest...

davidedmundson requested changes to this revision.May 15 2018, 10:13 AM
davidedmundson added a subscriber: davidedmundson.

It might work, but it's overly messy.

We have addAccountToCache which has an argument pos, which determines if we're adding or replacing.

Then we have a second replace method replaceAccount which also does replacing.
So we have two ways of replacing an entry both and both are used once, and they're both identical except for a very subtle change on usage of m_userPath.

I'm sure we can do something better.

This revision now requires changes to proceed.May 15 2018, 10:13 AM

We have addAccountToCache which has an argument pos, which determines if we're adding or replacing.

I've actually removed this bit, addAccountToCache now only adds accounts (either inserts at pos or appends)

Though I agree that current code is probably a bit fragile, maybe the model can be changed the way there's no need in manual ordering or at least storing "fake user". If that seems like a better approach I can look into that.

src/lib/accountmodel.cpp
361

On second look, I might have misunderstood.

This isn't a replace, it's just making sure the current user is at the top?

valeriymalov added inline comments.May 15 2018, 1:13 PM
src/lib/accountmodel.cpp
361

Yes. Replace code was added to addAccountToCache at some point because of the "modify new user entry" logic (line 434 in the original), which broke addAccountToCache here. This patch moves the replace code out to replaceAccount so addAccountToCache does what the name says again.

In fact replaceAccount technically adds a user too but does it by replacing fake user entry ("+ Add new user" in the list) with it ๐Ÿ˜• This whole bit might be worth refactoring to kick fake user entry out of model containers & add tests, but I don't think I'll be able to do it this week.

davidedmundson accepted this revision.May 15 2018, 1:15 PM
This revision is now accepted and ready to land.May 15 2018, 1:15 PM

Any chance we could land this on the stable branch?

Any chance we could land this on the stable branch?

Well, it does apply cleanly to Plasma/5.12 branch and it still works, but I don't really know if there's a special procedure for landing patches onto stable branches

Any chance we could land this on the stable branch?

Well, it does apply cleanly to Plasma/5.12 branch and it still works, but I don't really know if there's a special procedure for landing patches onto stable branches

https://community.kde.org/Infrastructure/Phabricator#Landing_on_the_.22Stable_branch.22

I meant it more in terms of "not landing it right before next stable release" :v But if it's okay to land now I can land it right now

The next stable release is 5.12.6, which is scheduled for 2018-06-27 (actually after 5.13!). So I think you should be fine.

https://community.kde.org/Schedules/Plasma_5

This revision was automatically updated to reflect the committed changes.