GTBitsOfGood/southface

[Bug] Deleting referenced standards

Closed this issue · 0 comments

As an admin user, I might add a standard to my current project report and then delete that standard later. Currently, doing so breaks the application. Try it:

How to reproduce

  • Login as admin
  • Add a standard to the project report
  • Delete that standard
  • Hit refresh
  • If on deployment, try adding another standard to the project report

This turns into an unavoidable error for the user that can only be fixed by modifying the database.

This happens because standards in the active report are stored as references to documents in the cards collection. When fetching the active report in the api/user/active-report/get route, a populate call is done in mongoose to replace the references with the documents themselves.

When the populate call doesn't find a reference, it returns null instead (I think, might want to check on that). Handle the case when populate fails by removing the non-existing standard from the active report.

This bug may lead to a feature where the user is notified whenever a standard they referenced in their report is missing. There might also be a feature request for keeping a stale copy of a standard on the active report or notifying the user before they delete the standard that it is referenced in active reports; these changes will require varying degrees of backend additions.

For now, just make sure the application doesn't break by handling this error.