]> source.dussan.org Git - gitblit.git/commitdiff
Manager support for hook script inheritance
authorJames Moger <james.moger@gitblit.com>
Thu, 29 Dec 2011 01:09:46 +0000 (20:09 -0500)
committerJames Moger <james.moger@gitblit.com>
Thu, 29 Dec 2011 01:09:46 +0000 (20:09 -0500)
src/com/gitblit/RpcServlet.java
src/com/gitblit/client/EditTeamDialog.java
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/RepositoriesPanel.java
src/com/gitblit/client/TeamsPanel.java

index c33bd8a268796f7e124a9b6aa30efa36e8e8acab..2d51388760f2deaedfd3c8652dd3fb3e36b2f8c1 100644 (file)
@@ -276,7 +276,7 @@ public class RpcServlet extends JsonServlet {
                        }\r
                } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
                        // return the server's settings\r
-                       ServerSettings settings = GitBlit.self().getSettingsModel();                    \r
+                       ServerSettings settings = GitBlit.self().getSettingsModel();\r
                        if (allowAdmin) {\r
                                // return all settings\r
                                result = settings;\r
@@ -294,12 +294,12 @@ public class RpcServlet extends JsonServlet {
                                        keys.add(Keys.federation.sets);\r
                                }\r
                                // build the settings\r
-                               ServerSettings managementSettings = new ServerSettings();                               \r
+                               ServerSettings managementSettings = new ServerSettings();\r
                                for (String key : keys) {\r
                                        managementSettings.add(settings.get(key));\r
                                }\r
                                if (allowManagement) {\r
-                                       settings.pushScripts = settings.pushScripts;\r
+                                       managementSettings.pushScripts = settings.pushScripts;\r
                                }\r
                                result = managementSettings;\r
                        }\r
