Spaces:
Running
Running
Commit ·
9a61fc7
1
Parent(s): 247fc9b
fix(agent-canvas): retrieve system agent user ID dynamically by email to prevent Guid mismatch
Browse files81 unmodified lines82838485868785868788909189909193949596979899100101102103104105929394959697981069910010110210365 unmodified lines16917017117217917317417517637 unmodified lines21421521621722321821922022181 unmodified lines
try { var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); // Ensure default system agent user exists in database to prevent Foreign Key constraints failure var agentUser = await _userRepo.GetByIdAsync(agentId); // Retrieve the system agent user dynamically by email to prevent Guid mismatches (e.g. SQLite seeded DB vs Prod DB) var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); if (agentUser == null) { var existingByEmail = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); if (existingByEmail != null) var defaultAgentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); agentUser = new User { agentUser = existingByEmail; } else { agentUser = new User { Id = agentId, Email = "dan9228335@gmail.com", DisplayName = "Dodikuser", PasswordHash = "", CreatedAt = DateTime.UtcNow }; await _userRepo.CreateAsync(agentUser); Id = defaultAgentId, Email = "dan9228335@gmail.com", DisplayName = "Dodikuser", PasswordHash = "", CreatedAt = DateTime.UtcNow }; await _userRepo.CreateAsync(agentUser); } } var agentId = agentUser.Id;
// Also ensure the current authenticated user requesting this has a record in the database var requestUser = await _userRepo.GetByIdAsync(CurrentUserId);65 unmodified lines if (dbGraph == null) return NotFound(new { message = "Board not found." });
var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); var agentId = agentUser?.Id ?? Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); var isClaimed = dbGraph.UserId != agentId;
return Ok(new37 unmodified lines }
// Verify that the board is currently owned by the agent system user (unclaimed) var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); var agentId = agentUser?.Id ?? Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); if (dbGraph.UserId != agentId) { return BadRequest(new { message = "This board has already been claimed by another user." });FlowAPI/Controllers/AgentCanvasController.cs+16-21