From 479cc28bdf743b778f9528bd0e9b997541aead53 Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 23 Oct 2012 17:17:14 -0400 Subject: [PATCH] Add some common regex filters to the repository lists --- src/com/gitblit/client/EditTeamDialog.java | 27 ++++++++++++--- src/com/gitblit/client/EditUserDialog.java | 25 +++++++++++--- .../gitblit/wicket/pages/EditTeamPage.java | 11 +----- .../gitblit/wicket/pages/EditUserPage.java | 12 ++----- src/com/gitblit/wicket/pages/RootSubPage.java | 34 +++++++++++++++++++ 5 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/com/gitblit/client/EditTeamDialog.java b/src/com/gitblit/client/EditTeamDialog.java index 81146fc6..4350310e 100644 --- a/src/com/gitblit/client/EditTeamDialog.java +++ b/src/com/gitblit/client/EditTeamDialog.java @@ -315,18 +315,35 @@ public class EditTeamDialog extends JDialog { restricted.add(repo.name); } } + StringUtils.sortRepositorynames(restricted); - // remove repositories for which team already has a permission + List list = new ArrayList(); + // repositories + list.add(".*"); + // all repositories excluding personal repositories + list.add("[^~].*"); + String lastProject = null; + for (String repo : restricted) { + String projectPath = StringUtils.getFirstPathElement(repo); + if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) { + lastProject = projectPath; + if (!StringUtils.isEmpty(projectPath)) { + // regex for all repositories within a project + list.add(projectPath + "/.*"); + } + list.add(repo); + } + } + + // remove repositories for which user already has a permission if (permissions == null) { permissions = new ArrayList(); } else { for (RegistrantAccessPermission rp : permissions) { - restricted.remove(rp.registrant); + list.remove(rp.registrant); } } - - StringUtils.sortRepositorynames(restricted); - repositoryPalette.setObjects(restricted, permissions); + repositoryPalette.setObjects(list, permissions); } public void setUsers(List users, List selected) { diff --git a/src/com/gitblit/client/EditUserDialog.java b/src/com/gitblit/client/EditUserDialog.java index da75867f..e0966933 100644 --- a/src/com/gitblit/client/EditUserDialog.java +++ b/src/com/gitblit/client/EditUserDialog.java @@ -347,18 +347,35 @@ public class EditUserDialog extends JDialog { restricted.add(repo.name); } } + StringUtils.sortRepositorynames(restricted); + + List list = new ArrayList(); + // repositories + list.add(".*"); + // all repositories excluding personal repositories + list.add("[^~].*"); + String lastProject = null; + for (String repo : restricted) { + String projectPath = StringUtils.getFirstPathElement(repo); + if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) { + lastProject = projectPath; + if (!StringUtils.isEmpty(projectPath)) { + // regex for all repositories within a project + list.add(projectPath + "/.*"); + } + list.add(repo); + } + } // remove repositories for which user already has a permission if (permissions == null) { permissions = new ArrayList(); } else { for (RegistrantAccessPermission rp : permissions) { - restricted.remove(rp.registrant); + list.remove(rp.registrant); } } - - StringUtils.sortRepositorynames(restricted); - repositoryPalette.setObjects(restricted, permissions); + repositoryPalette.setObjects(list, permissions); } public void setTeams(List teams, List selected) { diff --git a/src/com/gitblit/wicket/pages/EditTeamPage.java b/src/com/gitblit/wicket/pages/EditTeamPage.java index a4e2c5e2..8908676e 100644 --- a/src/com/gitblit/wicket/pages/EditTeamPage.java +++ b/src/com/gitblit/wicket/pages/EditTeamPage.java @@ -36,11 +36,9 @@ import org.apache.wicket.model.Model; import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; -import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.models.RegistrantAccessPermission; -import com.gitblit.models.RepositoryModel; import com.gitblit.models.TeamModel; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.RequiresAdminRole; @@ -83,14 +81,7 @@ public class EditTeamPage extends RootSubPage { CompoundPropertyModel model = new CompoundPropertyModel(teamModel); - List repos = new ArrayList(); - for (String repo : GitBlit.self().getRepositoryList()) { - RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo); - if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) { - repos.add(repo); - } - } - StringUtils.sortRepositorynames(repos); + List repos = getAccessRestrictedRepositoryList(true); List teamUsers = new ArrayList(teamModel.users); Collections.sort(teamUsers); diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java index 3fc1eab1..a165305d 100644 --- a/src/com/gitblit/wicket/pages/EditUserPage.java +++ b/src/com/gitblit/wicket/pages/EditUserPage.java @@ -34,12 +34,10 @@ import org.apache.wicket.model.Model; import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; -import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.models.RegistrantAccessPermission; -import com.gitblit.models.RepositoryModel; import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; @@ -86,14 +84,8 @@ public class EditUserPage extends RootSubPage { StringUtils.isEmpty(userModel.password) ? "" : userModel.password); CompoundPropertyModel model = new CompoundPropertyModel(userModel); - List repos = new ArrayList(); - for (String repo : GitBlit.self().getRepositoryList()) { - RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo); - if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) { - repos.add(repo); - } - } - StringUtils.sortRepositorynames(repos); + // build list of projects including all repositories wildcards + List repos = getAccessRestrictedRepositoryList(true); List userTeams = new ArrayList(); for (TeamModel team : userModel.teams) { diff --git a/src/com/gitblit/wicket/pages/RootSubPage.java b/src/com/gitblit/wicket/pages/RootSubPage.java index f7572b14..30d296ed 100644 --- a/src/com/gitblit/wicket/pages/RootSubPage.java +++ b/src/com/gitblit/wicket/pages/RootSubPage.java @@ -15,9 +15,15 @@ */ package com.gitblit.wicket.pages; +import java.util.ArrayList; +import java.util.List; + import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; +import com.gitblit.GitBlit; +import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.models.RepositoryModel; import com.gitblit.utils.StringUtils; /** @@ -45,4 +51,32 @@ public abstract class RootSubPage extends RootPage { add(new Label("pageSubName", subName)); super.setupPage("", pageName); } + + protected List getAccessRestrictedRepositoryList(boolean includeWildcards) { + // build list of access-restricted projects + String lastProject = null; + List repos = new ArrayList(); + if (includeWildcards) { + // all repositories + repos.add(".*"); + // all repositories excluding personal repositories + repos.add("[^~].*"); + } + for (String repo : GitBlit.self().getRepositoryList()) { + RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo); + if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) { + if (includeWildcards) { + if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) { + lastProject = repositoryModel.projectPath; + if (!StringUtils.isEmpty(repositoryModel.projectPath)) { + // regex for all repositories within a project + repos.add(repositoryModel.projectPath + "/.*"); + } + } + } + repos.add(repo); + } + } + return repos; + } } -- 2.39.5