Esempio n. 1
0
 public ActionResult Edit(RepositoryDetailModel model)
 {
     if (ModelState.IsValid)
     {
         var currentUserIsInAdminList = model.PostedSelectedAdministrators != null && model.PostedSelectedAdministrators.Contains(User.Id());
         if (currentUserIsInAdminList || User.IsInRole(Definitions.Roles.Administrator))
         {
             var existingRepo = RepositoryRepository.GetRepository(model.Id);
             var repoModel    = ConvertRepositoryDetailModel(model);
             MoveRepo(existingRepo, repoModel);
             try
             {
                 RepositoryRepository.Update(repoModel);
             }
             catch (System.Data.Entity.Infrastructure.DbUpdateException)
             {
                 MoveRepo(repoModel, existingRepo);
             }
             ViewBag.UpdateSuccess = true;
         }
         else
         {
             ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself);
         }
     }
     PopulateCheckboxListData(ref model);
     return(View(model));
 }
Esempio n. 2
0
        protected override void Update()
        {
            ConcurrentBag <Repository> populatedRepositories = new ConcurrentBag <Repository>();

            Parallel.ForEach(projectRepository.GetAll(), new ParallelOptions {
                MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
            }, project =>
            {
                IList <TFSAdvanced.Updater.Models.Repositories.Repository> repositories = GetAsync.FetchResponseList <TFSAdvanced.Updater.Models.Repositories.Repository>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories?api=1.0").Result;
                if (repositories == null)
                {
                    return;
                }
                Parallel.ForEach(repositories, new ParallelOptions {
                    MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                }, repo =>
                {
                    try
                    {
                        var populatedRepository = GetAsync.Fetch <TFSAdvanced.Updater.Models.Repositories.Repository>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories/{repo.name}?api=1.0").Result;

                        var repositoryDto = new Repository
                        {
                            Id             = populatedRepository.id,
                            Name           = populatedRepository.name,
                            PullRequestUrl = populatedRepository._links.pullRequests.href,
                            Url            = populatedRepository.remoteUrl,
                            Project        = new Project
                            {
                                Id   = populatedRepository.project.id,
                                Name = populatedRepository.project.name,
                                Url  = populatedRepository.project.url
                            }
                        };
                        var policyConfigurations = GetAsync.FetchResponseList <PolicyConfiguration>(requestData, $"{requestData.BaseAddress}/defaultcollection/{project.Id}/_apis/policy/configurations?api-version=2.0-preview.1").Result;

                        foreach (var configuration in policyConfigurations)
                        {
                            if (configuration.type.displayName == "Minimum number of reviewers")
                            {
                                repositoryDto.MinimumApproverCount = configuration.settings.minimumApproverCount;
                            }
                        }
                        populatedRepositories.Add(repositoryDto);
                    }
                    catch (Exception)
                    {
                    }
                });
            });
            var repositoryList = populatedRepositories.ToList();

            repositoryRepository.Update(repositoryList);
            updateStatusRepository.UpdateStatus(new UpdateStatus {
                LastUpdate = DateTime.Now, UpdatedRecords = repositoryList.Count, UpdaterName = nameof(RepositoryUpdater)
            });
        }
Esempio n. 3
0
 public ActionResult Edit(RepositoryDetailModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Administrators.Contains(User.Identity.Name.ToLowerInvariant()))
         {
             RepositoryRepository.Update(ConvertRepositoryDetailModel(model));
             ViewBag.UpdateSuccess = true;
         }
         else
         {
             ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself);
         }
     }
     PopulateEditData();
     return(View(model));
 }
Esempio n. 4
0
 public ActionResult Edit(RepositoryDetailModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.PostedSelectedAdministrators.Contains(User.Id()))
         {
             RepositoryRepository.Update(ConvertRepositoryDetailModel(model));
             ViewBag.UpdateSuccess = true;
         }
         else
         {
             ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself);
         }
     }
     PopulateCheckboxListData(ref model);
     return(View(model));
 }
Esempio n. 5
0
 public ActionResult Edit(RepositoryDetailModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Administrators.Contains(User.Id(), StringComparer.OrdinalIgnoreCase))
         {
             RepositoryRepository.Update(ConvertRepositoryDetailModel(model));
             ViewBag.UpdateSuccess = true;
         }
         else
         {
             ModelState.AddModelError("Administrators", Resources.Repository_Edit_CantRemoveYourself);
         }
     }
     PopulateEditData();
     return(View(model));
 }
Esempio n. 6
0
        protected override void Update()
        {
            var populatedRepositories = new ConcurrentBag <Repository>();

            Parallel.ForEach(projectRepository.GetAll(), new ParallelOptions {
                MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
            }, project =>
            {
                IList <TFSAdvanced.Updater.Models.Repositories.Repository> repositories = GetAsync.FetchResponseList <TFSAdvanced.Updater.Models.Repositories.Repository>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories?api=1.0", Logger).Result;
                if (repositories == null)
                {
                    return;
                }

                // policies are project scoped, so we only need to request once per project
                List <PolicyConfiguration> policyConfigurations = GetAsync.FetchResponseList <PolicyConfiguration>(requestData, $"{requestData.BaseAddress}/defaultcollection/{project.Id}/_apis/policy/configurations?api-version=2.0-preview.1", Logger).Result;

                Parallel.ForEach(repositories, new ParallelOptions {
                    MaxDegreeOfParallelism = AppSettings.MAX_DEGREE_OF_PARALLELISM
                }, repo =>
                {
                    try
                    {
                        TFSAdvanced.Updater.Models.Repositories.Repository populatedRepository = GetAsync.Fetch <TFSAdvanced.Updater.Models.Repositories.Repository>(requestData, $"{requestData.BaseAddress}/{project.Name}/_apis/git/repositories/{repo.name}?api=1.0").Result;

                        var repositoryDto = new Repository
                        {
                            Id             = populatedRepository.id,
                            Name           = populatedRepository.name,
                            PullRequestUrl = populatedRepository._links.pullRequests.href,
                            Url            = populatedRepository.remoteUrl,
                            Project        = new Project
                            {
                                Id   = populatedRepository.project.id,
                                Name = populatedRepository.project.name,
                                Url  = populatedRepository.project.url
                            }
                        };

                        foreach (PolicyConfiguration configuration in policyConfigurations)
                        {
                            if (configuration.type.id == MinimumReviewerPolicyId)
                            {
                                foreach (PolicyScope scope in configuration.settings.scope)
                                {
                                    if (scope.repositoryId == repositoryDto.Id)
                                    {
                                        // NOTE: there could be multiple reviewer policies in a repo (per branch) so this may not be the correct level to store
                                        // this setting
                                        repositoryDto.MinimumApproverCount = configuration.settings.minimumApproverCount;
                                        break;
                                    }
                                }
                            }
                        }
                        populatedRepositories.Add(repositoryDto);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                });
            });
            List <Repository> repositoryList = populatedRepositories.ToList();

            repositoryRepository.Update(repositoryList);
            updateStatusRepository.UpdateStatus(new UpdateStatus {
                LastUpdate = DateTime.Now, UpdatedRecords = repositoryList.Count, UpdaterName = nameof(RepositoryUpdater)
            });
        }