private async Task <UserListModel> GetUserListModel(List <UserRolesInfo> users) { var coursesForUsers = userRolesRepo.GetCoursesForUsers(); var courses = User.GetControllableCoursesId().ToList(); var currentUserId = User.Identity.GetUserId(); var userIds = users.Select(u => u.UserId).ToList(); var tempCoursesIds = tempCoursesRepo.GetTempCourses() .Select(t => t.CourseId) .ToHashSet(); var model = new UserListModel { CanToggleRoles = User.HasAccess(CourseRole.CourseAdmin), ShowDangerEntities = User.IsSystemAdministrator(), Users = users.Select(user => GetUserModel(user, coursesForUsers, courses, tempCoursesIds)).ToList(), UsersGroups = groupsRepo.GetUsersGroupsNamesAsStrings(courses, userIds, User, actual: true, archived: false), UsersArchivedGroups = groupsRepo.GetUsersGroupsNamesAsStrings(courses, userIds, User, actual: false, archived: true), CanViewAndToggleCourseAccesses = false, CanViewAndToogleSystemAccesses = User.IsSystemAdministrator(), CanViewProfiles = systemAccessesRepo.HasSystemAccess(currentUserId, SystemAccessType.ViewAllProfiles) || User.IsSystemAdministrator(), }; return(model); }
public async Task <ActionResult> Courses(string courseId = null, string courseTitle = null) { var isSystemAdministrator = User.IsSystemAdministrator(); var userId = User.Identity.GetUserId(); var courses = courseManager.GetCourses(); // Неопубликованные курсы не покажем тем, кто не имеет роли в них. if (!isSystemAdministrator) { var visibleCourses = unitsRepo.GetVisibleCourses(); var coursesInWhichUserHasAnyRole = userRolesRepo.GetCoursesWhereUserIsInRole(userId, CourseRole.Tester); var coursesWhereIAmStudent = groupsRepo.GetUserGroups(userId) .Select(g => g.CourseId) .Distinct(StringComparer.OrdinalIgnoreCase) .Where(c => visibleCourses.Contains(c)).ToList(); courses = courses.Where(c => coursesInWhichUserHasAnyRole.Contains(c.Id, StringComparer.OrdinalIgnoreCase) || coursesWhereIAmStudent.Contains(c.Id, StringComparer.OrdinalIgnoreCase)); } var incorrectChars = new string(CourseManager.GetInvalidCharacters().OrderBy(c => c).Where(c => 32 <= c).ToArray()); if (isSystemAdministrator) { courses = courses.OrderBy(course => course.Id, StringComparer.InvariantCultureIgnoreCase); } else { courses = courses.OrderBy(course => course.Title, StringComparer.InvariantCultureIgnoreCase); } var tempCourses = tempCoursesRepo.GetTempCourses().Select(c => c.CourseId).ToHashSet(); var model = new CourseListViewModel { Courses = courses .Select(course => new CourseViewModel { Id = course.Id, Title = course.Title, LastWriteTime = courseManager.GetLastWriteTime(course.Id), IsTemp = tempCourses.Contains(course.Id) }) .ToList(), LastTryCourseId = courseId, LastTryCourseTitle = courseTitle, InvalidCharacters = incorrectChars }; return(View(model)); }
private void TryCheckTempCoursesAndReloadIfNecessary(string courseIdToUpdate = null) { try { if (new DateTime(tempCoursesUpdateTime) > DateTime.Now.Subtract(tempCourseUpdateEvery)) { return; } if (courseIdToUpdate != null && IsTempCourseUpdatedRecent(courseIdToUpdate)) { return; } if (courseIdToUpdate == null) { Interlocked.Exchange(ref tempCoursesUpdateTime, DateTime.Now.Ticks); } var tempCoursesRepo = new TempCoursesRepo(); var tempCourses = tempCoursesRepo.GetTempCourses(); foreach (var tempCourse in tempCourses) { var courseId = tempCourse.CourseId; Course course = null; try { course = base.GetCourse(courseId); // Не используется FindCourse, иначе бесконечная рекурсия } catch (Exception ex) { log.Error(ex); } if (course == null || course.GetSlides(true).Count == 0 || courseId == courseIdToUpdate && tempCourse.LastUpdateTime < tempCourse.LoadingTime) { TryReloadCourse(courseId); tempCoursesRepo.UpdateTempCourseLastUpdateTimeAsync(courseId).Wait(); courseVersionFetchTime[courseId] = DateTime.Now; } else if (tempCourse.LastUpdateTime > tempCourse.LoadingTime) { courseVersionFetchTime[courseId] = DateTime.Now; } } } catch (Exception ex) { log.Error(ex); } }