Spaces:
Running
Running
Commit ·
83f2320
1
Parent(s): b01b49e
feat: Add dynamic UpdateFromAgent endpoint to allow programmatical roadmap editing
Browse files154 unmodified lines155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226154 unmodified lines } }
[HttpPost("{id}/update")] public async Task<IActionResult> UpdateFromAgent(Guid id, [FromBody] QuestSchemaDto schema) { if (CurrentUserId == Guid.Empty) return Unauthorized(new { message = "User authentication required." });
if (schema == null || schema.Nodes == null || schema.Nodes.Count == 0) { return BadRequest(new { message = "QuestboardAI plan must contain at least one task node." }); }
try { var dbGraph = await _graphRepo.GetByIdAsync(id); if (dbGraph == null) return NotFound(new { message = "Board not found." });
// Secure check: verify that the user has edit permission to this graph (owner or shared editor) var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); var agentId = agentUser?.Id ?? Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); // Allow write if the current user owns it or if it is still owned by the agent system user (unclaimed) if (dbGraph.UserId != CurrentUserId && dbGraph.UserId != agentId) { var sharedAccess = await _sharedGraphRepo.GetShareAsync(id, CurrentUserId); if (sharedAccess == null || sharedAccess.Permission != "Edit") { return Unauthorized(new { message = "You do not have write access to edit this board." }); } }
// If the title or description is provided, update the Graph metadata if (!string.IsNullOrWhiteSpace(schema.Title)) { dbGraph.Title = schema.Title.Trim(); } if (schema.Description != null) { dbGraph.Description = schema.Description; } await _graphRepo.UpdateAsync(dbGraph);
// Perform Auto-Layout on the new nodes var fullGraph = AutoLayoutEngine.LayoutGraph(schema, dbGraph.UserId); fullGraph.Id = id; // Sync graph ID
// Save all new nodes and edges, completely replacing the old graph structure var saveResult = await _graphService.SaveFullGraphAsync(id, fullGraph, dbGraph.UserId); if (!saveResult) { return BadRequest(new { message = "Failed to update generated task nodes in database." }); }
return Ok(new { success = true, graphId = id, canvasUrl = $"/canvas/{id}" }); } catch (Exception ex) { return BadRequest(new { message = $"Internal error during plan update: {ex}" }); } }
[AllowAnonymous] [HttpPost("claim/check")] public async Task<IActionResult> CheckClaimToken([FromBody] ClaimRequestDto dto)FlowAPI/Controllers/AgentCanvasController.cs+66