Skip to content

Commit 5f82152

Browse files
authored
Merge pull request #749 from iceljc/features/add-role
Features/add role
2 parents e07deb1 + 6ef25b1 commit 5f82152

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1129
-144
lines changed

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/AgentFilter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ public class AgentFilter
99
public string? Type { get; set; }
1010
public bool? IsPublic { get; set; }
1111
public List<string>? AgentIds { get; set; }
12+
13+
public static AgentFilter Empty()
14+
{
15+
return new AgentFilter();
16+
}
1217
}

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/AgentTaskFilter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ public class AgentTaskFilter
55
public Pagination Pager { get; set; } = new Pagination();
66
public string? AgentId { get; set; }
77
public bool? Enabled { get; set; }
8+
9+
public static AgentTaskFilter Empty()
10+
{
11+
return new AgentTaskFilter();
12+
}
813
}

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ public class ConversationFilter
2525
public IEnumerable<KeyValue>? States { get; set; } = [];
2626

2727
public IEnumerable<string>? Tags { get; set; } = [];
28+
29+
public static ConversationFilter Empty()
30+
{
31+
return new ConversationFilter();
32+
}
2833
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace BotSharp.Abstraction.Repositories.Filters;
2+
3+
public class RoleFilter
4+
{
5+
[JsonPropertyName("names")]
6+
public IEnumerable<string>? Names { get; set; }
7+
8+
public static RoleFilter Empty()
9+
{
10+
return new RoleFilter();
11+
}
12+
}

src/Infrastructure/BotSharp.Abstraction/Users/Models/UserFilter.cs renamed to src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/UserFilter.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace BotSharp.Abstraction.Users.Models;
1+
namespace BotSharp.Abstraction.Repositories.Filters;
22

33
public class UserFilter : Pagination
44
{
@@ -14,6 +14,14 @@ public class UserFilter : Pagination
1414
[JsonPropertyName("roles")]
1515
public IEnumerable<string>? Roles { get; set; }
1616

17+
[JsonPropertyName("types")]
18+
public IEnumerable<string>? Types { get; set; }
19+
1720
[JsonPropertyName("sources")]
1821
public IEnumerable<string>? Sources { get; set; }
22+
23+
public static UserFilter Empty()
24+
{
25+
return new UserFilter();
26+
}
1927
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Loggers.Models;
22
using BotSharp.Abstraction.Plugins.Models;
33
using BotSharp.Abstraction.Repositories.Filters;
4+
using BotSharp.Abstraction.Roles.Models;
45
using BotSharp.Abstraction.Shared;
56
using BotSharp.Abstraction.Tasks.Models;
67
using BotSharp.Abstraction.Translation.Models;
@@ -16,6 +17,13 @@ public interface IBotSharpRepository : IHaveServiceProvider
1617
void SavePluginConfig(PluginConfig config);
1718
#endregion
1819

20+
#region Role
21+
bool RefreshRoles(IEnumerable<Role> roles) => throw new NotImplementedException();
22+
IEnumerable<Role> GetRoles(RoleFilter filter) => throw new NotImplementedException();
23+
Role? GetRoleDetails(string roleId, bool includeAgent = false) => throw new NotImplementedException();
24+
bool UpdateRole(Role role, bool updateRoleAgents = false) => throw new NotImplementedException();
25+
#endregion
26+
1927
#region User
2028
User? GetUserByEmail(string email) => throw new NotImplementedException();
2129
User? GetUserByPhone(string phone) => throw new NotImplementedException();
@@ -34,7 +42,8 @@ public interface IBotSharpRepository : IHaveServiceProvider
3442
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
3543
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
3644
PagedItems<User> GetUsers(UserFilter filter) => throw new NotImplementedException();
37-
bool UpdateUser(User user, bool isUpdateUserAgents = false) => throw new NotImplementedException();
45+
User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
46+
bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
3847
#endregion
3948

4049
#region Agent
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using BotSharp.Abstraction.Repositories.Filters;
2+
using BotSharp.Abstraction.Roles.Models;
3+
4+
namespace BotSharp.Abstraction.Roles;
5+
6+
public interface IRoleService
7+
{
8+
Task<bool> RefreshRoles();
9+
Task<IEnumerable<string>> GetRoleOptions();
10+
Task<IEnumerable<Role>> GetRoles(RoleFilter filter);
11+
Task<Role?> GetRoleDetails(string roleId);
12+
Task<bool> UpdateRole(Role role, bool isUpdateRoleAgents = false);
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace BotSharp.Abstraction.Roles.Models;
2+
3+
public class Role
4+
{
5+
[JsonPropertyName("id")]
6+
public string Id { get; set; }
7+
8+
[JsonPropertyName("name")]
9+
public string Name { get; set; }
10+
11+
[JsonPropertyName("permissions")]
12+
public IEnumerable<string> Permissions { get; set; } = [];
13+
14+
[JsonIgnore]
15+
public IEnumerable<RoleAgentAction> AgentActions { get; set; } = [];
16+
17+
[JsonPropertyName("updated_time")]
18+
public DateTime UpdatedTime { get; set; }
19+
20+
[JsonPropertyName("created_time")]
21+
public DateTime CreatedTime { get; set; }
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace BotSharp.Abstraction.Roles.Models;
2+
3+
public class RoleAgent
4+
{
5+
[JsonPropertyName("id")]
6+
public string Id { get; set; } = string.Empty;
7+
8+
[JsonPropertyName("user_id")]
9+
public string RoleId { get; set; } = string.Empty;
10+
11+
[JsonPropertyName("agent_id")]
12+
public string AgentId { get; set; }
13+
14+
[JsonPropertyName("actions")]
15+
public IEnumerable<string> Actions { get; set; } = [];
16+
17+
[JsonIgnore]
18+
public Agent? Agent { get; set; }
19+
20+
[JsonPropertyName("updated_time")]
21+
public DateTime UpdatedTime { get; set; }
22+
23+
[JsonPropertyName("created_time")]
24+
public DateTime CreatedTime { get; set; }
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace BotSharp.Abstraction.Roles.Models;
2+
3+
public class RoleAgentAction
4+
{
5+
[JsonPropertyName("id")]
6+
public string Id { get; set; }
7+
8+
[JsonPropertyName("agent_id")]
9+
public string AgentId { get; set; }
10+
11+
[JsonIgnore]
12+
public Agent? Agent { get; set; }
13+
14+
[JsonPropertyName("actions")]
15+
public IEnumerable<string> Actions { get; set; } = [];
16+
}

0 commit comments

Comments
 (0)