fix(audit): attribute resource mutations to admins
This commit is contained in:
1 parent
b2c03ad24d
commit
0d8ec23154
25 files changed
+244
-70
No files matched your search
@@ -45,10 +45,10 @@ public class SitesController : ControllerBase
|
||||
public async Task<IActionResult> Create(
|
||||
[FromBody] CreateSiteRequest request, CancellationToken ct)
|
||||
{
|
||||
if (!this.TryGetUserId(out _))
|
||||
if (!this.TryGetUserId(out var actorId))
|
||||
return Unauthorized(new { error = "Invalid user identity" });
|
||||
|
||||
var command = new CreateSiteCommand(request.Name, request.Address, request.Timezone);
|
||||
var command = new CreateSiteCommand(request.Name, request.Address, request.Timezone, ActorId: actorId);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
@@ -111,7 +111,9 @@ public class SitesController : ControllerBase
|
||||
public async Task<IActionResult> Update(
|
||||
Guid id, [FromBody] UpdateSiteRequest request, CancellationToken ct)
|
||||
{
|
||||
var command = new UpdateSiteCommand(id, request.Name, request.Address, request.Timezone, request.NtfyTopic, request.AutoUpdateEnabled);
|
||||
if (!this.TryGetUserId(out var actorId)) return Unauthorized();
|
||||
var command = new UpdateSiteCommand(id, request.Name, request.Address, request.Timezone,
|
||||
request.NtfyTopic, request.AutoUpdateEnabled, actorId);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
@@ -152,7 +154,8 @@ public class SitesController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _mediator.Send(new DeleteSiteCommand(id), ct);
|
||||
if (!this.TryGetUserId(out var actorId)) return Unauthorized();
|
||||
var result = await _mediator.Send(new DeleteSiteCommand(id, actorId), ct);
|
||||
return result.IsSuccess
|
||||
? NoContent()
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -166,9 +169,10 @@ public class SitesController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GenerateToken(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _mediator.Send(new GenerateSiteTokenCommand(id), ct);
|
||||
if (!this.TryGetUserId(out var actorId)) return Unauthorized();
|
||||
var result = await _mediator.Send(new GenerateSiteTokenCommand(id, actorId), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user