harvard-lil / perma

Indelible links
423 stars 71 forks source link

Bulk organization user creation/addition feature #3651

Open teovin opened 2 weeks ago

teovin commented 2 weeks ago

This feature adds a new button to the organization user management view (/manage/organization-users):

image

Upon clicking, the bulk upload form comes up:

image

User makes the organization, affiliation expiration, and CSV file selections. Form cannot be submitted without an organization selection or with a non .csv file extension.

It is also invalid if it doesn't include all of the column headers, if it doesn't have any users at all, if it doesn't include the email data for a given user and also if it has duplicate users.

image

image

image

image

image

image

The affiliation field can be toggled just like in the single user flow.

image

Once submitted, users that don't exist will be created; those that do will have their organization affiliation updated. New users will receive new user email with account activation email. Existing users will receive the user added to organization email.

image

image

A generic success message will be displayed at the end if there are no validation errors:

image

If some of the users get processed, but some can't due to those being an admin or registrar, below will be displayed:

image

If all users in the CSV are admins or registrars, the below error message will be displayed:

image

This PR also fixes a bug where the existing user email wasn't displaying the organization name.

image

Disclaimer: Any behavior and the wording here are open to feedback. This was my initial take on it :)

EDIT:

As of Nov 20th, I put this feature behind a feature flag so we can do some more testing on it in stage before a possible production deployment.

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 87.60331% with 15 lines in your changes missing coverage. Please review.

Project coverage is 69.28%. Comparing base (1c1fd71) to head (2d59d57). Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
perma_web/perma/views/user_management.py 70.73% 12 Missing :warning:
perma_web/perma/forms.py 96.20% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #3651 +/- ## =========================================== + Coverage 69.01% 69.28% +0.27% =========================================== Files 54 54 Lines 7478 7593 +115 =========================================== + Hits 5161 5261 +100 - Misses 2317 2332 +15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features:

christiansmith commented 1 week ago

Reviewing this with @bensteinberg (running locally), we noticed a few minor details with the CSV handling form.

  1. The CSV upload fails without a header row or with incorrect column names.
    1. We could provide a template for users to download and edit
    2. We could also handle the case of a missing header row and validate the structure of the provided data rows.
  2. When there is a validation error, instructions should remain on the screen along with the error message.
  3. If a malformed CSV is uploaded, it would be good to have better feedback for the user than the current stack trace.
teovin commented 1 week ago

@christiansmith @bensteinberg Pushed a couple of commits for the desired behavior and also added a test. I am checking with Clare about below to see what her preference would be. My initial approach was that it is good to process the good data and ignore the rest, as in something is better than nothing if it makes sense. Will check with Becky on the point of running a single db query.

It might also make sense to fail if there are any validation errors, rather than create some users and not others.

teovin commented 4 days ago

@christiansmith @bensteinberg I made some changes to the PR since you last looked, I'd appreciate it if you could look again. Clare preferred to process the valid users and notify the requestor for those that were invalid, and I updated the PR description and UI messaging to reflect that.