index a04ed2cfaa7221e2fcf9ab2a99c3d5c112c20484..49669e2ce2dcd4e160c2440c0be6a75b12706bda 100644 (file)
@@ -71,6 +71,10 @@ public class EditTeamDialog extends JDialog {
 \r
        private JPalette<String> userPalette;\r
 \r
+       private JPalette<String> preReceivePalette;\r
+\r
+       private JPalette<String> postReceivePalette;\r
+\r
        private Set<String> teamnames;\r
 \r
        public EditTeamDialog(int protocolVersion, ServerSettings settings) {\r
@@ -141,10 +145,24 @@ public class EditTeamDialog extends JDialog {
                };\r
                usersPanel.add(userPalette, BorderLayout.CENTER);\r
 \r
+               preReceivePalette = new JPalette<String>(true);\r
+               JPanel preReceivePanel = new JPanel(new BorderLayout(5, 5));\r
+               preReceivePanel.add(\r
+                               newFieldPanel(Translation.get("gb.preReceiveScripts"), preReceivePalette),\r
+                               BorderLayout.CENTER);\r
+\r
+               postReceivePalette = new JPalette<String>(true);\r
+               JPanel postReceivePanel = new JPanel(new BorderLayout(5, 5));\r
+               postReceivePanel.add(\r
+                               newFieldPanel(Translation.get("gb.postReceiveScripts"), postReceivePalette),\r
+                               BorderLayout.CENTER);\r
+\r
                JTabbedPane panel = new JTabbedPane(JTabbedPane.TOP);\r
                panel.addTab(Translation.get("gb.general"), fieldsPanelTop);\r
                panel.addTab(Translation.get("gb.teamMembers"), usersPanel);\r
                panel.addTab(Translation.get("gb.restrictedRepositories"), repositoriesPanel);\r
+               panel.addTab(Translation.get("gb.preReceiveScripts"), preReceivePanel);\r
+               panel.addTab(Translation.get("gb.postReceiveScripts"), postReceivePanel);\r
 \r
                JButton createButton = new JButton(Translation.get("gb.save"));\r
                createButton.addActionListener(new ActionListener() {\r
@@ -241,6 +259,13 @@ public class EditTeamDialog extends JDialog {
 \r
                team.users.clear();\r
                team.users.addAll(userPalette.getSelections());\r
+\r
+               team.preReceiveScripts.clear();\r
+               team.preReceiveScripts.addAll(preReceivePalette.getSelections());\r
+\r
+               team.postReceiveScripts.clear();\r
+               team.postReceiveScripts.addAll(postReceivePalette.getSelections());\r
+\r
                return true;\r
        }\r
 \r
@@ -278,6 +303,22 @@ public class EditTeamDialog extends JDialog {
                userPalette.setObjects(users, selected);\r
        }\r
 \r
+       public void setPreReceiveScripts(List<String> unused, List<String> selected) {\r
+               Collections.sort(unused);\r
+               if (selected != null) {\r
+                       Collections.sort(selected);\r
+               }\r
+               preReceivePalette.setObjects(unused, selected);\r
+       }\r
+\r
+       public void setPostReceiveScripts(List<String> unused, List<String> selected) {\r
+               Collections.sort(unused);\r
+               if (selected != null) {\r
+                       Collections.sort(selected);\r
+               }\r
+               postReceivePalette.setObjects(unused, selected);\r
+       }\r
+\r
        public TeamModel getTeam() {\r
                if (canceled) {\r
                        return null;\r
index f9af8dfea13c6e51e6b660c84ab3f46b5bf12aba..d37ee911053c4f4fadf5e717e6b9a8becd7d3baa 100644 (file)
@@ -21,9 +21,11 @@ import java.util.ArrayList;
 import java.util.Collections;\r
 import java.util.Date;\r
 import java.util.HashSet;\r
+import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
+import java.util.TreeSet;\r
 \r
 import com.gitblit.Constants;\r
 import com.gitblit.GitBlitException.ForbiddenException;\r
@@ -183,11 +185,105 @@ public class GitblitClient implements Serializable {
                }\r
        }\r
 \r
-       public List<String> getAvailableScripts() {\r
-               if (settings.pushScripts == null) {\r
-                       return new ArrayList<String>();\r
+       /**\r
+        * Returns the list of pre-receive scripts the repository inherited from the\r
+        * global settings and team affiliations.\r
+        * \r
+        * @param repository\r
+        *            if null only the globally specified scripts are returned\r
+        * @return a list of scripts\r
+        */\r
+       public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) {\r
+               Set<String> scripts = new LinkedHashSet<String>();\r
+               // Globals\r
+               for (String script : settings.get(Keys.groovy.preReceiveScripts).getStrings()) {\r
+                       if (script.endsWith(".groovy")) {\r
+                               scripts.add(script.substring(0, script.lastIndexOf('.')));\r
+                       } else {\r
+                               scripts.add(script);\r
+                       }\r
+               }\r
+\r
+               // Team Scripts\r
+               if (repository != null) {\r
+                       for (String teamname : getPermittedTeamnames(repository)) {\r
+                               TeamModel team = getTeamModel(teamname);\r
+                               scripts.addAll(team.preReceiveScripts);\r
+                       }\r
+               }\r
+               return new ArrayList<String>(scripts);\r
+       }\r
+\r
+       /**\r
+        * Returns the list of all available Groovy pre-receive push hook scripts\r
+        * that are not already inherited by the repository. Script files must have\r
+        * .groovy extension\r
+        * \r
+        * @param repository\r
+        *            optional parameter\r
+        * @return list of available hook scripts\r
+        */\r
+       public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) {\r
+               Set<String> inherited = new TreeSet<String>(getPreReceiveScriptsInherited(repository));\r
+\r
+               // create list of available scripts by excluding inherited scripts\r
+               List<String> scripts = new ArrayList<String>();\r
+               for (String script : settings.pushScripts) {\r
+                       if (!inherited.contains(script)) {\r
+                               scripts.add(script);\r
+                       }\r
+               }\r
+               return scripts;\r
+       }\r
+\r
+       /**\r
+        * Returns the list of post-receive scripts the repository inherited from\r
+        * the global settings and team affiliations.\r
+        * \r
+        * @param repository\r
+        *            if null only the globally specified scripts are returned\r
+        * @return a list of scripts\r
+        */\r
+       public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {\r
+               Set<String> scripts = new LinkedHashSet<String>();\r
+               // Global Scripts\r
+               for (String script : settings.get(Keys.groovy.postReceiveScripts).getStrings()) {\r
+                       if (script.endsWith(".groovy")) {\r
+                               scripts.add(script.substring(0, script.lastIndexOf('.')));\r
+                       } else {\r
+                               scripts.add(script);\r
+                       }\r
                }\r
-               return settings.pushScripts;\r
+               // Team Scripts\r
+               if (repository != null) {\r
+                       for (String teamname : getPermittedTeamnames(repository)) {\r
+                               TeamModel team = getTeamModel(teamname);\r
+                               scripts.addAll(team.postReceiveScripts);\r
+                       }\r
+               }\r
+               return new ArrayList<String>(scripts);\r
+       }\r
+\r
+       /**\r
+        * Returns the list of unused Groovy post-receive push hook scripts that are\r
+        * not already inherited by the repository. Script files must have .groovy\r
+        * extension\r
+        * \r
+        * @param repository\r
+        *            optional parameter\r
+        * @return list of available hook scripts\r
+        */\r
+       public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {\r
+               Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));\r
+\r
+               // create list of available scripts by excluding inherited scripts\r
+               List<String> scripts = new ArrayList<String>();\r
+               for (String script : settings.pushScripts) {\r
+                       if (!inherited.contains(script)) {\r
+                               scripts.add(script);\r
+                       }\r
+               }\r
+               return scripts;\r
        }\r
 \r
        public ServerSettings getSettings() {\r
@@ -393,6 +489,15 @@ public class GitblitClient implements Serializable {
                }\r
                return teamnames;\r
        }\r
+       \r
+       public TeamModel getTeamModel(String name) {\r
+               for (TeamModel team : allTeams) {\r
+                       if (team.name.equalsIgnoreCase(name)) {\r
+                               return team;\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
 \r
        public List<String> getFederationSets() {\r
                return settings.get(Keys.federation.sets).getStrings();\r
index 2994b763e18514f7fd9f462579a789d5b421b890..50284be1fa9730e1ba4c9aef8471a306ec7d29e3 100644 (file)
@@ -357,8 +357,8 @@ public abstract class RepositoriesPanel extends JPanel {
                dialog.setTeams(gitblit.getTeamnames(), null);\r
                dialog.setRepositories(gitblit.getRepositories());\r
                dialog.setFederationSets(gitblit.getFederationSets(), null);\r
-               dialog.setPreReceiveScripts(gitblit.getAvailableScripts(), null);\r
-               dialog.setPostReceiveScripts(gitblit.getAvailableScripts(), null);\r
+               dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null), null);\r
+               dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null), null);\r
                dialog.setVisible(true);\r
                final RepositoryModel newRepository = dialog.getRepository();\r
                final List<String> permittedUsers = dialog.getPermittedUsers();\r
@@ -417,8 +417,10 @@ public abstract class RepositoriesPanel extends JPanel {
                dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository));\r
                dialog.setRepositories(gitblit.getRepositories());\r
                dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);\r
-               dialog.setPreReceiveScripts(gitblit.getAvailableScripts(), repository.preReceiveScripts);\r
-               dialog.setPostReceiveScripts(gitblit.getAvailableScripts(), repository.postReceiveScripts);\r
+               dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(repository),\r
+                               repository.preReceiveScripts);\r
+               dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(repository),\r
+                               repository.postReceiveScripts);\r
                dialog.setVisible(true);\r
                final RepositoryModel revisedRepository = dialog.getRepository();\r
                final List<String> permittedUsers = dialog.getPermittedUsers();\r
index 2d1d914ab75f69737ee69578ff1806e3c29f5b7d..b2a18731c9577cd77d50bebf37977f686b2dd76f 100644 (file)
@@ -257,6 +257,8 @@ public abstract class TeamsPanel extends JPanel {
                dialog.setTeams(gitblit.getTeams());\r
                dialog.setRepositories(gitblit.getRepositories(), null);\r
                dialog.setUsers(gitblit.getUsernames(), null);\r
+               dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null), null);\r
+               dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null), null);\r
                dialog.setVisible(true);\r
                final TeamModel newTeam = dialog.getTeam();\r
                if (newTeam == null) {\r
@@ -304,6 +306,10 @@ public abstract class TeamsPanel extends JPanel {
                dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(team.repositories));\r
                dialog.setUsers(gitblit.getUsernames(), team.users == null ? null : new ArrayList<String>(\r
                                team.users));\r
+               dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null),\r
+                               team.preReceiveScripts);\r
+               dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null),\r
+                               team.postReceiveScripts);\r
                dialog.setVisible(true);\r
                final TeamModel revisedTeam = dialog.getTeam();\r
                if (revisedTeam == null) {\r