diff --git a/Wollmilchsau/Components/Pages/Home.razor b/Wollmilchsau/Components/Pages/Home.razor index cf42da1..5ddc24d 100644 --- a/Wollmilchsau/Components/Pages/Home.razor +++ b/Wollmilchsau/Components/Pages/Home.razor @@ -17,16 +17,7 @@ Office Anmeldung - - - - Umfragen - Hier kannst du an Umfragen teilnehmen. - - - Umfragen - - + diff --git a/Wollmilchsau/Components/Pages/Students/OfficeStudentHome.razor b/Wollmilchsau/Components/Pages/Students/OfficeStudentHome.razor index 99d1194..0d82e70 100644 --- a/Wollmilchsau/Components/Pages/Students/OfficeStudentHome.razor +++ b/Wollmilchsau/Components/Pages/Students/OfficeStudentHome.razor @@ -161,6 +161,7 @@ } private void CreateAccount(MouseEventArgs args) { + CurrentUser = OfficeState.Value.LdapUsers.GetValueOrDefault(CurrentUserName ?? string.Empty); if (CurrentUser is null) return; Dispatcher.Dispatch(new CreateNewAccountAction(CurrentUser)); } diff --git a/Wollmilchsau/Services/Ldap/ILdapService.cs b/Wollmilchsau/Services/Ldap/ILdapService.cs index 7c01c4e..1001ed9 100644 --- a/Wollmilchsau/Services/Ldap/ILdapService.cs +++ b/Wollmilchsau/Services/Ldap/ILdapService.cs @@ -6,6 +6,7 @@ public interface ILdapService { Task GetUserCount(CancellationToken cancellationToken = default); IAsyncEnumerable GetAllUsers(CancellationToken cancellationToken = default); + Task GetUser(string uid, CancellationToken cancellationToken = default); Task GetClassroomCount(CancellationToken cancellationToken = default); IAsyncEnumerable GetAllClassrooms(CancellationToken cancellationToken = default); } diff --git a/Wollmilchsau/Services/Ldap/LdapService.cs b/Wollmilchsau/Services/Ldap/LdapService.cs index c8c9cae..5140f29 100644 --- a/Wollmilchsau/Services/Ldap/LdapService.cs +++ b/Wollmilchsau/Services/Ldap/LdapService.cs @@ -39,6 +39,30 @@ public sealed class LdapService(IOptions options) : ILdapService } } + public Task GetUser(string uid, CancellationToken cancellationToken = default) + { + ArgumentException.ThrowIfNullOrWhiteSpace(uid); + cancellationToken.ThrowIfCancellationRequested(); + + using var connection = CreateConnection(); + var studentRoleDn = BuildDistinguishedName(_options.StudentsRole, _options.RoleBase); + var teacherRoleDn = BuildDistinguishedName(_options.TeacherRole, _options.RoleBase); + var request = new SearchRequest( + BuildDistinguishedName(_options.UserBase), + $"(&(uid={EscapeFilterValue(uid)}){GetSupportedRolesFilter(studentRoleDn, teacherRoleDn)})", + SearchScope.Subtree, + "uid", + "sn", + "givenName", + "memberOf"); + var response = (SearchResponse)connection.SendRequest(request); + + return Task.FromResult(response.Entries + .Cast() + .Select(entry => CreateUser(entry, studentRoleDn, teacherRoleDn)) + .SingleOrDefault()); + } + public Task GetClassroomCount(CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/Wollmilchsau/Store/OfficeStore/OfficeEffects.cs b/Wollmilchsau/Store/OfficeStore/OfficeEffects.cs index 75c8735..4ab466c 100644 --- a/Wollmilchsau/Store/OfficeStore/OfficeEffects.cs +++ b/Wollmilchsau/Store/OfficeStore/OfficeEffects.cs @@ -13,8 +13,8 @@ public sealed class OfficeEffects(IOfficeService officeService, ILdapService lda { if (action.UserId is null) return; var graphUser = await officeService.GetUserByAliasesAsync(action.UserId); - //var ldapUser = await ldapService.GetUserByUidAsync(action.UserId); - dispatcher.Dispatch(new UpdateCurrentUserInfoWithResultAction(action.UserId, graphUser, /*ldapUser.ValueOrDefault*/ null)); + var ldaUser = await ldapService.GetUser(action.UserId); + dispatcher.Dispatch(new UpdateCurrentUserInfoWithResultAction(action.UserId, graphUser, ldaUser)); } [EffectMethod] public async Task HandleCreateNewAccountAction(CreateNewAccountAction action, IDispatcher dispatcher)