AnalogIO / analog-core

.NET 8 backend for Cafe Analog's coffee card app
https://core.prd.analogio.dk/swagger
MIT License
4 stars 1 forks source link

Webhook for bulk updating accounts usergroup #264

Closed A-Guldborg closed 8 months ago

A-Guldborg commented 8 months ago

Implements the endpoint PUT /api/v2/webhooks/accounts/user-group, allowing an external service to update user groups in bulk.

Example request body:

{
   "privilegedUsers": [
       { "accountId": 123, "userGroup": "Manager" },
       { "accountId": 124, "userGroup": "Barista" }
    ]
}

The X-Api-Key header should be present on the request with a valid API key.

The userGroup should be one of:

Notes on testing

I have been unable to implement an integration test, since EFCore.InMemory does not seem to support the performance-optimized ExecuteUpdate that is implemented in EF Core 7 and used in this service. Reference: https://stackoverflow.com/questions/74907256/ef-7-new-executedelete-and-executeupdate-methods-not-working-on-an-in-memory-d

Business logic

Initially, business logic was implemented using client-side hashing to verify duplicate requests did not use many resources. Later, it was changed to server-side hashing however hashing was completely removed again, as it would cause weird behaviour in combination with the below mentioned existing endpoint. Now it will be clearer that the state in the external system will correct itself if analog-core and the external system are out of sync.

Notes on affected existing endpoints

This change will also mark our PATCH /api/v2/account/<id>/user-group endpoint, as any calls to the new endpoint will override any user-groups set by the old patch endpoint. The endpoint is used by the Shifty User Manager from https://github.com/AnalogIO/shifty-webapp/pull/21

ghost commented 8 months ago
πŸ‘‡ Click on the image for a new way to code review #### [![Review these changes using an interactive CodeSee Map](https://s3.us-east-2.amazonaws.com/maps.codesee.io/images/github/AnalogIO/analog-core/264/07692157/4adb5feb9d9ddf7f51cc737f2cc4e4b591db10ed.svg)](https://app.codesee.io/r/reviews?pr=264&src=https%3A%2F%2Fgithub.com%2FAnalogIO%2Fanalog-core) #### Legend CodeSee Map legend
A-Guldborg commented 8 months ago

Hi @jonasanker , it is now ready for re-review based on my above comments/replies to your change-requests.

Please note that I have not added the index that you mentioned in-person. Do you still reckon we should have an index on e.g. UserGroup or something else? 😊

sonarcloud[bot] commented 8 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required β‰₯ 80%)

See analysis details on SonarCloud