Esempio n. 1
0
        public ActionResult GetInputData(int testId, int submissionId)
        {
            var testInfo = this.Data.Tests
                           .All()
                           .Where(t => t.Id == testId)
                           .Select(t => new
            {
                InputDataAsBytes = t.InputData,
                t.IsTrialTest,
                t.IsOpenTest,
                t.ProblemId,
                t.Problem.ContestId,
                t.Problem.ShowDetailedFeedback,
                t.Problem.Contest.AutoChangeTestsFeedbackVisibility
            })
                           .FirstOrDefault();

            if (testInfo == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resource.Test_not_found_message);
            }

            var hasPermissions = this.CheckIfUserHasProblemPermissions(testInfo.ProblemId);
            var isParticipant  = this.Data.Participants
                                 .All()
                                 .Any(p => p.UserId == this.UserProfile.Id && p.ContestId == testInfo.ContestId);

            var isUnofficialParticipant = this.Data.Submissions
                                          .All()
                                          .Any(s => s.Id == submissionId && !s.Participant.IsOfficial);

            bool shouldDisplayDetailedTestInfo = hasPermissions ||
                                                 ((testInfo.IsTrialTest ||
                                                   testInfo.ShowDetailedFeedback ||
                                                   testInfo.IsOpenTest) &&
                                                  isParticipant) ||
                                                 (testInfo.AutoChangeTestsFeedbackVisibility && isUnofficialParticipant);

            if (shouldDisplayDetailedTestInfo)
            {
                var inputDataViewModel = new TestInputDataViewModel
                {
                    InputData = testInfo.InputDataAsBytes.Decompress(),
                    TestId    = testId
                };

                return(this.PartialView("_GetInputDataPartial", inputDataViewModel));
            }

            throw new HttpException((int)HttpStatusCode.Forbidden, Resource.No_rights_message);
        }
        public ActionResult GetInputData(int testId, int submissionId)
        {
            var testInfo = this.testsData
                           .GetByIdQuery(testId)
                           .Select(t => new
            {
                InputDataAsBytes = t.InputData,
                t.IsTrialTest,
                t.IsOpenTest,
                t.ProblemId,
                t.Problem.ProblemGroup.ContestId,
                t.Problem.ShowDetailedFeedback,
                t.Problem.ProblemGroup.Contest.AutoChangeTestsFeedbackVisibility
            })
                           .FirstOrDefault();

            if (testInfo == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resource.Test_not_found_message);
            }

            if (!ShouldDisplayDetailedTestInfo())
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, Resource.No_rights_message);
            }

            var inputDataViewModel = new TestInputDataViewModel
            {
                InputData = testInfo.InputDataAsBytes.Decompress(),
                TestId    = testId
            };

            return(this.PartialView("_GetInputDataPartial", inputDataViewModel));

            bool ShouldDisplayDetailedTestInfo()
            {
                var userHasProblemPermissions = this.CheckIfUserHasProblemPermissions(testInfo.ProblemId);

                var userIsParticipant = this.participantsData
                                        .ExistsByContestAndUser(testInfo.ContestId, this.UserProfile.Id);

                var userHasTestPermissions = userIsParticipant &&
                                             (testInfo.IsTrialTest || testInfo.ShowDetailedFeedback || testInfo.IsOpenTest);

                var isUnofficialSubmission = !this.submissionsData.IsOfficialById(submissionId);

                var testIsOpenForEveryone = testInfo.AutoChangeTestsFeedbackVisibility && isUnofficialSubmission;

                return(userHasProblemPermissions || userHasTestPermissions || testIsOpenForEveryone);
            }
        }
        public ActionResult GetInputData(int id)
        {
            var testInfo = this.Data.Tests
                           .All()
                           .Where(t => t.Id == id)
                           .Select(t => new
            {
                InputDataAsBytes = t.InputData,
                t.IsTrialTest,
                t.IsOpenTest,
                t.ProblemId,
                t.Problem.ContestId,
                t.Problem.ShowDetailedFeedback
            })
                           .FirstOrDefault();

            if (testInfo == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resource.Test_not_found_message);
            }

            var hasPermissions = this.CheckIfUserHasProblemPermissions(testInfo.ProblemId);
            var isParticipant  = this.Data.Participants
                                 .All()
                                 .Any(p => p.UserId == this.UserProfile.Id && p.ContestId == testInfo.ContestId);

            if (hasPermissions ||
                ((testInfo.IsTrialTest || testInfo.ShowDetailedFeedback || testInfo.IsOpenTest) && isParticipant))
            {
                var inputDataViewModel = new TestInputDataViewModel
                {
                    InputData = testInfo.InputDataAsBytes.Decompress(),
                    TestId    = id
                };

                return(this.PartialView("_GetInputDataPartial", inputDataViewModel));
            }

            throw new HttpException((int)HttpStatusCode.Forbidden, Resource.No_rights_message);
        }