fix some edge cases

This commit is contained in:
Jicheng Lu 2024-06-11 16:56:17 -05:00
parent b211795cce
commit a32916def6
3 changed files with 7 additions and 4 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