public async Task <IActionResult> DeleteADUser(string contactEmail) { _logger.LogDebug("DeleteADUser"); if (await _userApiService.CheckUserExistsInAAD(contactEmail)) { await _userApiService.DeleteUserInAAD(contactEmail); } else { return(NotFound(contactEmail)); } _logger.LogDebug("User with contact email {contactEmail} deleted", contactEmail); return(NoContent()); }
public async Task <UserDto> AllocateToService(UserType userType, Application application, TestType testType, bool isProdUser, int expiresInMinutes = 10, string allocatedBy = null) { var users = await GetAllUsers(userType, testType, application, isProdUser); _logger.LogDebug($"Found {users.Count} user(s) of type '{userType}', test type '{testType}' and application '{application}'"); var allocations = await CreateAllocationsForUsersIfRequired(users); var userId = GetUnallocatedUserId(allocations); if (userId == null) { _logger.LogDebug($"All {users.Count} users were already allocated"); var number = await IterateUserNumber(userType, application, isProdUser, testType); _logger.LogDebug($"Iterated user number to {number}"); await CreateNewUserInTestApi(userType, application, testType, isProdUser, number); _logger.LogDebug( $"A new user with user type {userType}, application {application} and number {number} has been created"); var newUser = await GetUserIdByUserTypeApplicationAndNumber(userType, application, number, isProdUser); _logger.LogDebug($"A new user with Id {newUser.Id} has been retrieved"); await CreateNewAllocation(newUser.Id); _logger.LogDebug($"The new user with Id {newUser.Id} has a new allocation"); userId = newUser.Id; } var user = await GetUserById(userId.Value); if (!await IsRecentlyCreated(user.Username) && await UserDoesNotExistInAAD(user.Username)) { _logger.LogDebug($"The user with username {user.Username} does not already exist in AAD"); var response = await CreateUserInAAD(user); _logger.LogDebug($"The user with username {response.Username} created in AAD"); if (response.Username != user.Username) { await _userApiService.DeleteUserInAAD(response.Username); _logger.LogDebug($"The newly created user was a duplicate of an existing AAD user and was therefore deleted"); } else { await AddNewUserToRecentlyCreatedList(user.Username); _logger.LogDebug($"The ad user has been added to the list of recently created users with username {user.Username}"); var groupsCount = await AddGroupsToUser(user, response.UserId); _logger.LogDebug($"The ad user now has {groupsCount} groups"); } } await AllocateUser(user.Id, expiresInMinutes, allocatedBy); _logger.LogDebug($"User with username '{user.Username}' has been allocated"); return(user); }