Adapt welcome wallpaper to SGU gender
This commit is contained in:
@@ -11,6 +11,8 @@ public sealed class ActiveDirectorySynchronizer(
|
||||
BrokerOptions options,
|
||||
ILogger<ActiveDirectorySynchronizer> logger) : IActiveDirectorySynchronizer
|
||||
{
|
||||
private const string GenderMetadataPrefix = "SGU-Gender:";
|
||||
private const int InfoAttributeMaximumLength = 1024;
|
||||
private const int AccountDisabled = 0x0002;
|
||||
private const int NormalAccount = 0x0200;
|
||||
private static readonly AuthenticationTypes BindFlags =
|
||||
@@ -164,6 +166,7 @@ public sealed class ActiveDirectorySynchronizer(
|
||||
SetOptionalProperty(user, "l", profile.City);
|
||||
SetOptionalProperty(user, "st", profile.State);
|
||||
SetOptionalProperty(user, "postalCode", profile.PostalCode);
|
||||
SetGenderMetadata(user, profile.Gender, identity.UserName, logger);
|
||||
if (string.Equals(profile.EmployeeNumber, identity.NumericId, StringComparison.Ordinal))
|
||||
{
|
||||
SetOptionalProperty(user, "employeeID", profile.EmployeeNumber);
|
||||
@@ -201,6 +204,56 @@ public sealed class ActiveDirectorySynchronizer(
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetGenderMetadata(
|
||||
DirectoryEntry entry,
|
||||
InstitutionalGender? gender,
|
||||
string institutionalUser,
|
||||
ILogger logger)
|
||||
{
|
||||
if (gender is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string existing = Convert.ToString(entry.Properties["info"].Value) ?? string.Empty;
|
||||
string? updated = MergeGenderMetadata(existing, gender);
|
||||
if (updated is null)
|
||||
{
|
||||
logger.LogWarning(
|
||||
BrokerEventIds.DirectoryOptionalMetadataFailure,
|
||||
"Gender metadata was not written for {InstitutionalUser} because the Active Directory info attribute has no remaining capacity.",
|
||||
institutionalUser);
|
||||
return;
|
||||
}
|
||||
|
||||
entry.Properties["info"].Value = updated;
|
||||
}
|
||||
|
||||
internal static string? MergeGenderMetadata(
|
||||
string? existing,
|
||||
InstitutionalGender? gender)
|
||||
{
|
||||
if (gender is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string managedLine = $"{GenderMetadataPrefix} {gender}";
|
||||
string normalizedExisting = (existing ?? string.Empty)
|
||||
.Replace("\r\n", "\n", StringComparison.Ordinal)
|
||||
.Replace('\r', '\n');
|
||||
string[] preservedLines = string.IsNullOrEmpty(normalizedExisting)
|
||||
? []
|
||||
: normalizedExisting
|
||||
.Split('\n')
|
||||
.Where(line => !line.TrimStart().StartsWith(
|
||||
GenderMetadataPrefix,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
string updated = string.Join("\r\n", preservedLines.Append(managedLine));
|
||||
return updated.Length <= InfoAttributeMaximumLength ? updated : null;
|
||||
}
|
||||
|
||||
private void EnsureRoleGroupMembership(DirectoryEntry user, UserIdentity identity)
|
||||
{
|
||||
user.RefreshCache(["distinguishedName"]);
|
||||
|
||||
Reference in New Issue
Block a user