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 lines82838485868788899091929394959697989910010110210310410510610710810911065 unmodified lines17617717817918018118237 unmodified lines22022122222322422522681 unmodified linestry{var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");// Ensure default system agent user exists in database to prevent Foreign Key constraints failurevar agentUser = await _userRepo.GetByIdAsync(agentId);if (agentUser == null){var existingByEmail = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");if (existingByEmail != null){agentUser = existingByEmail;}else{agentUser = new User{Id = agentId,Email = "dan9228335@gmail.com",DisplayName = "Dodikuser",PasswordHash = "",CreatedAt = DateTime.UtcNow};await _userRepo.CreateAsync(agentUser);}}// Also ensure the current authenticated user requesting this has a record in the databasevar requestUser = await _userRepo.GetByIdAsync(CurrentUserId);65 unmodified linesif (dbGraph == null)return NotFound(new { message = "Board not found." });var agentId = 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 agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");if (dbGraph.UserId != agentId){return BadRequest(new { message = "This board has already been claimed by another user." });81 unmodified lines82838485868788899091929394959697989910010110210365 unmodified lines16917017117217317417517637 unmodified lines21421521621721821922022181 unmodified linestry{// 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 defaultAgentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");agentUser = new User{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 databasevar requestUser = await _userRepo.GetByIdAsync(CurrentUserId);65 unmodified linesif (dbGraph == null)return NotFound(new { message = "Board not found." });var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");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 = 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