Example #1
0
        private BlockRenderContext CreateRenderContext(Course course, Slide slide,
                                                       AbstractManualSlideChecking manualChecking = null,
                                                       int?exerciseSubmissionId = null, List <string> groupsIds        = null, bool isLti = false,
                                                       bool autoplay            = false, bool isManualCheckingReadonly = false, bool defaultProhibitFurtherReview = true,
                                                       int manualCheckingsLeft  = 0)
        {
            /* ExerciseController will fill blockDatas later */
            var blockData = slide.Blocks.Select(b => (dynamic)null).ToArray();

            return(new BlockRenderContext(
                       course,
                       slide,
                       slide.Info.DirectoryRelativePath,
                       blockData,
                       isGuest: false,
                       revealHidden: User.HasAccessFor(course.Id, CourseRole.Instructor),
                       manualChecking: manualChecking,
                       manualCheckingsLeft: manualCheckingsLeft,
                       canUserFillQuiz: false,
                       groupsIds: groupsIds,
                       isLti: isLti,
                       autoplay: autoplay,
                       isManualCheckingReadonly: isManualCheckingReadonly,
                       defaultProhibitFurtherReview: defaultProhibitFurtherReview
                       )
            {
                VersionId = exerciseSubmissionId
            });
        }
Example #2
0
        private BlockRenderContext CreateRenderContext(Course course, Slide slide,
                                                       AbstractManualSlideChecking manualChecking = null,
                                                       int?exerciseSubmissionId = null,
                                                       List <string> groupsIds  = null,
                                                       bool isLti    = false,
                                                       bool autoplay = false,
                                                       bool isManualCheckingReadonly = false)
        {
            /* ExerciseController will fill blockDatas later */
            var blockData = slide.Blocks.Select(b => (dynamic)null).ToArray();

            return(new BlockRenderContext(
                       course,
                       slide,
                       slide.Info.DirectoryRelativePath,
                       blockData,
                       false,
                       User.HasAccessFor(course.Id, CourseRole.Instructor),
                       manualChecking,
                       false,
                       groupsIds,
                       isLti,
                       autoplay,
                       isManualCheckingReadonly
                       )
            {
                VersionId = exerciseSubmissionId
            });
        }
Example #3
0
        private async Task <CoursePageModel> CreateCoursePageModel(
            Course course, Slide slide,
            AbstractManualSlideChecking manualChecking, int?exerciseSubmissionId = null,
            List <string> groupsIds       = null,
            bool autoplay                 = false,
            bool isManualCheckingReadonly = false)
        {
            var userId = User.Identity.GetUserId();

            if (manualChecking != null)
            {
                userId = manualChecking.UserId;
            }

            var visiter = await VisitSlide(course.Id, slide.Id, userId);

            var maxSlideScore = GetMaxSlideScoreForUser(course, slide, userId);

            var score = Tuple.Create(visiter.Score, maxSlideScore);
            var model = new CoursePageModel
            {
                UserId             = userId,
                CourseId           = course.Id,
                CourseTitle        = course.Title,
                Slide              = slide,
                Score              = score,
                BlockRenderContext = CreateRenderContext(course, slide, manualChecking, exerciseSubmissionId, groupsIds, autoplay: autoplay, isManualCheckingReadonly: isManualCheckingReadonly),
                ManualChecking     = manualChecking,
                ContextManualCheckingUserGroups = manualChecking != null?groupsRepo.GetUserGroupsNamesAsString(course.Id, manualChecking.UserId, User) : "",
                                                      IsGuest = false
            };

            return(model);
        }
Example #4
0
 private string GetAdminCheckActionName(AbstractManualSlideChecking queueItem)
 {
     if (queueItem is ManualQuizChecking)
     {
         return("CheckQuiz");
     }
     if (queueItem is ManualExerciseChecking)
     {
         return("CheckExercise");
     }
     return("");
 }
