Skip to content

Commit d19e39e

Browse files
authored
Merge pull request #248 from hchen2020/master
Fix click element in WebDriver.
2 parents 358609a + ddebff6 commit d19e39e

File tree

17 files changed

+35
-10
lines changed

17 files changed

+35
-10
lines changed

src/Infrastructure/BotSharp.Abstraction/Users/IUserIdentity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public interface IUserIdentity
44
{
55
string Id { get; }
66
string Email { get; }
7+
string UserName { get; }
78
string FirstName { get; }
89
string LastName { get; }
910
}

src/Infrastructure/BotSharp.Abstraction/Users/Models/User.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Users.Models;
55
public class User
66
{
77
public string Id { get; set; } = string.Empty;
8+
public string UserName { get; set; } = string.Empty;
89
public string FirstName { get; set; } = string.Empty;
910
public string LastName { get; set; } = string.Empty;
1011
public string Email { get; set; } = string.Empty;

src/Infrastructure/BotSharp.Core/Infrastructures/Utilities.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static (string, string) SplitAsTuple(this string str, string sep)
2323
return (splits[0], splits[1]);
2424
}
2525

26+
/// <summary>
27+
/// Flush cache
28+
/// </summary>
2629
public static void ClearCache()
2730
{
2831
// Clear whole cache.

src/Infrastructure/BotSharp.Core/Users/Services/UserIdentity.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public UserIdentity(IHttpContextAccessor contextAccessor)
1717
public string Id
1818
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value!;
1919

20+
public string UserName
21+
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value!;
22+
2023
public string Email
2124
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value!;
2225

src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BotSharp.Abstraction.Repositories;
2-
using BotSharp.Abstraction.Repositories.Records;
32
using BotSharp.Abstraction.Users.Models;
43
using Microsoft.Extensions.Configuration;
54
using Microsoft.IdentityModel.Tokens;
@@ -29,12 +28,15 @@ public async Task<User> CreateUser(User user)
2928
}
3029

3130
record = user;
31+
record.UserName = user.UserName.ToLower();
3232
record.Email = user.Email.ToLower();
3333
record.Salt = Guid.NewGuid().ToString("N");
3434
record.Password = Utilities.HashText(user.Password, record.Salt);
35-
record.ExternalId = _user.Id;
3635

3736
db.CreateUser(record);
37+
38+
Utilities.ClearCache();
39+
3840
return record;
3941
}
4042

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/UserCreationModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using BotSharp.Abstraction.Users.Enums;
2-
using BotSharp.Abstraction.Users.Models;
32

43
namespace BotSharp.OpenAPI.ViewModels.Users;
54

