Merge pull request #494 from iceljc/bugfix/fix-agent-conv-edge-cases

Bugfix/fix agent conv edge cases
This commit is contained in:
C. Oceania 2024-06-12 02:57:40 +00:00 committed by GitHub
commit 2263cd2949
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 6 deletions

View file

@ -1,6 +1,8 @@
using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Repositories.Enums;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Users.Enums;
using Microsoft.EntityFrameworkCore.Metadata;
using System.IO;
namespace BotSharp.Core.Agents.Services;
@ -11,7 +13,9 @@ public partial class AgentService
{
var userService = _services.GetRequiredService<IUserService>();
var user = await userService.GetUser(_user.Id);
if (user?.Role != UserRole.Admin) return;
var userAgents = GetAgentsByUser(user?.Id);
var editable = userAgents?.Select(x => x.Id)?.Contains(agent.Id) ?? false;
if (user?.Role != UserRole.Admin && !editable) return;
if (agent == null || string.IsNullOrEmpty(agent.Id)) return;

View file

@ -373,7 +373,6 @@ namespace BotSharp.Core.Repository
var filter = new AgentFilter
{
IsPublic = true,
AgentIds = agentIds
};
var agents = GetAgents(filter);

View file

@ -59,7 +59,7 @@ public class ConversationController : ControllerBase
user = await userService.GetUser(item.User.Id);
item.User = UserViewModel.FromUser(user);
var agent = await agentService.GetAgent(item.AgentId);
item.AgentName = agent?.Name;
item.AgentName = agent?.Name ?? "Unkown";
}
return new PagedItems<ConversationViewModel>
@ -110,7 +110,7 @@ public class ConversationController : ControllerBase
Data = message.Data,
Sender = new UserViewModel
{
FirstName = agent.Name,
FirstName = agent?.Name ?? "Unkown",
Role = message.Role,
},
RichContent = message.SecondaryRichContent ?? message.RichContent

View file

@ -308,8 +308,7 @@ public partial class MongoRepository
var filter = new AgentFilter
{
AgentIds = agentIds,
IsPublic = true
AgentIds = agentIds
};
var agents = GetAgents(filter);
return agents;