]> source.dussan.org Git - gitblit.git/commitdiff
Add some common regex filters to the repository lists
authorJames Moger <james.moger@gitblit.com>
Tue, 23 Oct 2012 21:17:14 +0000 (17:17 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 23 Oct 2012 21:17:14 +0000 (17:17 -0400)
src/com/gitblit/client/EditTeamDialog.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/wicket/pages/EditTeamPage.java
src/com/gitblit/wicket/pages/EditUserPage.java
src/com/gitblit/wicket/pages/RootSubPage.java

index 81146fc6b231aa10dbd0622caee4b8a66b30100c..4350310e5e0d42e968637dcc2e086bc036541fb5 100644 (file)
@@ -315,18 +315,35 @@ public class EditTeamDialog extends JDialog {
                                restricted.add(repo.name);\r
                        }\r
                }\r
+               StringUtils.sortRepositorynames(restricted);\r
                \r
-               // remove repositories for which team already has a permission\r
+               List<String> list = new ArrayList<String>();\r
+               // repositories\r
+               list.add(".*");\r
+               // all repositories excluding personal repositories\r
+               list.add("[^~].*");\r
+               String lastProject = null;\r
+               for (String repo : restricted) {\r
+                       String projectPath = StringUtils.getFirstPathElement(repo);\r
+                       if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) {\r
+                               lastProject = projectPath;\r
+                               if (!StringUtils.isEmpty(projectPath)) {\r
+                                       // regex for all repositories within a project\r
+                                       list.add(projectPath + "/.*");\r
+                               }\r
+                               list.add(repo);\r
+                       }\r
+               }\r
+\r
+               // remove repositories for which user already has a permission\r
                if (permissions == null) {\r
                        permissions = new ArrayList<RegistrantAccessPermission>();\r
                } else {\r
                        for (RegistrantAccessPermission rp : permissions) {\r
-                               restricted.remove(rp.registrant);\r
+                               list.remove(rp.registrant);\r
                        }\r
                }\r
-\r
-               StringUtils.sortRepositorynames(restricted);\r
-               repositoryPalette.setObjects(restricted, permissions);\r
+               repositoryPalette.setObjects(list, permissions);\r
        }\r
 \r
        public void setUsers(List<String> users, List<String> selected) {\r
index da75867fb328a227e41e3440b701abdd085267e9..e096693391349b1423095599e7de6aa2b615a4ad 100644 (file)
@@ -347,18 +347,35 @@ public class EditUserDialog extends JDialog {
                                restricted.add(repo.name);\r
                        }\r
                }\r
+               StringUtils.sortRepositorynames(restricted);\r
+               \r
+               List<String> list = new ArrayList<String>();\r
+               // repositories\r
+               list.add(".*");\r
+               // all repositories excluding personal repositories\r
+               list.add("[^~].*");\r
+               String lastProject = null;\r
+               for (String repo : restricted) {\r
+                       String projectPath = StringUtils.getFirstPathElement(repo);\r
+                       if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) {\r
+                               lastProject = projectPath;\r
+                               if (!StringUtils.isEmpty(projectPath)) {\r
+                                       // regex for all repositories within a project\r
+                                       list.add(projectPath + "/.*");\r
+                               }\r
+                               list.add(repo);\r
+                       }\r
+               }\r
 \r
                // remove repositories for which user already has a permission\r
                if (permissions == null) {\r
                        permissions = new ArrayList<RegistrantAccessPermission>();\r
                } else {\r
                        for (RegistrantAccessPermission rp : permissions) {\r
-                               restricted.remove(rp.registrant);\r
+                               list.remove(rp.registrant);\r
                        }\r
                }\r
