mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Implemented automated asset counter into asset creation and asset update, Fixed uid visible in owner attribute in Assets frontend
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user