[Camera] Keep activated cameras offline until agent confirmation (#325)
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 21m18s
Heimdall Gitea / Build and scan server image (push) Successful in 8m5s
Heimdall Gitea / Build and scan agent image (push) Successful in 11m29s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 33m56s
Heimdall Gitea / Publish versioned installer release (push) Successful in 4m13s
Heimdall Gitea / CI policy (push) Successful in 2s
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 21m18s
Heimdall Gitea / Build and scan server image (push) Successful in 8m5s
Heimdall Gitea / Build and scan agent image (push) Successful in 11m29s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 33m56s
Heimdall Gitea / Publish versioned installer release (push) Successful in 4m13s
Heimdall Gitea / CI policy (push) Successful in 2s
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
This commit was merged in pull request #325.
This commit is contained in:
1 parent
9fd9c75f94
commit
dc8a313deb
8 files changed
+81
-11
No files matched your search
+1
-1
@@ -23,7 +23,7 @@ public class ToggleCameraStatusCommandHandler : IRequestHandler<ToggleCameraStat
|
||||
var oldStatus = camera.Status;
|
||||
|
||||
var newStatus = camera.Status == CameraStatus.Disabled
|
||||
? CameraStatus.Online
|
||||
? CameraStatus.Offline
|
||||
: CameraStatus.Disabled;
|
||||
|
||||
camera.SetStatus(newStatus);
|
||||
|
||||
@@ -633,7 +633,7 @@ else
|
||||
if (result.Succeeded && result.Data is not null)
|
||||
{
|
||||
_camera.Status = result.Data.Status;
|
||||
Snackbar.Add(result.Data.Status == "Online" ? Text["CameraDetail_Enabled"] : Text["CameraDetail_Disabled"], Severity.Success);
|
||||
Snackbar.Add(result.Data.Status != "Disabled" ? Text["CameraDetail_Enabled"] : Text["CameraDetail_Disabled"], Severity.Success);
|
||||
}
|
||||
else _editError = result.ErrorMessage ?? Text["CameraDetail_StatusError"];
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@
|
||||
{
|
||||
camera.Status = result.Data.Status;
|
||||
Snackbar.Add(
|
||||
result.Data.Status == "Online" ? string.Format(Language.Culture, Text["CamerasPage_CameraEnabled"], camera.Name) : string.Format(Language.Culture, Text["CamerasPage_CameraDisabled"], camera.Name),
|
||||
result.Data.Status != "Disabled" ? string.Format(Language.Culture, Text["CamerasPage_CameraEnabled"], camera.Name) : string.Format(Language.Culture, Text["CamerasPage_CameraDisabled"], camera.Name),
|
||||
Severity.Success);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -10,6 +10,7 @@ using Heimdall.Application.AgentLogs.Queries.GetAgentLogs;
|
||||
using Heimdall.Application.Inventory.Queries.GetAgentMetricHistory;
|
||||
using Heimdall.Application.Cameras.Commands.ReportCameraStatus;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Api.Security;
|
||||
using Heimdall.Domain.Enums;
|
||||
using Heimdall.Infrastructure.Security;
|
||||
using MediatR;
|
||||
@@ -24,6 +25,8 @@ namespace Heimdall.Api.Controllers;
|
||||
[EnableRateLimiting("Api")]
|
||||
public class AgentsController : ControllerBase
|
||||
{
|
||||
private readonly ResourceAccess _resourceAccess;
|
||||
|
||||
/// <summary>Query parameters for agent log retrieval.</summary>
|
||||
public record AgentLogsQuery(
|
||||
[FromQuery] int Page = 1,
|
||||
@@ -35,7 +38,11 @@ public class AgentsController : ControllerBase
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public AgentsController(IMediator mediator) => _mediator = mediator;
|
||||
public AgentsController(IMediator mediator, ResourceAccess resourceAccess)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_resourceAccess = resourceAccess;
|
||||
}
|
||||
|
||||
/// <summary>Register an agent using a site registration token.</summary>
|
||||
[AllowAnonymous]
|
||||
@@ -149,6 +156,12 @@ public class AgentsController : ControllerBase
|
||||
public async Task<IActionResult> ReportCameraStatus(
|
||||
Guid id, Guid cameraId, [FromBody] ReportCameraStatusRequest request, CancellationToken ct)
|
||||
{
|
||||
var requester = await _resourceAccess.ResolveAsync(User, ct);
|
||||
if (requester is null || requester.Kind != RequesterKind.Agent ||
|
||||
!await _resourceAccess.AgentAsync(requester, id, ct) ||
|
||||
!await _resourceAccess.CameraAsync(requester, cameraId, ct))
|
||||
return Forbid();
|
||||
|
||||
if (!Enum.TryParse<CameraStatus>(request.Status, true, out var status))
|
||||
return BadRequest(new { error = $"Invalid status: {request.Status}" });
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class CamerasController : ControllerBase
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
|
||||
/// <summary>Toggle a camera between Online and Disabled.</summary>
|
||||
/// <summary>Toggle a camera between enabled (initially Offline) and Disabled.</summary>
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)]
|
||||
[HttpPost("{id:guid}/toggle-status")]
|
||||
[ProducesResponseType(typeof(CameraResponse), StatusCodes.Status200OK)]
|
||||
|
||||
Reference in new issue
Block a user