-               \r
-               StringUtils.sortRepositorynames(restricted);\r
-               repositoryPalette.setObjects(restricted, permissions);\r
+               repositoryPalette.setObjects(list, permissions);\r
        }\r
 \r
        public void setTeams(List<TeamModel> teams, List<TeamModel> selected) {\r
index a4e2c5e21bee37a79e6978e41a821d4d1c2b180e..8908676e8639bad6a52bc3f1075e607ab50c8962 100644 (file)
@@ -36,11 +36,9 @@ import org.apache.wicket.model.Model;
 import org.apache.wicket.model.util.CollectionModel;\r
 import org.apache.wicket.model.util.ListModel;\r
 \r
-import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
-import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.RequiresAdminRole;\r
@@ -83,14 +81,7 @@ public class EditTeamPage extends RootSubPage {
 \r
                CompoundPropertyModel<TeamModel> model = new CompoundPropertyModel<TeamModel>(teamModel);\r
 \r
-               List<String> repos = new ArrayList<String>();\r
-               for (String repo : GitBlit.self().getRepositoryList()) {\r
-                       RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo);\r
-                       if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
-                               repos.add(repo);\r
-                       }\r
-               }\r
-               StringUtils.sortRepositorynames(repos);\r
+               List<String> repos = getAccessRestrictedRepositoryList(true);\r
 \r
                List<String> teamUsers = new ArrayList<String>(teamModel.users);\r
                Collections.sort(teamUsers);\r
index 3fc1eab15d7a1e167b50acd5a67fae67ef45b941..a165305d91710f7d0aeb8b124183f6dab809672c 100644 (file)
@@ -34,12 +34,10 @@ import org.apache.wicket.model.Model;
 import org.apache.wicket.model.util.CollectionModel;\r
 import org.apache.wicket.model.util.ListModel;\r
 \r
-import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
-import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -86,14 +84,8 @@ public class EditUserPage extends RootSubPage {
                                StringUtils.isEmpty(userModel.password) ? "" : userModel.password);\r
                CompoundPropertyModel<UserModel> model = new CompoundPropertyModel<UserModel>(userModel);\r
 \r
-               List<String> repos = new ArrayList<String>();\r
-               for (String repo : GitBlit.self().getRepositoryList()) {\r
-                       RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo);\r
-                       if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
-                               repos.add(repo);\r
-                       }\r
-               }\r
-               StringUtils.sortRepositorynames(repos);\r
+               // build list of projects including all repositories wildcards\r
+               List<String> repos = getAccessRestrictedRepositoryList(true);\r
                \r
                List<String> userTeams = new ArrayList<String>();\r
                for (TeamModel team : userModel.teams) {\r
index f7572b141aa688915b13a44cd5a2e46feb2c1206..30d296edd1e93f463dacda893c64fda9717bff9f 100644 (file)
  */\r
 package com.gitblit.wicket.pages;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 \r
+import com.gitblit.GitBlit;\r
+import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
@@ -45,4 +51,32 @@ public abstract class RootSubPage extends RootPage {
                add(new Label("pageSubName", subName));\r
                super.setupPage("", pageName);\r
        }\r
+       \r
+       protected List<String> getAccessRestrictedRepositoryList(boolean includeWildcards) {\r
+               // build list of access-restricted projects\r
+               String lastProject = null;\r
+               List<String> repos = new ArrayList<String>();\r
+               if (includeWildcards) {\r
+                       // all repositories\r
+                       repos.add(".*");\r
+                       // all repositories excluding personal repositories\r
+                       repos.add("[^~].*");\r
+               }\r
+               for (String repo : GitBlit.self().getRepositoryList()) {\r
+                       RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo);\r
+                       if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
+                               if (includeWildcards) {\r
+                                       if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) {\r
+                                               lastProject = repositoryModel.projectPath;\r
+                                               if (!StringUtils.isEmpty(repositoryModel.projectPath)) {\r
+                                                       // regex for all repositories within a project\r
+                                                       repos.add(repositoryModel.projectPath + "/.*");\r
+                                               }\r
+                                       }\r
+                               }\r
+                               repos.add(repo);\r
+                       }\r
+               }\r
+               return repos;\r
+       }\r
 }\r