Uploading users in bulk in Django

Hi @ks_1, that’s great! I’m not aware of an endpoint that’s exposed to do that, but I’ll leave that open to @jnm to comment. It looks like you can manage this sort of thing just through the existing permissions endpoints as a work-around? You could have a spreadsheet or whatever that links permissions to groups and then assign those to users. Team management is something that’s in the pipeline, so hopefully you can manage this without a work-around soon.

1 Like

We haven’t done anything with Django’s group features yet.

Hello @Josh

Can we update bulk users’ passwords for existing users?

Hi @Mdkhamru, you can refer to the Django docs for this:

https://docs.djangoproject.com/en/dev/topics/auth/default/#user-objects

3 Likes

@Josh thanks

2 Likes

We always faced some credential issues when using this method, only now did we realize the problem…
When creating users through this method, the credentials work on KPI, but they don’t work on KC (although the users are created there as well). Users can log into kf.url, but if they try to sign in on ODK Collect using the KC endpoint, the credentials don’t work.
The only way to get it to work is to go to kf.url/admin and reset the passwords for these users.

I think this is a bug.

1 Like

ya right even some times after password reset they are still not able to login kobo collect and credentials works only in web

Thanks for reporting this issue. It looks like a workaround is to log in to KPI first with the newly created user’s credentials, for example:

john@world:~$ curl --user special_api_user:not_very_secret http://kf.kobo.local:9000/me/; echo
{"username":"special_api_user","first_name":"","last_name":"","email":"foo@bar.baz","server_time":"2021-11-18T01:41:37Z","date_joined":"2021-11-18T01:40:48Z","projects_url":"http://kc.kobo.local:9000/special_api_user","is_superuser":false,"gravatar":"https://www.gravatar.com/avatar/9050f8ea6abf7524e8ca40107fc8b00c?s=40","is_staff":false,"last_login":null,"extra_details":{"require_auth":false},"git_rev":false}

After that, the KoBoCAT OpenRosa endpoints, which use digest authentication, should work for the new user. I’ve filed a bug; please check the reproduction steps and add comments if your experience differs.

3 Likes

@jnm
We’ve edited the v2 KPI endpoints to create users and edit permissions (also all other parameters) using superuser credentials… Can I directly submit a pull request?

Thanks for the pull request. Did you intend to expose the usernames, names, email addresses, etc. to anyone who accessed the endpoint, including anonymous users and non-superusers? You also seem to remove an entire method, migrate(), for no apparent reason.

I would request that you please review the checklist in the PR template (none of the boxes are checked). Unit tests are absolutely mandatory for a change like this, and the unit tests should illustrate what you expect the API to do. For example, I would be able to tell if you intentionally wanted to give the general public that level of access to your user list if there were a unit test—and if you didn’t, the unit test would’ve caught the mistake.

Thanks again.

2 Likes

Does this code only work in kobo?

how you add new users

Thanks for the feedback and sorry I couldn’t respond earlier. Admittedly it was a quickly put-together hack from our end and we didn’t do much testing. We did make some changes later to prevent visibility of all users publicly.
Frankly we’re running quite busy these days, but I’ll be sure to edit the PR with better code in the near future.

1 Like