Example #5
0
        private async Task <CoursePageModel> CreateCoursePageModel(
            Course course, Slide slide,
            AbstractManualSlideChecking manualChecking, int?exerciseSubmissionId = null,
            List <string> groupsIds       = null,
            bool autoplay                 = false,
            bool isManualCheckingReadonly = false)
        {
            var userId = User.Identity.GetUserId();

            if (manualChecking != null)
            {
                userId = manualChecking.UserId;
            }

            var visiter = await VisitSlide(course.Id, slide.Id, userId).ConfigureAwait(false);

            var maxSlideScore = GetMaxSlideScoreForUser(course, slide, userId);
            var defaultProhibitFurtherReview = groupsRepo.GetDefaultProhibitFutherReviewForUser(course.Id, userId, User);
            var manualCheckingsLeft          = manualChecking != null?ControllerUtils.GetManualCheckingsCountInQueue(slideCheckingsRepo, groupsRepo, User, course.Id, slide, groupsIds) : 0;

            var score = Tuple.Create(visiter.Score, maxSlideScore);
            var model = new CoursePageModel
            {
                UserId             = userId,
                CourseId           = course.Id,
                CourseTitle        = course.Title,
                Slide              = slide,
                Score              = score,
                BlockRenderContext = CreateRenderContext(
                    course, slide, manualChecking, exerciseSubmissionId, groupsIds,
                    autoplay: autoplay,
                    isManualCheckingReadonly: isManualCheckingReadonly,
                    defaultProhibitFurtherReview: defaultProhibitFurtherReview, manualCheckingsLeft: manualCheckingsLeft),
                ManualChecking = manualChecking,
                ContextManualCheckingUserGroups = manualChecking != null?groupsRepo.GetUserGroupsNamesAsString(course.Id, manualChecking.UserId, User) : "",
                                                      ContextManualCheckingUserArchivedGroups = manualChecking != null?groupsRepo.GetUserGroupsNamesAsString(course.Id, manualChecking.UserId, User, onlyArchived : true) : "",
                                                                                                    IsGuest      = false,
                                                                                                    SlideEditUrl = GetGitEditLink(course, slide.Info.SlideFile)
            };

            return(model);
        }
Example #6
0
        private (string, string) GetGroupNames(Course course, AbstractManualSlideChecking manualChecking)
        {
            var notArchivedGroupNames = "";
            var archivedGroupNames    = "";

            if (manualChecking != null)
            {
                var userGroups = groupsRepo.GetUsersGroups(new List <string> {
                    course.Id
                }, new List <string> {
                    manualChecking.UserId
                }, User,
                                                           actual: true, archived: true, 100);
                if (userGroups.ContainsKey(manualChecking.UserId))
                {
                    notArchivedGroupNames = string.Join(", ", groupsRepo.GetUserGroupsNames(userGroups[manualChecking.UserId].Where(g => !g.IsArchived)));
                    archivedGroupNames    = string.Join(", ", groupsRepo.GetUserGroupsNames(userGroups[manualChecking.UserId].Where(g => g.IsArchived)));
                }
            }

            return(notArchivedGroupNames, archivedGroupNames);
        }
Example #7
0
        private async Task <CoursePageModel> CreateCoursePageModel(
            Course course, Slide slide,
            AbstractManualSlideChecking manualChecking, int?exerciseSubmissionId = null,
            List <string> groupsIds       = null,
            bool autoplay                 = false,
            bool isManualCheckingReadonly = false)
        {
            var userId = User.Identity.GetUserId();

            if (manualChecking != null)
            {
                userId = manualChecking.UserId;
            }

            var defaultProhibitFurtherReview = groupsRepo.GetDefaultProhibitFutherReviewForUser(course.Id, userId, User);
            var manualCheckingsLeftInQueue   = manualChecking != null?ControllerUtils.GetManualCheckingsCountInQueue(slideCheckingsRepo, groupsRepo, User, course.Id, slide, groupsIds) : 0;

            var(notArchivedGroupNames, archivedGroupNames) = GetGroupNames(course, manualChecking);

            var model = new CoursePageModel
            {
                UserId             = userId,
                CourseId           = course.Id,
                CourseTitle        = course.Title,
                Slide              = slide,
                BlockRenderContext = CreateRenderContext(
                    course, slide, manualChecking, exerciseSubmissionId, groupsIds,
                    autoplay: autoplay,
                    isManualCheckingReadonly: isManualCheckingReadonly,
                    defaultProhibitFurtherReview: defaultProhibitFurtherReview, manualCheckingsLeftInQueue: manualCheckingsLeftInQueue),
                ManualChecking = manualChecking,
                ContextManualCheckingUserGroups         = notArchivedGroupNames,
                ContextManualCheckingUserArchivedGroups = archivedGroupNames,
                IsGuest = false,
            };

            return(model);
        }
