mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Merge pull request #42 from LD-Reborn/38-feature-add-a-filter-to-usersindex
Added filter to /Users/Index to filter out fields
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
namespace Berufsschule_HAM.Models;
|
||||
|
||||
public class UsersIndexRequestModel
|
||||
{
|
||||
public string? Uid { get; set; } = null;
|
||||
public bool Cn { get; set; } = true;
|
||||
public bool Sn { get; set; } = true;
|
||||
public bool Title { get; set; } = true;
|
||||
public bool Description { get; set; } = true;
|
||||
public bool JpegPhoto { get; set; } = true;
|
||||
public bool UserPassword { get; set; } = true;
|
||||
}
|
||||
|
||||
public class UsersModifyRequestModel
|
||||
{
|
||||
public required string uid { get; set; }
|
||||
|
||||
@@ -55,11 +55,21 @@ public class LdapService : IDisposable
|
||||
return await ListObjectBy(UsersBaseDn, "", ["cn", "sn", "title", "uid", "jpegPhoto", "userPassword", "description"]);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Dictionary<string, string>>> ListUsersAsync(string[] attributes)
|
||||
{
|
||||
return await ListObjectBy(UsersBaseDn, "", attributes);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>> GetUserByUidAsync(string uid)
|
||||
{
|
||||
return (await ListObjectBy(UsersBaseDn, $"uid={uid}", ["cn", "sn", "title", "uid", "jpegPhoto", "userPassword", "description"])).First();
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>> GetUserByUidAsync(string uid, string[] attributes)
|
||||
{
|
||||
return (await ListObjectBy(UsersBaseDn, $"uid={uid}", attributes)).First();
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<Dictionary<string, string>>> ListDeviceAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user