示例#1
0
        /// <inheritdoc />
        public async Task <IEnumerable <BasicUser> > GetUsers(Guid campusId, ClaimsPrincipal user, UserScope scope)
        {
            var campus = await _campusDbService.GetById(campusId);

            AuthorizeHubLeadForCampus(campus, user);

            var users = await _graphGroupService.GetGroupMembers(campus.AadGroupId);

            if (scope == UserScope.Basic)
            {
                return(users.Select(BasicUser.FromGraphUser));
            }

            return(await _graphUserService.AddFullScope(users));
        }
示例#2
0
        public async Task DefineCampusLead(Guid userId, Guid campusId)
        {
            // get the user and campus
            var user = await FindById(userId);

            var campus = await _graphGroupService.GetGroupById(campusId);

            // find existing lead of campus (if possible)
            User existingLead = await GetLeadForCampus(campus.Id);

            if (existingLead != null)
            {
                throw new MccBadRequestException(
                          $"Unable to assign campus lead because there is already an existing lead defined ({existingLead.Mail})");
            }

            // make sure the user has the correct job title and campus assigned
            var userUpdate = new User()
            {
                Id          = userId.ToString(),
                JobTitle    = UserJobTitleCampusLead,
                Department  = campus.Id.ToString(),
                CompanyName = campus.Name
            };
            await _graphService.Client.Users[user.Id].Request().UpdateAsync(userUpdate);

            // add the campus lead to the campusLeads group
            await _graphGroupService.AddUserToGroup(user, _authorizationConfiguration.CampusLeadsGroupId);


            // change the manager of all members of the group to the new campus lead
            var campusMembers = await _graphGroupService.GetGroupMembers(campusId);

            // where() -> don't change the manager of the lead itself.
            foreach (var member in campusMembers.Where(m => m.Id != user.Id))
            {
                try
                {
                    await AssignManager(member, user.Id);
                }
                catch (Exception e)
                {
                    _appInsightsService.TrackException(null,
                                                       new Exception($"Could not assign manager {user.Id} to user {user.Id} ({user.MailNickname}).",
                                                                     e), Guid.Empty);
                }
            }
        }