From bd298874c466a1b1a44933c797ba717c4ce5328f Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Fri, 3 Oct 2025 21:27:00 +0200 Subject: [PATCH 1/2] Added Locations Delete CRUD element --- src/Controllers/LocationsController.cs | 18 ++++++++++++++++++ src/Services/LdapService.cs | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/Controllers/LocationsController.cs b/src/Controllers/LocationsController.cs index 1d997a6..bdcefc1 100644 --- a/src/Controllers/LocationsController.cs +++ b/src/Controllers/LocationsController.cs @@ -16,4 +16,22 @@ public class LocationsController : Controller return list; } + [HttpGet("Delete")] + public async Task Delete(string cn) + { + if (cn is null) { return false; } + return await Task.Run(() => + { + try + { + _ldap.DeleteLocation(cn); + return true; + } + catch (Exception) + { + return false; + } + }); + } + } diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index 8930cda..c5cb0d7 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -261,6 +261,12 @@ public partial class LdapService : IDisposable DeleteObjectByDn(dn); } + public void DeleteLocation(string cn) + { + string dn = PrependRDN($"cn={cn}", LocationsBaseDn); + DeleteObjectByDn(dn); + } + public async Task UpdateUser(string uid, string attributeName, string attributeValue) { await UpdateObject(UsersBaseDn, "uid", uid, attributeName, attributeValue); From 10e8e172e0f4af1c9002bc50cdd4df0159b76ee8 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Fri, 3 Oct 2025 21:30:48 +0200 Subject: [PATCH 2/2] Fixed empty Locations Index, cleaned up attribute magic values --- src/Services/LdapService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index c5cb0d7..b267708 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -45,15 +45,17 @@ public partial class LdapService : IDisposable public string UsersBaseDn => string.IsNullOrEmpty(_opts.UsersOu) ? _opts.BaseDn : $"{_opts.UsersOu},{_opts.BaseDn}"; public string GroupsBaseDn => string.IsNullOrEmpty(_opts.GroupsOu) ? _opts.BaseDn : $"{_opts.GroupsOu},{_opts.BaseDn}"; 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[] LocationsAttributes => ["l", "street", "description"]; public string[] GroupsAttributes => ["cn", "gidNumber", "description"]; public async Task>> ListLocationsAsync() { - return await ListObjectBy(LocationsBaseDn, "(ou=locations)", ["l", "street", "description"]); + return await ListObjectBy(LocationsBaseDn, "", LocationsAttributes); } public async Task>> ListUsersAsync() { - return await ListObjectBy(UsersBaseDn, "", ["cn", "sn", "title", "uid", "jpegPhoto", "userPassword", "description"]); + return await ListObjectBy(UsersBaseDn, "", UsersAttributes); } public async Task GetMigrationVersionAsync()