Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public async Task<Agent> CreateAgent(Agent agent)
Id = Guid.NewGuid().ToString(),
UserId = user.Id,
AgentId = foundAgent?.Id ?? agentRecord.Id,
Editable = false,
CreatedTime = DateTime.UtcNow,
UpdatedTime = DateTime.UtcNow
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public async Task RefreshAgents()
Id = Guid.NewGuid().ToString(),
UserId = user.Id,
AgentId = agent.Id,
Editable = false,
CreatedTime = DateTime.UtcNow,
UpdatedTime = DateTime.UtcNow
};
Expand Down
23 changes: 16 additions & 7 deletions src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ private IQueryable<User> Users
{
foreach (var d in Directory.GetDirectories(dir))
{
var json = File.ReadAllText(Path.Combine(d, "user.json"));
var userFile = Path.Combine(d, "user.json");
if (!Directory.Exists(d) || !File.Exists(userFile))
continue;

var json = File.ReadAllText(userFile);
_users.Add(JsonSerializer.Deserialize<User>(json, _options));
}
}
Expand All @@ -75,7 +79,11 @@ private IQueryable<Agent> Agents
{
foreach (var d in Directory.GetDirectories(dir))
{
var json = File.ReadAllText(Path.Combine(d, "agent.json"));
var file = Path.Combine(d, "agent.json");
if (!Directory.Exists(d) || !File.Exists(file))
continue;

var json = File.ReadAllText(file);
var agent = JsonSerializer.Deserialize<Agent>(json, _options);
if (agent != null)
{
Expand Down Expand Up @@ -108,11 +116,11 @@ private IQueryable<UserAgent> UserAgents
foreach (var d in Directory.GetDirectories(dir))
{
var file = Path.Combine(d, "agents.json");
if (Directory.Exists(d) && File.Exists(file))
{
var json = File.ReadAllText(file);
_userAgents.AddRange(JsonSerializer.Deserialize<List<UserAgent>>(json, _options));
}
if (!Directory.Exists(d) || !File.Exists(file))
continue;

var json = File.ReadAllText(file);
_userAgents.AddRange(JsonSerializer.Deserialize<List<UserAgent>>(json, _options));
}
}
return _userAgents.AsQueryable();
Expand Down Expand Up @@ -777,6 +785,7 @@ public List<string> GetExectionLogs(string conversationId)
public void CreateUser(User user)
{
var userId = Guid.NewGuid().ToString();
user.Id = userId;
var dir = Path.Combine(_dbSettings.FileRepository, "users", userId);
if (!Directory.Exists(dir))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;

namespace BotSharp.OpenAPI.ViewModels.Users;
Expand All @@ -8,6 +9,7 @@ public class UserCreationModel
public string LastName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string Role { get; set; } = UserRole.Client;

public User ToUser()
{
Expand All @@ -16,7 +18,8 @@ public User ToUser()
FirstName = FirstName,
LastName = LastName,
Email = Email,
Password = Password
Password = Password,
Role = Role
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class UserAgentCollection : MongoBase
{
public string UserId { get; set; }
public string AgentId { get; set; }
public bool Editable { get; set; }

public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class UserCollection : MongoBase
public string Salt { get; set; }
public string Password { get; set; }
public string? ExternalId { get; set; }
public string Role { get; set; }

public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public int Transaction<TTableInterface>(Action action)
Password = x.Password,
Email = x.Email,
ExternalId = x.ExternalId,
Role = x.Role,
CreatedTime = x.CreatedTime,
UpdatedTime = x.UpdatedTime
}).ToList();
Expand All @@ -162,6 +163,7 @@ public int Transaction<TTableInterface>(Action action)
.Set(x => x.Salt, user.Salt)
.Set(x => x.Password, user.Password)
.Set(x => x.ExternalId, user.ExternalId)
.Set(x => x.Role, user.Role)
.Set(x => x.CreatedTime, user.CreatedTime)
.Set(x => x.UpdatedTime, user.UpdatedTime);
_dc.Users.UpdateOne(filter, update, _options);
Expand All @@ -174,6 +176,7 @@ public int Transaction<TTableInterface>(Action action)
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
AgentId = x.AgentId,
UserId = !string.IsNullOrEmpty(x.UserId) ? x.UserId : string.Empty,
Editable = x.Editable,
CreatedTime = x.CreatedTime,
UpdatedTime = x.UpdatedTime
}).ToList();
Expand All @@ -184,6 +187,7 @@ public int Transaction<TTableInterface>(Action action)
var update = Builders<UserAgentCollection>.Update
.Set(x => x.AgentId, userAgent.AgentId)
.Set(x => x.UserId, userAgent.UserId)
.Set(x => x.Editable, userAgent.Editable)
.Set(x => x.CreatedTime, userAgent.CreatedTime)
.Set(x => x.UpdatedTime, userAgent.UpdatedTime);
_dc.UserAgents.UpdateOne(filter, update, _options);
Expand Down Expand Up @@ -571,6 +575,7 @@ public void BulkInsertUserAgents(List<UserAgent> userAgents)
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
AgentId = x.AgentId,
UserId = !string.IsNullOrEmpty(x.UserId) ? x.UserId : string.Empty,
Editable = x.Editable,
CreatedTime = x.CreatedTime,
UpdatedTime = x.UpdatedTime
}).ToList();
Expand Down Expand Up @@ -764,7 +769,8 @@ public List<string> GetExectionLogs(string conversationId)
Email = user.Email,
Password = user.Password,
Salt = user.Salt,
ExternalId = user.ExternalId
ExternalId = user.ExternalId,
Role = user.Role
} : null;
}

Expand All @@ -779,7 +785,8 @@ public List<string> GetExectionLogs(string conversationId)
Email = user.Email,
Password = user.Password,
Salt = user.Salt,
ExternalId = user.ExternalId
ExternalId = user.ExternalId,
Role = user.Role
} : null;
}

Expand All @@ -796,6 +803,7 @@ public void CreateUser(User user)
Password = user.Password,
Email = user.Email,
ExternalId = user.ExternalId,
Role = user.Role,
CreatedTime = DateTime.UtcNow,
UpdatedTime = DateTime.UtcNow
};
Expand Down