diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs index 3c9e6bf2..c4fce4c5 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Tasks.Models; +using BotSharp.Abstraction.Users.Enums; using System.IO; using System.Text.RegularExpressions; @@ -25,6 +26,20 @@ public partial class AgentService var user = _db.GetUserById(_user.Id); _db.BulkInsertAgents(new List { agentRecord }); + if (!UserConstant.AdminRoles.Contains(user.Role)) + { + _db.BulkInsertUserAgents(new List + { + new UserAgent + { + UserId = user.Id, + AgentId = agent.Id, + Actions = new List { UserAction.Edit }, + CreatedTime = DateTime.UtcNow, + UpdatedTime = DateTime.UtcNow + } + }); + } Utilities.ClearCache(); return await Task.FromResult(agentRecord); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index d4a02e93..bf3f811f 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -429,15 +429,16 @@ public partial class MongoRepository { if (userAgents.IsNullOrEmpty()) return; - var userAgentDocs = userAgents.Select(x => new UserAgentDocument - { - Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(), - UserId = !string.IsNullOrEmpty(x.UserId) ? x.UserId : string.Empty, - AgentId = x.AgentId, - Actions = x.Actions, - CreatedTime = x.CreatedTime, - UpdatedTime = x.UpdatedTime - }).ToList(); + var userAgentDocs = userAgents.Where(x => !string.IsNullOrEmpty(x.UserId)) + .Select(x => new UserAgentDocument + { + Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(), + UserId = x.UserId, + AgentId = x.AgentId, + Actions = x.Actions, + CreatedTime = x.CreatedTime, + UpdatedTime = x.UpdatedTime + }).ToList(); _dc.UserAgents.InsertMany(userAgentDocs); }