danylokhodus commited on
Commit
9a61fc7
·
1 Parent(s): 247fc9b

fix(agent-canvas): retrieve system agent user ID dynamically by email to prevent Guid mismatch

Browse files
FlowAPI/Controllers/AgentCanvasController.cs CHANGED
@@ -82,29 +82,22 @@ namespace FlowAPI.Controllers
82
 
83
  try
84
  {
85
- var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
86
- // Ensure default system agent user exists in database to prevent Foreign Key constraints failure
87
- var agentUser = await _userRepo.GetByIdAsync(agentId);
88
  if (agentUser == null)
89
  {
90
- var existingByEmail = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");
91
- if (existingByEmail != null)
92
  {
93
- agentUser = existingByEmail;
94
- }
95
- else
96
- {
97
- agentUser = new User
98
- {
99
- Id = agentId,
100
- Email = "dan9228335@gmail.com",
101
- DisplayName = "Dodikuser",
102
- PasswordHash = "",
103
- CreatedAt = DateTime.UtcNow
104
- };
105
- await _userRepo.CreateAsync(agentUser);
106
- }
107
  }
 
108
 
109
  // Also ensure the current authenticated user requesting this has a record in the database
110
  var requestUser = await _userRepo.GetByIdAsync(CurrentUserId);
@@ -176,7 +169,8 @@ namespace FlowAPI.Controllers
176
  if (dbGraph == null)
177
  return NotFound(new { message = "Board not found." });
178
 
179
- var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
 
180
  var isClaimed = dbGraph.UserId != agentId;
181
 
182
  return Ok(new
@@ -220,7 +214,8 @@ namespace FlowAPI.Controllers
220
  }
221
 
222
  // Verify that the board is currently owned by the agent system user (unclaimed)
223
- var agentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
 
224
  if (dbGraph.UserId != agentId)
225
  {
226
  return BadRequest(new { message = "This board has already been claimed by another user." });
 
82
 
83
  try
84
  {
85
+ // Retrieve the system agent user dynamically by email to prevent Guid mismatches (e.g. SQLite seeded DB vs Prod DB)
86
+ var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");
 
87
  if (agentUser == null)
88
  {
89
+ var defaultAgentId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
90
+ agentUser = new User
91
  {
92
+ Id = defaultAgentId,
93
+ Email = "dan9228335@gmail.com",
94
+ DisplayName = "Dodikuser",
95
+ PasswordHash = "",
96
+ CreatedAt = DateTime.UtcNow
97
+ };
98
+ await _userRepo.CreateAsync(agentUser);
 
 
 
 
 
 
 
99
  }
100
+ var agentId = agentUser.Id;
101
 
102
  // Also ensure the current authenticated user requesting this has a record in the database
103
  var requestUser = await _userRepo.GetByIdAsync(CurrentUserId);
 
169
  if (dbGraph == null)
170
  return NotFound(new { message = "Board not found." });
171
 
172
+ var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");
173
+ var agentId = agentUser?.Id ?? Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
174
  var isClaimed = dbGraph.UserId != agentId;
175
 
176
  return Ok(new
 
214
  }
215
 
216
  // Verify that the board is currently owned by the agent system user (unclaimed)
217
+ var agentUser = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");
218
+ var agentId = agentUser?.Id ?? Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
219
  if (dbGraph.UserId != agentId)
220
  {
221
  return BadRequest(new { message = "This board has already been claimed by another user." });