Implemented automated asset counter into asset creation and asset update, Fixed uid visible in owner attribute in Assets frontend

This commit is contained in:
2025-10-12 18:49:09 +02:00
parent 434b0952dc
commit a3c5a5341d
5 changed files with 82 additions and 33 deletions

View File

@@ -118,6 +118,51 @@ public partial class LdapService : IDisposable
return true;
}
public async Task<string> GetAssetCounterAndIncrementAsync()
{
AssetsMetadataModel assetModel = await GetAssetCounterAsync();
string returnValue = assetModel.CnCounter.ToString();
assetModel.CnCounter++;
await UpdateAssetCounterAsync(assetModel);
return returnValue;
}
public async Task<AssetsMetadataModel> GetAssetCounterAsync()
{
Dictionary<string, string> entry = (await ListObjectBy(_opts.BaseDn, _opts.AssetsOu, ["description"])).First();
try
{
string description = entry["description"];
return JsonSerializer.Deserialize<AssetsMetadataModel>(description) ?? throw new Exception($"Unable to deserialize description: {description}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Unable to retrieve asset counter due to exception: {ex.Message} - {ex.StackTrace}", [ex.Message, ex.StackTrace]);
throw;
}
}
public async Task<bool> UpdateAssetCounterAsync(AssetsMetadataModel assetMetadataModel)
{
await ConnectAndBind();
try
{
string dn = AssetsBaseDn; //PrependRDN($"", MigrationsBaseDn);
string targetText = JsonSerializer.Serialize(assetMetadataModel);
_logger.LogInformation("Setting the LDAP asset counter to {targetText} for {dn}", [targetText, dn]);
var modification = new LdapModification(
LdapModification.Replace,
new LdapAttribute("description", targetText)
);
await _conn.ModifyAsync(dn, modification);
}
catch (Exception)
{
return false;
}
return true;
}
public async Task<IEnumerable<UserModel>> ListUsersAsync(string[] attributes)
{
List<UserModel> returnValue = [];