Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Changing a user role from volunteer -> parent fails with error #1281

Open
glenpike opened this issue Oct 15, 2019 · 3 comments
Open

Changing a user role from volunteer -> parent fails with error #1281

glenpike opened this issue Oct 15, 2019 · 3 comments

Comments

@glenpike
Copy link

I had a parent sign-up as a volunteer by mistake. I was told that I could change their role, so accepted, then tried this out.

I got an error on the screen (need to look at error messages??):

Screenshot 2019-10-15 at 10 43 36

The request POST: https://zen.coderdojo.com/api/2.0/dojos/save-usersdojos with body:

{"userDojo":{"entity$":"-/cd/usersdojos","id":"81e5e435-74c6-43bd-91b7-c244f1f12fd1","mysqlUserId":null,"mysqlDojoId":null,"owner":null,"userId":"a9ff105a-ff5c-48c3-8708-a8ef253bf26a","dojoId":"5b14872f-abfb-4c4c-8f41-05de94c9a958","userTypes":["parent-guardian"],"userPermissions":[],"backgroundChecked":false,"deleted":0,"deletedBy":null,"deletedAt":null}}

Errors with the following:

{"statusCode":400,"error":"Bad Request","message":"child \"userDojo\" fails because [child \"owner\" fails because [\"owner\" must be a number]]","validation":{"source":"payload","keys":["userDojo.owner"]}}

Paired with Ant and tried copying the request and running as cURL, but changing the owner value to 0 as we assumed that the champion === owner, the message that came back was:

{"error":"You cannot change your ownership status"}

So guessing there's some issue there :)

@Wardormeur
Copy link
Contributor

Owner is a flag used for representing the current owner of the Dojo. There should be only one per Dojo, and only the owner of the Dojo can pass this ownership to somebody else (nb, that's never been enforced in the DB).
As per se, forcing the owner in the payload to 0 won't help as https://github.com/CoderDojo/cp-dojos-service/blob/master/lib/save-usersdojo.js#L36 checks for "any" mutation.
The fact that the owner value is missing from the payload is weird by itself, as I don't believe we mutate the payload (at least not that field) in the frontend. Note however that the DB does not enforce it that field to be set. If users are being created without the owner flag (not 0 nor 1), it might create some issues in the future, but I havent been able to reproduce it in dev (adding children through My children page or the booking flow). You might want to check the prod if there are any relationship (cd_usersdojos) not having a "owner" set to anything but 0 or 1.

@glenpike
Copy link
Author

Thx @Wardormeur :)
I wonder if this happened because the person who signed up applied to be a Volunteer and something in that flow isn't correct?

@Wardormeur
Copy link
Contributor

I did try with a newly created volunteer account (joined through the "Join" button, my previous comment was indeed describing another flow, my bad), and had no issue on the dev stack. It could be that the user is also a parent, that it's an old account that might be glitched (ref previous comment), or ..?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants