public ActionResult SecureGetInfoRefs(String repositoryName, String service) { bool isPush = String.Equals("git-receive-pack", service, StringComparison.OrdinalIgnoreCase); if (!RepositoryIsValid(repositoryName)) { // This isn't a real repo - but we might consider allowing creation if (isPush && UserConfiguration.Current.AllowPushToCreate) { if (!RepositoryPermissionService.HasCreatePermission(User.Id())) { Log.Warning("GitC: User {UserId} is not allowed to do push-to-create", User.Id()); return(UnauthorizedResult()); } if (!TryCreateOnPush(repositoryName)) { return(UnauthorizedResult()); } } else { return(new HttpNotFoundResult()); } } var requiredLevel = isPush ? RepositoryAccessLevel.Push : RepositoryAccessLevel.Pull; if (RepositoryPermissionService.HasPermission(User.Id(), repositoryName, requiredLevel)) { return(GetInfoRefs(repositoryName, service)); } else { Log.Warning("GitC: SecureGetInfoRefs unauth because User {UserId} doesn't have permission {Permission} on repo {RepositoryName}", User.Id(), requiredLevel, repositoryName); return(UnauthorizedResult()); } }
public ActionResult Clone(Guid id, RepositoryDetailModel model) { if (!RepositoryPermissionService.HasCreatePermission(User.Id())) { return(RedirectToAction("Unauthorized", "Home")); } if (model != null && !String.IsNullOrEmpty(model.Name)) { model.Name = Regex.Replace(model.Name, @"\s", ""); } if (model != null && String.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", Resources.Repository_Create_NameFailure); } else if (ModelState.IsValid) { var repo_model = ConvertRepositoryDetailModel(model); if (RepositoryRepository.Create(repo_model)) { string targetRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, model.Name); if (!Directory.Exists(targetRepositoryPath)) { var source_repo = RepositoryRepository.GetRepository(id); string sourceRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, source_repo.Name); LibGit2Sharp.CloneOptions options = new LibGit2Sharp.CloneOptions() { IsBare = true, Checkout = false }; LibGit2Sharp.Repository.Clone(sourceRepositoryPath, targetRepositoryPath, options); using (var repo = new LibGit2Sharp.Repository(targetRepositoryPath)) { if (repo.Network.Remotes.Any(r => r.Name == "origin")) { repo.Network.Remotes.Remove("origin"); } } TempData["CloneSuccess"] = true; return(RedirectToAction("Index")); } else { RepositoryRepository.Delete(model.Id); ModelState.AddModelError("", Resources.Repository_Create_DirectoryExists); } } else { ModelState.AddModelError("", Resources.Repository_Create_Failure); } } ViewBag.ID = id; PopulateCheckboxListData(ref model); return(View(model)); }