Added filter to /Users/Index to filter out fields

This commit is contained in:
2025-09-28 22:08:08 +02:00
parent 6297f9dc19
commit 5c9a066ded
3 changed files with 33 additions and 3 deletions

View File

@@ -17,16 +17,25 @@ public class UsersController : Controller
}
[HttpGet("Index")]
public async Task<IEnumerable<Dictionary<string, string>>> Index(string? uid = null)
public async Task<IEnumerable<Dictionary<string, string>>> Index(UsersIndexRequestModel requestModel)
{
string? uid = requestModel.Uid;
List<string> attributes = ["cn", "sn", "title", "uid", "jpegPhoto", "userPassword", "description"];
if (!requestModel.Cn) attributes.Remove("cn");
if (!requestModel.Sn) attributes.Remove("sn");
if (!requestModel.Title) attributes.Remove("title");
if (!requestModel.JpegPhoto) attributes.Remove("jpegPhoto");
if (!requestModel.UserPassword) attributes.Remove("userPassword");
if (!requestModel.Description) attributes.Remove("description");
if (uid is null)
{
var users = await _ldap.ListUsersAsync();
var users = await _ldap.ListUsersAsync([.. attributes]);
return users;
}
else
{
var user = await _ldap.GetUserByUidAsync(uid);
var user = await _ldap.GetUserByUidAsync(uid, [.. attributes]);
return [user];
}
}