Skip to content

Commit

Permalink
Webhook for bulk updating accounts usergroup (#264)
Browse files Browse the repository at this point in the history
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:
- Barista
- Manager
- Board
- (Customer will also work, but will have the same effect as not
specifying the user in the request)

### 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
AnalogIO/shifty-webapp#21

---------

Co-authored-by: Jonas Anker Rasmussen <[email protected]>
  • Loading branch information
A-Guldborg and jonasanker authored Feb 27, 2024
1 parent 84844f2 commit 6ae1cbf
Show file tree
Hide file tree
Showing 11 changed files with 808 additions and 15 deletions.
3 changes: 1 addition & 2 deletions coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>default</LangVersion>
Expand All @@ -9,7 +9,6 @@
<PackageReference Include="MimeKit" Version="3.4.2" />
<PackageReference Include="NetEscapades.Configuration.Validation" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
<PackageReference Include="RestSharp" Version="108.0.2" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
Expand Down
Loading

0 comments on commit 6ae1cbf

Please sign in to comment.