SORMAS-Project icon indicating copy to clipboard operation
SORMAS-Project copied to clipboard

Make user sync more resilient to missing user roles

Open StefanKock opened this issue 2 years ago • 1 comments

Problem Description

#9903 showed that users without user roles make data sync breaking.

UserDtoHelper.fillInnerFromDto is to complicated (imho):

  1. Fiddles around with userroles if not empty. This helps to avoid currupting existing data (makes data different to server then!), but the initial sync
  2. Calculates JurisdictionLevel despite being sent in the DTO, that fails if userRoles == null.

Proposed Change

Make data sync work even if users don't have user roles.

  • [ ] Do a null-check for source.getUserRoles() when using source.getUserRoles().size()
  • [ ] in UserDtoHelper.fillInnerFromDto set the jurisdiction level to the value of the UserDto, instead of re-calculating it (this was needed back in the times when the UserDto did not have a jurisdiction level

Acceptance Criteria

  • When the user role(s) of a user are changed, this is properly synced to the mobile device
  • When the jurisdiction level of a user is changed, this is properly synced to the mobile device

StefanKock avatar Jul 20 '22 07:07 StefanKock

I have added details and acceptance criteria.

MartinWahnschaffe avatar Aug 08 '22 07:08 MartinWahnschaffe

We saw with @sergiupacurariu that right now this scenario ( editing or creating a user without a user role) is not possible from the Sormas UI, because the user roles are mandatory: image

I'll check if the API is exposed in the Resource ( if the user roles can be changed from Postman or the Automation tests). This would be a possible scenario for having users without user roles.

carina29 avatar Oct 23 '23 09:10 carina29

I've checked the code and the endpoints related to the user's role ( or edititing / creating) are not exposed which means that currently there is no way to create/update a user without user roles ( from Sormas Ui or from Postman/Automation tests).

Probably was possible before the user roles became mandatory in Sormas UI.

carina29 avatar Oct 23 '23 11:10 carina29

Verified ticket on the local machine using the latest version of SORMAS from the development branch - 1.91.0-SNAPSHOT(3a8bfa5).

The mobile app is updated based on the user's rights and/or roles by doing the following steps: I - if already logged with the user in the mobile app

  1. In the web app, log in with an Admin+NatUser;
  2. Navigate to the 'Users' directory and open an existing user;
  3. Edit them by changing the user role and save(update the user that is already logged in the mobile app);
  4. With the user that's already logged in the mobile app trigger a re-synchronize data;
  5. Log out and then log in with the same user;
  6. Observe the display of the mobile app (what entities the user has access to based on the role given).

II - if logged with other user in the mobile app

  1. In the web app, log in with an Admin+NatUser;
  2. Navigate to the 'Users' directory and open an existing user;
  3. Edit them by changing the user role and save;
  4. With the user that's already logged in the mobile app trigger a re-synchronize data;
  5. Log out and then log in with the user updated at step 3;
  6. Observe the display of the mobile app (what entities the user has access to based on the role given).

III - if mobile app is not started:

  1. In the web app, log in with an Admin+NatUser;
  2. Navigate to the 'Users' directory and open an existing user;
  3. Edit them by changing the user role and save;
  4. Start the mobile app and log in with the updated user from step 3.
  5. Observe the display of the mobile app (what entities the user has access to based on the role given).

Additionally, for the scenarios, at step 3, the user rights of the role already assigned to the user can be updated and the flow would work the same afterwards.

adinaflorea9 avatar Oct 30 '23 18:10 adinaflorea9