Add UserType.

This commit is contained in:
Haiping Chen 2024-09-18 19:49:32 -05:00
parent 0f37ef88f6
commit 5fceb2cd4f
9 changed files with 31 additions and 7 deletions

View file

@ -13,9 +13,9 @@ public class UserRole
public const string CSR = "csr"; public const string CSR = "csr";
/// <summary> /// <summary>
/// Client /// Authorized user
/// </summary> /// </summary>
public const string Client = "client"; public const string User = "user";
/// <summary> /// <summary>
/// Back office operations /// Back office operations

View file

@ -0,0 +1,8 @@
namespace BotSharp.Abstraction.Users.Enums;
public class UserType
{
public const string Internal = "internal";
public const string Client = "client";
public const string Affiliate = "affiliate";
}

View file

@ -14,7 +14,11 @@ public class User
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
public string Source { get; set; } = "internal"; public string Source { get; set; } = "internal";
public string? ExternalId { get; set; } public string? ExternalId { get; set; }
public string Role { get; set; } = UserRole.Client; /// <summary>
/// internal, client, affiliate
/// </summary>
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
public string? VerificationCode { get; set; } public string? VerificationCode { get; set; }
public bool Verified { get; set; } public bool Verified { get; set; }
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;

View file

@ -126,7 +126,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
_historyStates = _db.GetConversationStates(conversationId); _historyStates = _db.GetConversationStates(conversationId);
var dialogs = _db.GetConversationDialogs(conversationId); var dialogs = _db.GetConversationDialogs(conversationId);
var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User || x.MetaData?.Role == UserRole.Client) var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User || x.MetaData?.Role == UserRole.User)
.GroupBy(x => x.MetaData?.MessageId) .GroupBy(x => x.MetaData?.MessageId)
.Select(g => g.First()) .Select(g => g.First())
.OrderBy(x => x.MetaData?.CreateTime) .OrderBy(x => x.MetaData?.CreateTime)

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models; using BotSharp.Abstraction.Users.Models;
using BotSharp.Abstraction.Users.Settings; using BotSharp.Abstraction.Users.Settings;
using BotSharp.OpenAPI.ViewModels.Users; using BotSharp.OpenAPI.ViewModels.Users;
@ -137,6 +138,7 @@ public class UserService : IUserService
Source = user.Source, Source = user.Source,
ExternalId = user.ExternalId, ExternalId = user.ExternalId,
Password = user.Password, Password = user.Password,
Type = user.Type,
}; };
await CreateUser(record); await CreateUser(record);
} }
@ -190,6 +192,7 @@ public class UserService : IUserService
new Claim(JwtRegisteredClaimNames.FamilyName, user?.LastName ?? string.Empty), new Claim(JwtRegisteredClaimNames.FamilyName, user?.LastName ?? string.Empty),
new Claim("source", user.Source), new Claim("source", user.Source),
new Claim("external_id", user.ExternalId ?? string.Empty), new Claim("external_id", user.ExternalId ?? string.Empty),
new Claim("type", user.Type ?? UserType.Client),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim("phone", user.Phone ?? string.Empty) new Claim("phone", user.Phone ?? string.Empty)
}; };

View file

@ -10,7 +10,8 @@ public class UserCreationModel
public string? Email { get; set; } public string? Email { get; set; }
public string? Phone { get; set; } public string? Phone { get; set; }
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
public string Role { get; set; } = UserRole.Client; public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
public User ToUser() public User ToUser()
{ {
@ -22,7 +23,8 @@ public class UserCreationModel
Email = Email, Email = Email,
Phone = Phone, Phone = Phone,
Password = Password, Password = Password,
Role = Role Role = Role,
Type = Type
}; };
} }
} }

View file

@ -14,7 +14,8 @@ public class UserViewModel
public string? LastName { get; set; } public string? LastName { get; set; }
public string? Email { get; set; } public string? Email { get; set; }
public string? Phone { get; set; } public string? Phone { get; set; }
public string Role { get; set; } = UserRole.Client; public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
[JsonPropertyName("full_name")] [JsonPropertyName("full_name")]
public string FullName => $"{FirstName} {LastName}".Trim(); public string FullName => $"{FirstName} {LastName}".Trim();
public string Source { get; set; } public string Source { get; set; }
@ -34,6 +35,7 @@ public class UserViewModel
{ {
FirstName = "Unknown", FirstName = "Unknown",
LastName = "Anonymous", LastName = "Anonymous",
Type = UserType.Client,
Role = AgentRole.User Role = AgentRole.User
}; };
} }
@ -46,6 +48,7 @@ public class UserViewModel
LastName = user.LastName, LastName = user.LastName,
Email = user.Email, Email = user.Email,
Phone = user.Phone, Phone = user.Phone,
Type = user.Type,
Role = user.Role, Role = user.Role,
Source = user.Source, Source = user.Source,
ExternalId = user.ExternalId, ExternalId = user.ExternalId,

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models; using BotSharp.Abstraction.Users.Models;
namespace BotSharp.Plugin.MongoStorage.Collections; namespace BotSharp.Plugin.MongoStorage.Collections;
@ -13,6 +14,7 @@ public class UserDocument : MongoBase
public string Password { get; set; } = null!; public string Password { get; set; } = null!;
public string Source { get; set; } = "internal"; public string Source { get; set; } = "internal";
public string? ExternalId { get; set; } public string? ExternalId { get; set; }
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = null!; public string Role { get; set; } = null!;
public string? VerificationCode { get; set; } public string? VerificationCode { get; set; }
public bool Verified { get; set; } public bool Verified { get; set; }
@ -33,6 +35,7 @@ public class UserDocument : MongoBase
Salt = Salt, Salt = Salt,
Source = Source, Source = Source,
ExternalId = ExternalId, ExternalId = ExternalId,
Type = Type,
Role = Role, Role = Role,
VerificationCode = VerificationCode, VerificationCode = VerificationCode,
Verified = Verified, Verified = Verified,

View file

@ -46,6 +46,7 @@ public partial class MongoRepository
Source = user.Source, Source = user.Source,
ExternalId = user.ExternalId, ExternalId = user.ExternalId,
Role = user.Role, Role = user.Role,
Type = user.Type,
VerificationCode = user.VerificationCode, VerificationCode = user.VerificationCode,
Verified = user.Verified, Verified = user.Verified,
CreatedTime = DateTime.UtcNow, CreatedTime = DateTime.UtcNow,