Skip to content

Lida dev #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 29, 2024
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 @@ -14,25 +14,26 @@ public interface IBotSharpRepository
void Add<TTableInterface>(object entity);

#region Plugin
PluginConfig GetPluginConfig();
PluginConfig GetPluginConfig();
void SavePluginConfig(PluginConfig config);
#endregion

#region User
User? GetUserByEmail(string email) => throw new NotImplementedException();
User? GetUserByPhone(string phone) => throw new NotImplementedException();
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
User? GetUserById(string id) => throw new NotImplementedException();
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();
User? GetUserByAffiliateId(string affiliateId) => throw new NotImplementedException();
User? GetUserByUserName(string userName) => throw new NotImplementedException();
void CreateUser(User user) => throw new NotImplementedException();
void UpdateUserVerified(string userId) => throw new NotImplementedException();
void UpdateUserVerificationCode(string userId, string verficationCode) => throw new NotImplementedException();
void UpdateUserPassword(string userId, string password) => throw new NotImplementedException();
void UpdateUserEmail(string userId, string email)=> throw new NotImplementedException();
void UpdateUserEmail(string userId, string email) => throw new NotImplementedException();
void UpdateUserPhone(string userId, string Iphone) => throw new NotImplementedException();
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
#endregion

#region Agent
Expand Down Expand Up @@ -76,7 +77,7 @@ public interface IBotSharpRepository
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
IEnumerable<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
#endregion

#region Execution Log
void AddExecutionLogs(string conversationId, List<string> logs);
List<string> GetExecutionLogs(string conversationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface IAuthenticationHook
void BeforeSending(Token token);
Task UserCreated(User user);
Task VerificationCodeResetPassword(User user);
Task DelUsers(List<string> userIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface IUserService
Task<bool> ModifyUserPhone(string phone);
Task<bool> UpdatePassword(string newPassword, string verificationCode);
Task<DateTime> GetUserTokenExpires();
Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable);
}
22 changes: 20 additions & 2 deletions src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Infrastructures;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
using BotSharp.Abstraction.Users.Settings;
using BotSharp.OpenAPI.ViewModels.Users;
Expand All @@ -9,7 +9,6 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text.RegularExpressions;
using System.Net;

namespace BotSharp.Core.Users.Services;

Expand Down Expand Up @@ -524,4 +523,23 @@ public async Task<bool> ModifyUserPhone(string phone)
db.UpdateUserPhone(record.Id, phone);
return true;
}

public async Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
db.UpdateUsersIsDisable(userIds, isDisable);

if (!isDisable)
{
return true;
}

// del membership
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
await hook.DelUsers(userIds);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task<ActionResult<Token>> ActivateUser(UserActivationModel model)
var token = await _userService.ActiveUser(model);
if (token == null)
{
return Unauthorized();
return BadRequest();
}
return Ok(token);
}
Expand Down Expand Up @@ -143,6 +143,12 @@ public async Task<bool> ModifyUserPhone([FromQuery] string phone)
return await _userService.ModifyUserPhone(phone);
}

[HttpPost("/user/update/isdisable")]
public async Task<bool> UpdateUsersIsDisable([FromQuery] List<string> userIds, [FromQuery] bool isDisable)
{
return await _userService.UpdateUsersIsDisable(userIds, isDisable);
}

#region Avatar
[HttpPost("/user/avatar")]
public bool UploadUserAvatar([FromBody] UserAvatarModel input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,12 @@ public void UpdateUserIsDisable(string userId, bool isDisable)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
_dc.Users.UpdateOne(filter, update);
}

public void UpdateUsersIsDisable(List<string> userIds, bool isDisable)
{
foreach (var userId in userIds)
{
UpdateUserIsDisable(userId, isDisable);
}
}
}