mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added Locations Create CRUD element, Updated Locations LDAP service methods
This commit is contained in:
@@ -47,13 +47,13 @@ public partial class LdapService : IDisposable
|
||||
public string MigrationsBaseDn => string.IsNullOrEmpty(_opts.MigrationsOu) ? _opts.BaseDn : $"{_opts.MigrationsOu},{_opts.BaseDn}";
|
||||
public string[] UsersAttributes => ["cn", "sn", "title", "uid", "jpegPhoto", "userPassword", "description"];
|
||||
public string[] AssetsAttributes => ["CN", "description", "l", "owner", "serialNumber", "name"];
|
||||
public string[] LocationsAttributes => ["cn", "l", "street", "description"];
|
||||
public string[] LocationsAttributes => ["l", "description"];
|
||||
public string[] GroupsAttributes => ["cn", "gidNumber", "description"];
|
||||
public async Task<IEnumerable<LocationModel>> ListLocationsAsync()
|
||||
{
|
||||
IEnumerable<Dictionary<string, string>> locations = await ListObjectBy(LocationsBaseDn, "", LocationsAttributes);
|
||||
List<LocationModel> models = [];
|
||||
locations.ToList().ForEach(x => models.Add(new LocationModel(x) {Cn = x["cn"]}));
|
||||
locations.ToList().ForEach(x => models.Add(new LocationModel(x) {Location = x[LocationsAttributes[0]]}));
|
||||
return models;
|
||||
}
|
||||
|
||||
@@ -150,9 +150,9 @@ public partial class LdapService : IDisposable
|
||||
{
|
||||
return await GetLocationByCnAsync(cn, LocationsAttributes);
|
||||
}
|
||||
public async Task<LocationModel> GetLocationByCnAsync(string cn, string[] attributes)
|
||||
public async Task<LocationModel> GetLocationByCnAsync(string location, string[] attributes)
|
||||
{
|
||||
return new LocationModel((await ListObjectBy(LocationsBaseDn, $"cn={cn}", attributes)).First()) { Cn = cn };
|
||||
return new LocationModel((await ListObjectBy(LocationsBaseDn, $"l={location}", attributes)).First()) { Location = location };
|
||||
}
|
||||
|
||||
public async Task<AssetModel> GetAssetByCnAsync(string cn)
|
||||
@@ -196,15 +196,15 @@ public async Task CreateAsset(LdapAttributeSet attributeSet)
|
||||
}
|
||||
|
||||
public async Task CreateLocation(LdapAttributeSet attributeSet)
|
||||
{
|
||||
string? cn = attributeSet.GetAttribute("cn")?.StringValue;
|
||||
{
|
||||
string? cn = attributeSet.GetAttribute("l")?.StringValue;
|
||||
|
||||
if (string.IsNullOrEmpty(cn))
|
||||
throw new ArgumentException("AttributeSet must contain a cn attribute.");
|
||||
if (string.IsNullOrEmpty(cn))
|
||||
throw new ArgumentException("AttributeSet must contain an l attribute.");
|
||||
|
||||
string dn = PrependRDN($"cn={cn}", LocationsBaseDn);
|
||||
await CreateObject(dn, attributeSet);
|
||||
}
|
||||
string dn = PrependRDN($"l={cn}", LocationsBaseDn);
|
||||
await CreateObject(dn, attributeSet);
|
||||
}
|
||||
|
||||
public async Task<UserAuthenticationResult> AuthenticateUser(string username, string password)
|
||||
{
|
||||
@@ -302,9 +302,9 @@ public async Task CreateAsset(LdapAttributeSet attributeSet)
|
||||
await DeleteObjectByDnAsync(dn);
|
||||
}
|
||||
|
||||
public async Task DeleteLocationAsync(string cn)
|
||||
public async Task DeleteLocationAsync(string location)
|
||||
{
|
||||
string dn = PrependRDN($"cn={cn}", LocationsBaseDn);
|
||||
string dn = PrependRDN($"l={location}", LocationsBaseDn);
|
||||
await DeleteObjectByDnAsync(dn);
|
||||
}
|
||||
|
||||
@@ -324,9 +324,9 @@ public async Task CreateAsset(LdapAttributeSet attributeSet)
|
||||
await UpdateObject(GroupsBaseDn, "cn", cn, attributeName, attributeValue);
|
||||
}
|
||||
|
||||
public async Task UpdateLocation(string cn, string attributeName, string attributeValue)
|
||||
public async Task UpdateLocation(string location, string attributeName, string attributeValue)
|
||||
{
|
||||
await UpdateObject(LocationsBaseDn, "cn", cn, attributeName, attributeValue);
|
||||
await UpdateObject(LocationsBaseDn, "l", location, attributeName, attributeValue);
|
||||
}
|
||||
|
||||
public async Task UpdateAsset(string cn, string attributeName, string attributeValue)
|
||||
|
||||
Reference in New Issue
Block a user