Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#6543): adds api-side support for users with multiple facilities #9126

Merged
merged 31 commits into from
Jun 6, 2024

Conversation

dianabarsan
Copy link
Member

@dianabarsan dianabarsan commented May 15, 2024

Description

Covers:

  • support for downloading and uploading doc permissions when a user has multiple facilities
  • new users v3 api to add a user with multiple facilities
  • new users v3 api to update a user to add multiple facilities
  • updated users shared library to support multiple facilities
  • updated recent users search api to support multiple facilities

Implementation details:

  • when creating a user with multiple facilities, the contact has to be within one of the facilities
  • /v3/users accepts the same payload and /v1/users
  • /v3/users does not create facilities, only accepts an array of uuids of existing facilities
  • /v3/users does not create a contact

Does not cover:

  • validation to ensure all facilities are of the same type. We can add this, but right now it's not implemented

#6543

Code review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
…ulti-facility

# Conflicts:
#	shared-libs/contacts/test/unit/places.spec.js
#	shared-libs/user-management/src/users.js
#	shared-libs/user-management/test/unit/users.spec.js
#	tests/integration/api/controllers/users.spec.js
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Copy link
Contributor

@latin-panda latin-panda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dianabarsan this is great! Thanks a lot
I left few comments as I was reading to understand the changes

I tested the app and seems to work fine for users with 1 facility and with more than one:

contact list

Screenshot 2024-05-17 at 4 23 47 PM

contact details

Screenshot 2024-05-17 at 4 25 22 PM

breadcrumbs

open in a tab
Screenshot 2024-05-17 at 4 29 47 PM

I was able to create and update users:

Create

Screenshot 2024-05-17 at 4 21 51 PM

When I change or add a facility to the user, my session expires, then I login, I still the see the old stuff, but after sync, I see the facilities updated.

api/src/controllers/users.js Outdated Show resolved Hide resolved
api/src/controllers/users.js Show resolved Hide resolved
api/src/controllers/users.js Show resolved Hide resolved
api/src/services/authorization.js Show resolved Hide resolved
shared-libs/user-management/src/users.js Show resolved Hide resolved
Comment on lines +416 to +420
const getCommonFieldsUpdates = (userDoc, data) => {
getRolesUpdates(data);
if (data.roles) {
userDoc.roles = data.roles;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const getCommonFieldsUpdates = (userDoc, data) => {
getRolesUpdates(data);
if (data.roles) {
userDoc.roles = data.roles;
}
const setCommonFieldsUpdates = (userDoc, data) => {
const roles = getRolesUpdates(data);
if (roles) {
userDoc.roles = roles;
}

shared-libs/user-management/src/users.js Show resolved Hide resolved
shared-libs/user-management/src/users.js Outdated Show resolved Hide resolved
Copy link
Contributor

@Benmuiruri Benmuiruri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the create-user URL to point to v3

@latin-panda
Copy link
Contributor

latin-panda commented May 22, 2024

@Benmuiruri, I think you can use v3 for single user, and keep v2 for multiple users.

@latin-panda
Copy link
Contributor

Please feel free to dismiss my review to not block this PR 🙂

Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
@Benmuiruri
Copy link
Contributor

Hi @dianabarsan Jenni's comment suggests we should not change the URL for create-user to v3 and instead use createMultipleUsers .

However, that's not correct since the createMultipleUsers is for bulk uploading users... just a heads up on that.

@dianabarsan
Copy link
Member Author

Hi @Benmuiruri

We are not going to change the bulk create in this iteration to support multiple facilities.

@dianabarsan dianabarsan marked this pull request as ready for review May 28, 2024 14:07
@Benmuiruri
Copy link
Contributor

That's okay. But as it is... When I create a new user it goes to the v2 URL and fails

@dianabarsan
Copy link
Member Author

Can you send the bulk request to v2 and the single request to v3?

Copy link
Contributor

@Benmuiruri Benmuiruri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part all looks good. Just a question, how does the api handle an empty array for the place ?

There's the create-meta-db test in my branch that is returning code 400 with This user cannot have multiple places when place is set as an empty string

@dianabarsan
Copy link
Member Author

Great point @Benmuiruri . I'll handle this case as well.

Signed-off-by: Diana Barsan <barsan@medic.org>
Signed-off-by: Diana Barsan <barsan@medic.org>
@Benmuiruri
Copy link
Contributor

Hi @dianabarsan I believe this is ready to merge after Jenni and I reviewed it. Please rebase and merge if all is good so that I can rebase and merge Jenni's branches and my branches. Thanks.

@dianabarsan
Copy link
Member Author

I think I added one more commit after your last review, that validates that the places list is correct, so we handle:

There's the create-meta-db test in my #9128 that is returning code 400 with This user cannot have multiple places when place is set as an empty string

The response is still 400 I believe, but this edge case is handled in code and tested for.

Copy link
Contributor

@Benmuiruri Benmuiruri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the empty facility array check

@dianabarsan dianabarsan merged commit 2fdddd0 into master Jun 6, 2024
39 checks passed
@dianabarsan dianabarsan deleted the 6543-multi-facility branch June 6, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants