Exemple #1
0
        public ActionResult BrowsePlay(int courseId, string userName, int playgroundId, string pathInfo)
        {
            var repo = PlaygroundRepository.Get(courseId, userName, playgroundId);
            var user = ApplicationUser.Current;

            // if this is the user's own repository OR the user is a super user OR the repository is shared,
            // then the repository should be browsable
            if (string.Equals(user.UserName, userName, StringComparison.OrdinalIgnoreCase) || user.IsInRole(UserRoles.SuperUserRole) || repo.GetIsShared())
            {
                return(_Browse(repo.FilePath, pathInfo));
            }
            // also allow instructors to view any repo for their courses
            try
            {
                var course = _GetCourse(courseId);
                if (course != null && user.IsInstructorForCourse(course))
                {
                    return(_Browse(repo.FilePath, pathInfo));
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
            return(new HttpNotFoundResult());
        }
Exemple #2
0
        public ActionResult ImportProject(ProjectImportPostData data)
        {
            var repo = _GetRepo(data);

            if (repo == null)
            {
                return(new HttpNotFoundResult());
            }

            Repository sourceRepo = null;
            int        courseId   = data.SourceCourseId > 0 ? data.SourceCourseId : data.CourseId;

            if (data.SourceType == ImportableProjects.Types.PLAYGROUND)
            {
                string userName = String.IsNullOrWhiteSpace(data.SourceUserName) ? data.UserName : data.SourceUserName;
                sourceRepo = PlaygroundRepository.Get(courseId, userName, data.SourceRepositoryId);
            }
            else if (data.SourceType == ImportableProjects.Types.WORKSPACE)
            {
                sourceRepo = WorkRepository.Get(courseId, data.UserName, data.SourceRepositoryId);
            }
            else if (data.SourceType == ImportableProjects.Types.SUBMISSION)
            {
                sourceRepo = SubmissionRepository.Get(courseId, data.UserName, data.SourceRepositoryId);
                sourceRepo.Checkout();
            }
            if (sourceRepo == null)
            {
                return(new HttpNotFoundResult());
            }

            try
            {
                repo.Commit("Before Import Project");
                repo.CopyFromRepository(sourceRepo);
                repo.Commit("After Import Project");
                return(Json("success"));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }