Skip to content

Commit 8e060c9

Browse files
feat: add del user api
1 parent 2c77ad0 commit 8e060c9

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ public interface IBotSharpRepository
1414
void Add<TTableInterface>(object entity);
1515

1616
#region Plugin
17-
PluginConfig GetPluginConfig();
17+
PluginConfig GetPluginConfig();
1818
void SavePluginConfig(PluginConfig config);
1919
#endregion
2020

2121
#region User
2222
User? GetUserByEmail(string email) => throw new NotImplementedException();
2323
User? GetUserByPhone(string phone) => throw new NotImplementedException();
2424
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
25-
User? GetUserById(string id) => throw new NotImplementedException();
25+
User? GetUserById(string id) => throw new NotImplementedException();
2626
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
2727
User? GetUserByAffiliateId(string affiliateId) => throw new NotImplementedException();
2828
User? GetUserByUserName(string userName) => throw new NotImplementedException();
2929
void CreateUser(User user) => throw new NotImplementedException();
3030
void UpdateUserVerified(string userId) => throw new NotImplementedException();
3131
void UpdateUserVerificationCode(string userId, string verficationCode) => throw new NotImplementedException();
3232
void UpdateUserPassword(string userId, string password) => throw new NotImplementedException();
33-
void UpdateUserEmail(string userId, string email)=> throw new NotImplementedException();
33+
void UpdateUserEmail(string userId, string email) => throw new NotImplementedException();
3434
void UpdateUserPhone(string userId, string Iphone) => throw new NotImplementedException();
3535
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
36+
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
3637
#endregion
3738

3839
#region Agent
@@ -76,7 +77,7 @@ public interface IBotSharpRepository
7677
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
7778
IEnumerable<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
7879
#endregion
79-
80+
8081
#region Execution Log
8182
void AddExecutionLogs(string conversationId, List<string> logs);
8283
List<string> GetExecutionLogs(string conversationId);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public interface IAuthenticationHook
1010
void BeforeSending(Token token);
1111
Task UserCreated(User user);
1212
Task VerificationCodeResetPassword(User user);
13+
Task DelUsers(List<string> userIds);
1314
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public interface IUserService
1919
Task<bool> ModifyUserPhone(string phone);
2020
Task<bool> UpdatePassword(string newPassword, string verificationCode);
2121
Task<DateTime> GetUserTokenExpires();
22+
Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable);
2223
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using BotSharp.Abstraction.Users.Enums;
21
using BotSharp.Abstraction.Infrastructures;
2+
using BotSharp.Abstraction.Users.Enums;
33
using BotSharp.Abstraction.Users.Models;
44
using BotSharp.Abstraction.Users.Settings;
55
using BotSharp.OpenAPI.ViewModels.Users;
@@ -9,7 +9,6 @@
99
using System.IdentityModel.Tokens.Jwt;
1010
using System.Security.Claims;
1111
using System.Text.RegularExpressions;
12-
using System.Net;
1312

1413
namespace BotSharp.Core.Users.Services;
1514

@@ -524,4 +523,23 @@ public async Task<bool> ModifyUserPhone(string phone)
524523
db.UpdateUserPhone(record.Id, phone);
525524
return true;
526525
}
526+
527+
public async Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable)
528+
{
529+
var db = _services.GetRequiredService<IBotSharpRepository>();
530+
db.UpdateUsersIsDisable(userIds, isDisable);
531+
532+
if (!isDisable)
533+
{
534+
return true;
535+
}
536+
537+
// del membership
538+
var hooks = _services.GetServices<IAuthenticationHook>();
539+
foreach (var hook in hooks)
540+
{
541+
await hook.DelUsers(userIds);
542+
}
543+
return true;
544+
}
527545
}

src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ public async Task<bool> ModifyUserPhone([FromQuery] string phone)
143143
return await _userService.ModifyUserPhone(phone);
144144
}
145145

146+
[HttpPost("/user/update/isdisable")]
147+
public async Task<bool> UpdateUsersIsDisable([FromQuery] List<string> userIds, [FromQuery] bool isDisable)
148+
{
149+
return await _userService.UpdateUsersIsDisable(userIds, isDisable);
150+
}
151+
146152
#region Avatar
147153
[HttpPost("/user/avatar")]
148154
public bool UploadUserAvatar([FromBody] UserAvatarModel input)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,12 @@ public void UpdateUserIsDisable(string userId, bool isDisable)
126126
.Set(x => x.UpdatedTime, DateTime.UtcNow);
127127
_dc.Users.UpdateOne(filter, update);
128128
}
129+
130+
public void UpdateUsersIsDisable(List<string> userIds, bool isDisable)
131+
{
132+
foreach (var userId in userIds)
133+
{
134+
UpdateUserIsDisable(userId, isDisable);
135+
}
136+
}
129137
}

0 commit comments

Comments
 (0)