-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGroupsController.cs
More file actions
199 lines (181 loc) · 7.46 KB
/
Copy pathGroupsController.cs
File metadata and controls
199 lines (181 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using redb.Identity.Contracts.Groups;
using redb.Identity.Contracts.Routes;
using redb.Route.Controllers.Attributes;
namespace redb.Identity.Http.Controllers;
/// <summary>
/// REST management API for groups/organizations.
/// Forwards to <c>direct-vm://identity-manage-groups</c> route.
/// </summary>
[Route("groups")]
public class GroupsController : IdentityControllerBase
{
[HttpGet]
public async Task<object?> List(
[FromQuery("offset")] int offset = 0,
[FromQuery("count")] int count = 25)
{
return await Forward(IdentityEndpoints.ManageGroups, "list",
new Dictionary<string, object> { ["offset"] = offset, ["count"] = count });
}
/// <summary>
/// B.2 — flat paginated search across ALL groups (root + nested),
/// optionally filtered by name pattern and groupType. Each row carries a
/// member-count badge resolved server-side in a single bulk query.
/// </summary>
[HttpGet("search")]
public async Task<object?> Search(
[FromQuery("query")] string? query = null,
[FromQuery("groupType")] string? groupType = null,
[FromQuery("offset")] int offset = 0,
[FromQuery("count")] int count = 25)
{
var body = new Dictionary<string, object?>
{
["query"] = query,
["groupType"] = groupType,
["offset"] = offset,
["count"] = count
};
return await Forward(IdentityEndpoints.ManageGroups, "search", body);
}
[HttpGet("{id}")]
public async Task<object?> Get([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageGroups, "read",
ParseIdBody(id, numericKey: "groupId", stringKey: "groupId"));
}
[HttpPost]
public async Task<object?> Create([FromBody] CreateGroupRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
return await Forward(IdentityEndpoints.ManageGroups, "create", new Dictionary<string, object?>
{
["name"] = request.Name,
["groupType"] = request.GroupType,
["description"] = request.Description,
["parentGroupId"] = request.ParentGroupId
});
}
[HttpPost("{id}/children")]
public async Task<object?> CreateChild([FromRoute("id")] string id, [FromBody] CreateGroupRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
var parentId = long.TryParse(id, out var pid) ? pid : 0L;
return await Forward(IdentityEndpoints.ManageGroups, "create-child", new Dictionary<string, object?>
{
["parentGroupId"] = parentId,
["name"] = request.Name,
["groupType"] = request.GroupType,
["description"] = request.Description
});
}
[HttpPut("{id}")]
public async Task<object?> Update([FromRoute("id")] string id, [FromBody] UpdateGroupRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
var numericId = long.TryParse(id, out var nid) ? nid : 0L;
return await Forward(IdentityEndpoints.ManageGroups, "update", new Dictionary<string, object?>
{
["groupId"] = numericId,
["name"] = request.Name,
["groupType"] = request.GroupType,
["description"] = request.Description
});
}
[HttpDelete("{id}")]
public async Task<object?> Delete([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageGroups, "delete",
ParseIdBody(id, numericKey: "groupId", stringKey: "groupId"));
}
[HttpPost("{id}/move")]
public async Task<object?> Move([FromRoute("id")] string id, [FromBody] MoveGroupRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
var numericId = long.TryParse(id, out var nid) ? nid : 0L;
return await Forward(IdentityEndpoints.ManageGroups, "move", new Dictionary<string, object?>
{
["groupId"] = numericId,
["newParentGroupId"] = request.NewParentGroupId
});
}
[HttpGet("{id}/tree")]
public async Task<object?> Tree([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageGroups, "tree",
ParseIdBody(id, numericKey: "groupId", stringKey: "groupId"));
}
[HttpGet("{id}/path")]
public async Task<object?> Path([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageGroups, "path",
ParseIdBody(id, numericKey: "groupId", stringKey: "groupId"));
}
[HttpGet("{id}/children")]
public async Task<object?> Children([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageGroups, "children",
ParseIdBody(id, numericKey: "groupId", stringKey: "groupId"));
}
[HttpGet("{id}/members")]
public async Task<object?> ListMembers([FromRoute("id")] string id)
{
return await Forward(IdentityEndpoints.ManageGroups, "list-members",
ParseIdBody(id, numericKey: "groupId", stringKey: "groupId"));
}
[HttpPost("{id}/members")]
public async Task<object?> AddMember([FromRoute("id")] string id, [FromBody] AddMemberRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
var numericId = long.TryParse(id, out var nid) ? nid : 0L;
return await Forward(IdentityEndpoints.ManageGroups, "add-member", new Dictionary<string, object?>
{
["groupId"] = numericId,
["userId"] = request.UserId,
["role"] = request.Role,
["expiresAt"] = request.ExpiresAt
});
}
[HttpPut("{id}/members/{userId}")]
public async Task<object?> UpdateMember(
[FromRoute("id")] string id, [FromRoute("userId")] string userId,
[FromBody] UpdateMemberRequest request)
{
if (ValidateRequest(request) is { } problem) return problem;
return await Forward(IdentityEndpoints.ManageGroups, "update-member", new Dictionary<string, object?>
{
["groupId"] = long.TryParse(id, out var gid) ? gid : 0L,
["userId"] = long.TryParse(userId, out var uid) ? uid : 0L,
["role"] = request.Role
});
}
[HttpDelete("{id}/members/{userId}")]
public async Task<object?> RemoveMember([FromRoute("id")] string id, [FromRoute("userId")] string userId)
{
return await Forward(IdentityEndpoints.ManageGroups, "remove-member",
new Dictionary<string, object?>
{
["groupId"] = long.TryParse(id, out var gid) ? gid : 0,
["userId"] = long.TryParse(userId, out var uid) ? uid : 0
});
}
[HttpGet("users/{userId}/groups")]
public async Task<object?> UserGroups([FromRoute("userId")] string userId)
{
return await Forward(IdentityEndpoints.ManageGroups, "user-groups",
new Dictionary<string, object?>
{
["userId"] = long.TryParse(userId, out var uid) ? uid : 0L
});
}
[HttpGet("{id}/members/{userId}/check")]
public async Task<object?> IsMember([FromRoute("id")] string id, [FromRoute("userId")] string userId)
{
return await Forward(IdentityEndpoints.ManageGroups, "is-member",
new Dictionary<string, object?>
{
["groupId"] = long.TryParse(id, out var gid) ? gid : 0L,
["userId"] = long.TryParse(userId, out var uid) ? uid : 0L
});
}
}