mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Get OrgId only from token
This commit is contained in:
@@ -58,16 +58,10 @@ namespace WebApp.Endpoints
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null) return Results.Unauthorized();
|
||||
|
||||
// dodajemy id organizacji z tokenu
|
||||
Event Eve = newEvent.ToEntity();
|
||||
|
||||
// Wyzeruj EventRegistrations, ponieważ nie są to dane,
|
||||
// które powinniśmy przyjmować bez zgody wolontariuszy!
|
||||
Eve.EventRegistrations = [];
|
||||
Eve.OrganisationId = org.OrganisationId;
|
||||
|
||||
// Na wszelki wypadek, gdyby użytkownik wciskał nam kit :D
|
||||
if (newEvent.OrganisationId is not null && newEvent.OrganisationId != org.OrganisationId) return Results.StatusCode(418);
|
||||
|
||||
dbContext.Events.Add(Eve);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
@@ -81,12 +75,12 @@ namespace WebApp.Endpoints
|
||||
group.MapPut("/{id}",
|
||||
async (int id, EventUpdateDto updatedEvent, ApplicationDbContext dbContext, GeneralUseHelpers guhf, HttpContext httpContext) =>
|
||||
{
|
||||
|
||||
// Uzyskaj organizację z tokenu
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null) return Results.Unauthorized();
|
||||
|
||||
Console.Write(org.OrganisationId);
|
||||
var existingEvent = await dbContext.Events.FindAsync(id);
|
||||
if (existingEvent is null)
|
||||
{
|
||||
@@ -97,15 +91,11 @@ namespace WebApp.Endpoints
|
||||
// do zmodyfikowania tego (EventId = id) eventu.
|
||||
if (org.OrganisationId != existingEvent.OrganisationId) return Results.StatusCode(403);
|
||||
|
||||
// Nadpisz organisationId (obecne w updatedEvent,
|
||||
// lecz nie sprawdzane poniżej) na to, co odczytaliśmy
|
||||
// do existingEvent.
|
||||
// ... trzeba by było tworzyć obiekt od nowa, zamiast tego po prostu zwróćmy błąd.
|
||||
if (existingEvent.OrganisationId != updatedEvent.OrganisationId) return Results.StatusCode(403);
|
||||
|
||||
var originalOrgId = existingEvent.OrganisationId;
|
||||
dbContext.Entry(existingEvent)
|
||||
.CurrentValues
|
||||
.SetValues(updatedEvent.ToEntity(id));
|
||||
existingEvent.OrganisationId = originalOrgId;
|
||||
|
||||
dbContext.Entry(existingEvent)
|
||||
.Collection(Eve => Eve.EventRegistrations)
|
||||
|
||||
Reference in New Issue
Block a user