65
public class UserCreationModel
76
{
7+
public string UserName { get; set; } = string.Empty;
88
public string FirstName { get; set; } = string.Empty;
99
public string LastName { get; set; } = string.Empty;
1010
public string Email { get; set; } = string.Empty;
@@ -15,6 +15,7 @@ public User ToUser()
1515
{
1616
return new User
1717
{
18+
UserName = UserName,
1819
FirstName = FirstName,
1920
LastName = LastName,
2021
Email = Email,

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/UserViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using BotSharp.Abstraction.Agents.Enums;
21
using BotSharp.Abstraction.Users.Enums;
3-
using BotSharp.Abstraction.Users.Models;
42
using System.Text.Json.Serialization;
53

64
namespace BotSharp.OpenAPI.ViewModels.Users;
75

86
public class UserViewModel
97
{
108
public string Id { get; set; }
9+
[JsonPropertyName("user_name")]
10+
public string UserName { get; set; }
1111
[JsonPropertyName("first_name")]
1212
public string FirstName { get; set; }
1313
[JsonPropertyName("last_name")]
@@ -32,6 +32,7 @@ public static UserViewModel FromUser(User user)
3232
return new UserViewModel
3333
{
3434
Id = user.Id,
35+
UserName = user.UserName,
3536
FirstName = user.FirstName,
3637
LastName = user.LastName,
3738
Email = user.Email,

src/Plugins/BotSharp.Plugin.ChatHub/SignalRHub.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ public SignalRHub(IServiceProvider services,
2424

2525
public override async Task OnConnectedAsync()
2626
{
27-
_logger.LogInformation($"SignalR Hub: {_user.FirstName} {_user.LastName} ({Context.UserIdentifier}) connected in {Context.ConnectionId} [{DateTime.Now}]");
27+
_logger.LogInformation($"SignalR Hub: {_user.FirstName} {_user.LastName} ({Context.User.Identity.Name}) connected in {Context.ConnectionId}");
2828

2929
var hooks = _services.GetServices<IConversationHook>();
3030
var convService = _services.GetRequiredService<IConversationService>();
3131
_context.HttpContext.Request.Query.TryGetValue("conversationId", out var conversationId);
3232

3333
if (!string.IsNullOrEmpty(conversationId))
3434
{
35+
_logger.LogInformation($"Connection {Context.ConnectionId} is with conversation {conversationId}");
3536
var conv = await convService.GetConversation(conversationId);
3637
if (conv != null)
3738
{

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/UserDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
22

33
public class UserDocument : MongoBase
44
{
5+
public string UserName { get; set; }
56
public string FirstName { get; set; }
67
public string LastName { get; set; }
78
public string Email { get; set; }

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public int Transaction<TTableInterface>(Action action)
117117
var users = _users.Select(x => new UserDocument
118118
{
119119
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
120+
UserName = x.UserName,
120121
FirstName = x.FirstName,
121122
LastName = x.LastName,
122123
Salt = x.Salt,
@@ -132,6 +133,7 @@ public int Transaction<TTableInterface>(Action action)
132133
{
133134
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, user.Id);
134135
var update = Builders<UserDocument>.Update
136+
.Set(x => x.UserName, user.UserName)
135137
.Set(x => x.FirstName, user.FirstName)
136138
.Set(x => x.LastName, user.LastName)
137139
.Set(x => x.Email, user.Email)
@@ -868,6 +870,7 @@ public List<Conversation> GetLastConversations()
868870
return user != null ? new User
869871
{
870872
Id = user.Id,
873+
UserName = user.UserName,
871874
FirstName = user.FirstName,
872875
LastName = user.LastName,
873876
Email = user.Email,
@@ -884,6 +887,7 @@ public List<Conversation> GetLastConversations()
884887
return user != null ? new User
885888
{
886889
Id = user.Id,
890+
UserName = user.UserName,
887891
FirstName = user.FirstName,
888892
LastName = user.LastName,
889893
Email = user.Email,
@@ -901,6 +905,7 @@ public void CreateUser(User user)
901905
var userCollection = new UserDocument
902906
{
903907
Id = Guid.NewGuid().ToString(),
908+
UserName = user.UserName,
904909
FirstName = user.FirstName,
905910
LastName = user.LastName,
906911
Salt = user.Salt,

src/Plugins/BotSharp.Plugin.WeChat/Users/WeChatAccountUserService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using BotSharp.Abstraction.Users.Models;
33
using BotSharp.Core.Repository;
44
using Microsoft.EntityFrameworkCore;
5+
using Senparc.Weixin.MP.AdvancedAPIs.MerChant;
56
using System;
67
using System.Collections.Generic;
78
using System.Text;
@@ -21,6 +22,7 @@ public async Task<User> GetOrCreateWeChatAccountUserAsync(string appId, string o
2122
{
2223
var user = await userService.CreateUser(new User()
2324
{
25+
UserName = openId + "@" + appId + ".wechat",
2426
Email = openId + "@" + appId + ".wechat",
2527
Password = openId
2628
});

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ClickElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public async Task ClickElement(Agent agent, BrowsingContextIn context, string me
1414
foreach (var a in anchors)
1515
{
1616
var text = await a.TextContentAsync();
17-
str.Add($"<a>{text}</a>");
17+
str.Add($"<a>{(string.IsNullOrEmpty(text) ? "EMPTY" : text)}</a>");
1818
}
1919

2020
var buttons = await body.QuerySelectorAllAsync("button");

src/Plugins/BotSharp.Plugin.WebDriver/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"description": "website url."
1111
}
1212
},
13-
"required": []
13+
"required": ["url"]
1414
}
1515
},
1616
{
@@ -42,7 +42,7 @@
4242
"description": "user input."
4343
}
4444
},
45-
"required": ["element_name"]
45+
"required": ["element_name", "input_text"]
4646
}
4747
}
4848
]

src/WebStarter/data/users/10d12798-08fb-4aa6-977b-5dd94d82dbfe/user.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"userName": "guest",
23
"firstName": "Guest",
34
"lastName": "Anonymous",
45
"email": "[email protected]",

src/WebStarter/data/users/456e35c5-caf0-4d45-9084-b44a8ca717e4/user.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{
1+
{
2+
"userName": "haiping",
23
"firstName": "Haiping",
34
"lastName": "Chen",
45
"email": "[email protected]",

src/WebStarter/data/users/d0e6680d-03d5-4ed8-bdcd-aa7d86f2a1bc/user.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"userName": "nancy",
23
"firstName": "Nancy",
34
"lastName": "Luna",
45
"email": "[email protected]",

src/WebStarter/data/users/e465af5f-044f-414b-b670-92834929b96c/user.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"userName": "elon",
23
"firstName": "Elon",
34
"lastName": "Musk",
45
"email": "[email protected]",

0 commit comments

Comments
 (0)