Example #8
0
        public async Task <ActionResult> SlideById(string courseId, string slideId = "", int?checkQueueItemId = null, int?version = null, int autoplay = 0)
        {
            if (slideId.Contains("_"))
            {
                slideId = slideId.Substring(slideId.LastIndexOf('_') + 1);
            }

            var groupsIds = Request.GetMultipleValuesFromQueryString("group");

            if (!Guid.TryParse(slideId, out var slideGuid))
            {
                return(HttpNotFound());
            }

            if (string.IsNullOrWhiteSpace(courseId))
            {
                if (string.IsNullOrWhiteSpace(slideId))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(RedirectToSlideById(slideGuid));
            }

            var course = courseManager.FindCourse(courseId);

            if (course == null)
            {
                return(HttpNotFound());
            }

            var visibleUnits = unitsRepo.GetVisibleUnits(course, User);
            var isGuest      = !User.Identity.IsAuthenticated;

            var slide = slideGuid == Guid.Empty ? GetInitialSlideForStartup(courseId, visibleUnits) : course.FindSlideById(slideGuid);

            if (slide == null)
            {
                return(HttpNotFound());
            }

            AbstractManualSlideChecking queueItem = null;
            var isManualCheckingReadonly          = false;

            if (User.HasAccessFor(courseId, CourseRole.Instructor) && checkQueueItemId != null)
            {
                if (slide is QuizSlide)
                {
                    queueItem = slideCheckingsRepo.FindManualCheckingById <ManualQuizChecking>(checkQueueItemId.Value);
                }
                if (slide is ExerciseSlide)
                {
                    queueItem = slideCheckingsRepo.FindManualCheckingById <ManualExerciseChecking>(checkQueueItemId.Value);
                }

                if (queueItem == null)
                {
                    /* It's possible when checking has not been fully checked, lock has been released, but after it user re-send his solution and we removed old waiting checking */
                    var fakeQueueItem = slide is QuizSlide ? (AbstractManualSlideChecking) new ManualQuizChecking() : new ManualExerciseChecking();
                    return(RedirectToAction("CheckingQueue", "Admin", new
                    {
                        courseId = courseId,
                        message = "checking_removed"
                    }));
                }
            }

            var model = isGuest ?
                        CreateGuestCoursePageModel(course, slide, autoplay > 0) :
                        await CreateCoursePageModel(course, slide, queueItem, version, groupsIds, autoplay > 0, isManualCheckingReadonly);

            if (!string.IsNullOrEmpty(Request.QueryString["error"]))
            {
                model.Error = Request.QueryString["error"];
            }

            if (!visibleUnits.Contains(model.Slide.Info.Unit))
            {
                return(HttpNotFound("Slide is hidden " + slideGuid));
            }
            return(View("Slide", model));
        }
Example #9
0
        public async Task <ActionResult> SlideById(string courseId, string slideId = "", int?checkQueueItemId = null, int?version = null, int autoplay = 0)
        {
            if (slideId.Contains("_"))
            {
                slideId = slideId.Substring(slideId.LastIndexOf('_') + 1);
            }

            var groupsIds = Request.GetMultipleValues("group");

            Guid slideGuid;

            if (!Guid.TryParse(slideId, out slideGuid))
            {
                return(HttpNotFound());
            }

            if (string.IsNullOrWhiteSpace(courseId))
            {
                if (string.IsNullOrWhiteSpace(slideId))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(RedirectToSlideById(slideGuid));
            }

            var course = courseManager.FindCourse(courseId);

            if (course == null)
            {
                return(HttpNotFound());
            }

            var visibleUnits = unitsRepo.GetVisibleUnits(course, User);
            var isGuest      = !User.Identity.IsAuthenticated;

            var slide = slideGuid == Guid.Empty ? GetInitialSlideForStartup(courseId, course, visibleUnits) : course.FindSlideById(slideGuid);

            if (slide == null)
            {
                return(HttpNotFound());
            }

            AbstractManualSlideChecking queueItem = null;
            var isManualCheckingReadonly          = false;

            if (User.HasAccessFor(courseId, CourseRole.Instructor) && checkQueueItemId != null)
            {
                if (slide is QuizSlide)
                {
                    queueItem = slideCheckingsRepo.FindManualCheckingById <ManualQuizChecking>(checkQueueItemId.Value);
                }
                if (slide is ExerciseSlide)
                {
                    queueItem = slideCheckingsRepo.FindManualCheckingById <ManualExerciseChecking>(checkQueueItemId.Value);
                }

                if (queueItem == null)
                {
                    return(HttpNotFound());
                }

                /* If lock time is finished */
                if (!queueItem.IsLockedBy(User.Identity) && queueItem.HasLastLockedBy(User.Identity))
                {
                    return(RedirectToAction(GetAdminQueueActionName(queueItem), "Admin", new
                    {
                        CourseId = courseId,
                        group = string.Join(",", groupsIds),
                        done = queueItem.IsChecked,
                        message = "time_is_over",
                    }));
                }

                /* If it's not locked then lock them! */
                if (!queueItem.IsLocked)
                {
                    return(RedirectToAction(GetAdminCheckActionName(queueItem), "Admin", new
                    {
                        CourseId = courseId,
                        group = string.Join(",", groupsIds),
                        id = queueItem.Id,
                        recheck = true
                    }));
                }

                if (queueItem.IsLocked && !queueItem.IsLockedBy(User.Identity))
                {
                    isManualCheckingReadonly = true;
                }
            }

            var model = isGuest ?
                        CreateGuestCoursePageModel(course, slide, autoplay > 0) :
                        await CreateCoursePageModel(course, slide, queueItem, version, groupsIds, autoplay > 0, isManualCheckingReadonly);

            if (!string.IsNullOrEmpty(Request.QueryString["error"]))
            {
                model.Error = Request.QueryString["error"];
            }

            if (!visibleUnits.Contains(model.Slide.Info.Unit))
            {
                return(HttpNotFound("Slide is hidden " + slideGuid));
            }
            return(View("Slide", model));
        }