Calling mark_intro_complete doesn't respond correctly

Bug #1937138 reported by Huw Wilkins
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Fix Released
High
Björn Tillenius

Bug Description

When calling mark_intro_complete (https://github.com/maas/maas/blob/e70cca2fb81cf248ad1f080adade478973a7bfe4/src/maasserver/websockets/handlers/user.py#L194) there are two issues:

1. The API sends a response to `mark_intro_complete` that includes an out of date user (at the very least `sshkeys_count` is sent as `0` instead of the correct number).

2. The API does not send a `user.update` notify message to tell the client that the user data was changed.

Related branches

Revision history for this message
Bill Wear (billwear) wrote :

not able to test this ATM. leaving in New state.

Revision history for this message
Björn Tillenius (bjornt) wrote :

Can you include the steps that you take in the UI to reproduce this?

I think I see a problem, though. UserHandler.mark_intro_completed uses self.user, which might be out-of-date if you did operations, like adding an SSH key to the user.

Changed in maas:
status: New → Incomplete
Revision history for this message
Huw Wilkins (huwshimi) wrote :

To reproduce this:
- create a new user
- log in as that new user
- you should see the user intro
- open the network tab of your devtools and click on the messages list for the websocket (you may wish to clear the list so you can spot new messages)
- add an SSH key
- you should get a websocket user update message with should have `sshkeys_count: 1`
- click "Finish setup"
- you should see a message for user.mark_intro_complete and in the response message you should see `sshkeys_count: 0`

Revision history for this message
Björn Tillenius (bjornt) wrote :

Ok, thanks. That confirms my suspicion. The UserHandler shouldn't operate on self.user directly. It needs to get an up-to-date object from the db.

Changed in maas:
status: Incomplete → Triaged
importance: Undecided → High
tags: added: trivial
Changed in maas:
milestone: none → next
summary: - Calling mark_intro_complete does respond correctly
+ Calling mark_intro_complete doesn't respond correctly
Alberto Donato (ack)
Changed in maas:
status: Triaged → In Progress
assignee: nobody → Alberto Donato (ack)
Revision history for this message
Alberto Donato (ack) wrote :

The issue is that we currently cache sshkeys_count and machines_count for the user on the self.user object itself.

Since the object lives for the duration of the websocket connection, we need to keep the cache up to date.
For sshkeys we have to do that on keys creation, import and deletion. I suspect a similar issue might happen with machines count (which is harder to keep up to date since there's multiple places where the machine can be acquired/released).

I wonder if the UI really needs to always have these counts available. If they're only needed in specific cases, we could just fetch those instead of putting them on the user.

Changed in maas:
status: In Progress → Incomplete
tags: removed: api trivial
Revision history for this message
Huw Wilkins (huwshimi) wrote :

It looks like we only use user.machines_count in the user list in settings and user.sshkeys_count in the user list and machine deploy form.

We could fetch machines_count and sshkeys_count in those places but we'd need to be able to fetch them both for the authenticated user as well as for all users (in one call).

Revision history for this message
Alberto Donato (ack) wrote :

For the user listing page, it should be easy to add them.

But why is the ssh keys count needed for the machine deploy form?

Changed in maas:
status: Incomplete → New
status: New → Incomplete
Revision history for this message
Alberto Donato (ack) wrote :

Caching is also made tricky by the fact that we have 3 methods returning the state for the current user: user.auth_user, user.change_password and user.mark_intro_complete.

It'd be good if we could change things so that just the first one returns the user, others just perform changes.

The UI can call user.auth_user to get up to date info about the current user, and user.list to get all the users. In both cases we'd include the counts for machines and ssh keys.

Alberto Donato (ack)
Changed in maas:
status: Incomplete → Triaged
Revision history for this message
Huw Wilkins (huwshimi) wrote :

> But why is the ssh keys count needed for the machine deploy form?

It uses the ssh keys count to show a warning if the user has no keys: "Login will not be possible because no SSH keys have been added to your account. To add an SSH key, visit your account page."

> Caching is also made tricky by the fact that we have 3 methods returning the state for the current user: user.auth_user, user.change_password and user.mark_intro_complete.
>
> It'd be good if we could change things so that just the first one returns the user, others just perform changes.

That would work for us. If we get notify messages when the auth user changes then we wouldn't need to do anything with the responses from change_password and mark_intro_complete.

> The UI can call user.auth_user to get up to date info about the current user, and user.list to get all the users. In both cases we'd include the counts for machines and ssh keys.

This would be fine for initially getting the data, but we'd still need the notify messages for when the machine/ssh key counts change.

Changed in maas:
assignee: Alberto Donato (ack) → nobody
milestone: next → 3.3.0
Changed in maas:
assignee: nobody → Björn Tillenius (bjornt)
Changed in maas:
status: Triaged → In Progress
Changed in maas:
status: In Progress → Fix Committed
Changed in maas:
milestone: 3.3.0 → 3.3.0-beta3
Changed in maas:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.