public async Task <IActionResult> CompareEnvironments(int id) { var folder = await _foldersProvider.GetActiveFolder(); if (User.Identity.IsAuthenticated) { var user = await _usersProvider.GetUser(User.GetUserId()); folder = user.SelectedFolder; } var runs = await _runsProvider.GetTestsForComparison(id, folder); var testInfo = await _runsProvider.GetAllTestsInfo(); var model = new List <ViewTest>(); foreach (var item in runs) { var info = testInfo.FirstOrDefault(p => p.TestName == item?.Name + ".py"); if (info == null) { continue; } var newTest = new ViewTest(item) { SuitName = info.SuiteName, Author = info.AuthorLogin }; model.Add(newTest); } return(View(model)); }
public async Task <IActionResult> GetStatsForRun(string environment) { var model = new List <StatsViewModel>(); var folder = await _foldersProvider.GetActiveFolder(); if (User.Identity.IsAuthenticated) { var user = await _usersProvider.GetUser(User.GetUserId()); folder = user.SelectedFolder; } var items = await _runsProvider.GetLatestRunsForEnvironment(environment, folder); foreach (var item in items.OrderBy(p => p.ReportTime)) { model.Add(new StatsViewModel { Date = item.ReportTime.ToString("d"), Passed = item.Passed, Failed = item.Failed, Errors = item.Errors, Skipped = item.Skipped }); } return(Json(model)); }
public bool TryLogin(string username, string password) { if (_usersDb.GetUser(username, password) is null) { return(false); } CurrentUser = _usersDb.GetUser(username, password); return(true); }
public async Task <AccountModel> CreateAccount(AccountCreationModel accountCreationModel) { if (accountCreationModel == null) { _logger.LogError($"Creating an account failed - no data was passed"); throw new BadRequestException($"No data for account creation was passed"); } var userId = accountCreationModel.UserId; _logger.LogInformation($"Creating an account for user {userId}"); var user = await _usersProvider.GetUser(userId); if (user == null) { _logger.LogError($"Creating an account for user {userId} failed - no user found"); throw new NotFoundException($"No user {userId} has been found. Not possible to create the account"); } var accountExists = await IsAccountCreated(userId); if (accountExists) { _logger.LogError($"Account for the user {userId} is already created"); throw new BadRequestException($"Account for the user {userId} already exists"); } var account = await CreateNewAccount(accountCreationModel, user); _logger.LogInformation($"The account for user {userId} has been created"); return(_mapper.Map <AccountModel>(account)); }
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var controller = context.Controller as Controller; if (controller != null) { var folder = await _foldersProvider.GetActiveFolder(); if (context.HttpContext.User.Identity.IsAuthenticated) { controller.ViewBag.isCollapsed = context.HttpContext.Session.GetString("isCollapsed"); var contextUser = context.HttpContext.User; var userId = contextUser.GetUserId(); var userProfile = await _usersProvider.GetUser(userId); if (userProfile != null) { controller.ViewBag.user = userProfile; folder = userProfile.SelectedFolder; var messagesForUser = await _testLabProvider.GetMessagesForUser(userProfile.Id); var unreadMessages = messagesForUser.Where(p => !p.IsRead); controller.ViewBag.messages = unreadMessages; } } controller.ViewBag.runs = folder.Runs; controller.ViewBag.folders = await _foldersProvider.GetAllFolders(); } await next(); }
public async Task <ActionResult> EditUser(UserViewModel viewmodel) { var user = await _usersProvider.GetUser(Convert.ToInt32(viewmodel.Id)); user.NickName = viewmodel.NickName; user.PasswordHash = viewmodel.Password; IdentityResult res = await UserManager.UpdateAsync(user); if (!res.Succeeded) { return(View("_UserEdit", viewmodel)); } return(RedirectToAction("Users")); }
public async Task <IActionResult> Account() { var model = new AccountViewModel(); var user = await _usersProvider.GetUser(User.GetUserId()); var userManager = await _userManager.FindByIdAsync(User.GetUserId()); model.Name = user.Name; model.Email = userManager.Email; model.GitHubLogin = user.GitHubAccount; model.GitHubToken = user.GitHubToken; model.GitHubAliases = user.GithubAliases != null?string.Join(',', user.GithubAliases) : null; return(View(model)); }
private async Task <UserContext> GetUserContext(HttpContext context) { var userGuid = GetUserGuidFromContext(context); var user = await _usersProvider.GetUser(userGuid); if (user == null) { throw new DomainException(ErrorCode.UserNotFound); } return(new UserContext(user.Id, user.UserGuid, user.IsAdmin)); }
public async Task <ActionResult <UserModel> > Get(string email) { var user = await _usersProvider.GetUser(email); return(Ok(user)); }
public async Task <IActionResult> SwitchState(int id, int statusId, string returnurl) { var test = await _testLabProvider.GetTest(id); var who = await _usersProvider.GetUser(User.GetUserId()); var statusType = (Status)statusId; var historyItem = new TestCaseHistory { Author = who, Message = $@"changed status from <strong>{test.Status.GetDescription()}</strong> to <strong>{statusType.GetDescription()}</strong>" }; switch (statusType) { case Status.New: break; case Status.ReadyForAutomation: break; case Status.InProgress: test.Assignee = who; test.StartedOn = DateTime.Now; if (!string.IsNullOrEmpty(who.GitHubToken)) { var gitClient = new GithubApiClient(who.GitHubAccount, who.GitHubToken); gitClient.AddAssignees(test.GitHubId, new [] { who.GitHubAccount }); } break; case Status.ToCrossPlatform: break; case Status.ReadyForReview: return(RedirectToAction("SubmitForReview", "TestLab", new { @id = id })); case Status.ReviewStarted: test.Reviewer = who; if (!string.IsNullOrEmpty(who.GitHubToken)) { var gitClient = new GithubApiClient(who.GitHubAccount, who.GitHubToken); gitClient.AddReviewer(test.PullRequestId, new [] { who.GitHubAccount }); } break; case Status.CannotAutomate: break; case Status.Finished: test.FinishedOn = DateTime.Now; break; case Status.ChangesRequested: return(RedirectToAction("RequestChange", "TestLab", new { @id = id })); case Status.Fixed: break; default: throw new ArgumentOutOfRangeException(); } test.Status = statusType; test.HistoryItems.Add(historyItem); await _testLabProvider.UpdateTest(test); if (string.IsNullOrEmpty(returnurl)) { return(Redirect(Url.RouteUrl(new { controller = "TestLab", action = "TestSuite" }) + "/" + test.TestSuite.Id + "#test-" + test.Id)); } else { return(LocalRedirect(returnurl)); } }
public async Task <IActionResult> Index() { var folder = await _foldersProvider.GetActiveFolder(); SystemUser user = null; if (HttpContext.User.Identity.IsAuthenticated) { user = await _usersProvider.GetUser(HttpContext.User.GetUserId()); folder = user.SelectedFolder; } var platforms = new string[] { "osx", "win7", "win", "linux" }; var runs = folder.Runs; var model = new DashboardDataModel { FailedTests = new List <FailedTestPerPlatform>(), Users = await _usersProvider.GetAllUsers() }; foreach (var platform in platforms) { model.LatestStats.Add(await _runsProvider.GetLatestRunForEnvironment(platform, folder.Id)); } foreach (var run in runs.GroupBy(p => p.Environment).OrderBy(p => p.Key)) { var runner = run.OrderByDescending(p => p.ReportTime).FirstOrDefault(); model.LatestResults.Add(runner); var allTestsInfo = await _runsProvider.GetAllTestsInfo(); foreach (var test in runner.FailedTests) { var testInfo = allTestsInfo.FirstOrDefault(p => p.TestName == test + ".py"); var failedTest = new FailedTestPerPlatform { LinuxRunId = runs.Where(p => p.Environment == "linux").OrderByDescending(p => p.ReportTime).FirstOrDefault()?.Id, OsxRunId = runs.Where(p => p.Environment == "osx").OrderByDescending(p => p.ReportTime).FirstOrDefault()?.Id, Win10RunId = runs.Where(p => p.Environment == "win").OrderByDescending(p => p.ReportTime).FirstOrDefault()?.Id, Win7RunId = runs.Where(p => p.Environment == "win7").OrderByDescending(p => p.ReportTime).FirstOrDefault()?.Id, TestId = runs.OrderByDescending(p => p.ReportTime).Where(p => p.Tests != null).SelectMany(z => z.Tests).FirstOrDefault(q => q.Name == test)?.Id, Test = test, Author = testInfo?.AuthorLogin, Suit = testInfo?.SuiteName, CurrentUser = user, Linux = runs.OrderByDescending(p => p.ReportTime).FirstOrDefault(p => p.Environment == "linux")?.FailedTests.ToList().Exists(p => p == test), Windows7 = runs.OrderByDescending(p => p.ReportTime).FirstOrDefault(p => p.Environment == "win7")?.FailedTests.ToList().Exists(p => p == test), Osx = runs.OrderByDescending(p => p.ReportTime).FirstOrDefault(p => p.Environment == "osx")?.FailedTests.ToList().Exists(p => p == test), Windows10 = runs.OrderByDescending(p => p.ReportTime).FirstOrDefault(p => p.Environment == "win")?.FailedTests.ToList().Exists(p => p == test) }; model.FailedTests.Add(failedTest); } } model.FailedTests = model.FailedTests.Distinct().ToList(); //Historic data var groupedEnvironment = runs.GroupBy(p => p.Environment); model.HistoricData = new List <HistoricData>(); foreach (var grouping in groupedEnvironment) { var newHistoricData = new HistoricData { Platform = grouping.Key }; var groupedDate = grouping.GroupBy(p => p.ReportTime.Date).OrderBy(p => p.Key); newHistoricData.HistoricDataItems = new List <HistoricDataItems>(); foreach (var dt in groupedDate) { var item = dt.OrderByDescending(p => p.Total).FirstOrDefault(); if (item != null) { newHistoricData.HistoricDataItems.Add(new HistoricDataItems { DateLabel = dt.Key.ToShortDateString(), Blocked = item.Blocked, Failed = item.Failed, Passed = item.Passed, Skipped = item.Skipped, Total = item.Total }); } } model.HistoricData.Add(newHistoricData); } return(View(model)); }