/// <summary> /// Searches for a group with the given name. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public Task Consume(ConsumeContext <IFindUserGroupByName> context) { var fetcher = RoleBasedDataFetcher.Create(_ldapService.ListUserGroups, manager => _ldapService.FindUserGroupsByManager(manager)); var group = fetcher.Execute().SingleOrDefault(x => x.Name == context.Message.UserGroup); return(context.RespondAsync(new FindUserGroupByNameResult(group))); }
/// <summary> /// Returns a list of user groups. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public Task Consume(ConsumeContext <IListUserGroups> context) { var fetcher = RoleBasedDataFetcher.Create(_ldapService.ListUserGroups, manager => _ldapService.FindUserGroupsByManager(manager)); var groups = fetcher.Execute(); return(context.RespondAsync(ListCommand.UserGroupsResult(groups.ToArray()))); }
/// <summary> /// Returns a list of departments managed by the logged in user. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public Task Consume(ConsumeContext <IListDepartments> context) { var fetcher = RoleBasedDataFetcher.Create(_ldapService.ListDepartments, _ldapService.FindDepartmentsByManager); var departments = fetcher.Execute(); return(context.RespondAsync(ListCommand.DepartmentsResult(departments.ToArray()))); }
/// <summary> /// Returns a list of access points. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public Task Consume(ConsumeContext <IListAccessPoints> context) { var fetcher = RoleBasedDataFetcher.Create( _databaseContext.AccessPoints.GetAll, manager => _databaseContext.AccessPoints.Filter(x => x.ManagedBy == manager)); var entities = fetcher.Execute(); var accessPoints = entities.Select(ConvertAccessPoint).ToArray(); return(context.RespondAsync(ListCommand.AccessPointsResult(accessPoints))); }
/// <summary> /// Lists access rights. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public Task Consume(ConsumeContext <IListAccessRights> context) { var accessPointFetcher = RoleBasedDataFetcher.Create( _databaseContext.AccessPoints.GetAll, manager => _databaseContext.AccessPoints.Filter(x => x.ManagedBy == manager)); var accessPoints = accessPointFetcher.Execute(); var accessPointIds = accessPoints.Select(x => x.AccessPointId).ToArray(); var accessRights = _databaseContext.AccessRights.Filter(x => x.AccessRules.Any(rule => accessPointIds.Contains(rule.AccessPoint.AccessPointId))); var visitor = new ConvertAccessRightsVisitor(); accessRights.ForEach(x => x.Accept(visitor)); return(context.RespondAsync(ListCommand.AccessRightsResult(visitor.UserAccessRightsDto.ToArray(), visitor.UserGroupAccessRightsDto.ToArray()))); }
/// <summary> /// Returns a list of users in the specified group. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public Task Consume(ConsumeContext <IListUsersInGroup> context) { var fetcher = RoleBasedDataFetcher.Create( () => _ldapService.GetUsersInGroup(context.Message.UserGroupName), manager => { var allUsers = _ldapService.GetUsersInGroup(context.Message.UserGroupName); var allowed = _ldapService.FindUsersByManager(manager); return(allUsers.Where(x => allowed.Any(y => y.UserName == x.UserName))); }); var users = fetcher.Execute(); return(context.RespondAsync(ListCommand.UsersInGroupResult(users.ToArray()))); }