]> source.dussan.org Git - gitblit.git/commitdiff
RPC support for hook script selection
authorJames Moger <james.moger@gitblit.com>
Mon, 19 Dec 2011 23:00:29 +0000 (18:00 -0500)
committerJames Moger <james.moger@gitblit.com>
Mon, 19 Dec 2011 23:00:29 +0000 (18:00 -0500)
src/com/gitblit/RpcServlet.java
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/JPalette.java
src/com/gitblit/client/RepositoriesPanel.java
src/com/gitblit/models/ServerSettings.java

index 115d5536bb82ea3826fd736a8ff5d1d96b371666..c33bd8a268796f7e124a9b6aa30efa36e8e8acab 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,10 +294,13 @@ 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
+                               }\r
                                result = managementSettings;\r
                        }\r
                } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
index a70a61789419dfc24a6be0488ba293d503f43dc2..44b6fc6a01129320b751cda62426ffc1152f0509 100644 (file)
@@ -88,7 +88,7 @@ public class EditRepositoryDialog extends JDialog {
        private JCheckBox skipSummaryMetrics;\r
 \r
        private JCheckBox isFrozen;\r
-       \r
+\r
        private JTextField mailRecipientsField;\r
 \r
        private JComboBox accessRestriction;\r
@@ -98,11 +98,15 @@ public class EditRepositoryDialog extends JDialog {
        private JComboBox ownerField;\r
 \r
        private JPalette<String> usersPalette;\r
-       \r
+\r
        private JPalette<String> setsPalette;\r
-       \r
+\r
        private JPalette<String> teamsPalette;\r
 \r
+       private JPalette<String> preReceivePalette;\r
+\r
+       private JPalette<String> postReceivePalette;\r
+\r
        private Set<String> repositoryNames;\r
 \r
        public EditRepositoryDialog(int protocolVersion) {\r
@@ -162,7 +166,7 @@ public class EditRepositoryDialog extends JDialog {
 \r
                mailRecipientsField = new JTextField(anRepository.mailRecipients == null ? ""\r
                                : StringUtils.flattenStrings(anRepository.mailRecipients, " "), 50);\r
-               \r
+\r
                accessRestriction = new JComboBox(AccessRestrictionType.values());\r
                accessRestriction.setRenderer(new AccessRestrictionRenderer());\r
                accessRestriction.setSelectedItem(anRepository.accessRestriction);\r
@@ -216,6 +220,18 @@ public class EditRepositoryDialog extends JDialog {
                federationPanel.add(newFieldPanel(Translation.get("gb.federationSets"), setsPalette),\r
                                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"), fieldsPanel);\r
                panel.addTab(Translation.get("gb.accessRestriction"), accessPanel);\r
@@ -223,6 +239,8 @@ public class EditRepositoryDialog extends JDialog {
                        panel.addTab(Translation.get("gb.teams"), teamsPanel);\r
                }\r
                panel.addTab(Translation.get("gb.federation"), federationPanel);\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
@@ -352,8 +370,9 @@ public class EditRepositoryDialog extends JDialog {
                repository.skipSizeCalculation = skipSizeCalculation.isSelected();\r
                repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();\r
                repository.isFrozen = isFrozen.isSelected();\r
-               \r
-               repository.mailRecipients = StringUtils.getStringsFromValue(mailRecipientsField.getText().trim(), " ");\r
+\r
+               repository.mailRecipients = StringUtils.getStringsFromValue(mailRecipientsField.getText()\r
+                               .trim(), " ");\r
 \r
                repository.accessRestriction = (AccessRestrictionType) accessRestriction.getSelectedItem();\r
                repository.federationStrategy = (FederationStrategy) federationStrategy.getSelectedItem();\r
@@ -361,6 +380,9 @@ public class EditRepositoryDialog extends JDialog {
                if (repository.federationStrategy.exceeds(FederationStrategy.EXCLUDE)) {\r
                        repository.federationSets = setsPalette.getSelections();\r
                }\r
+\r
+               repository.preReceiveScripts = preReceivePalette.getSelections();\r
+               repository.postReceiveScripts = postReceivePalette.getSelections();\r
                return true;\r
        }\r
 \r
@@ -376,7 +398,7 @@ public class EditRepositoryDialog extends JDialog {
                }\r
                usersPalette.setObjects(all, selected);\r
        }\r
-       \r
+\r
        public void setTeams(List<String> all, List<String> selected) {\r
                teamsPalette.setObjects(all, selected);\r
        }\r
@@ -396,6 +418,14 @@ public class EditRepositoryDialog extends JDialog {
                setsPalette.setObjects(all, selected);\r
        }\r
 \r
+       public void setPreReceiveScripts(List<String> all, List<String> selected) {\r
+               preReceivePalette.setObjects(all, selected);\r
+       }\r
+\r
+       public void setPostReceiveScripts(List<String> all, List<String> selected) {\r
+               postReceivePalette.setObjects(all, selected);\r
+       }\r
+\r
        public RepositoryModel getRepository() {\r
                if (canceled) {\r
                        return null;\r
index b9444861db166aef9a8c0b79ab6b7545f1f3a5b2..f9af8dfea13c6e51e6b660c84ab3f46b5bf12aba 100644 (file)
@@ -183,6 +183,13 @@ public class GitblitClient implements Serializable {
                }\r
        }\r
 \r
+       public List<String> getAvailableScripts() {\r
+               if (settings.pushScripts == null) {\r
+                       return new ArrayList<String>();\r
+               }\r
+               return settings.pushScripts;\r
+       }\r
+\r
        public ServerSettings getSettings() {\r
                return settings;\r
        }\r
index eb445b45b58b701eca70bd986a06729662a8b6cb..699b271e758beb37b05cb47e17b01f0d437ef72d 100644 (file)
@@ -40,6 +40,10 @@ public class JPalette<T> extends JPanel {
        private PaletteModel<T> selectedModel;\r
 \r
        public JPalette() {\r
+               this(false);\r
+       }\r
+\r
+       public JPalette(boolean controlOrder) {\r
                super(new BorderLayout(5, 5));\r
 \r
                availableModel = new PaletteModel<T>();\r
@@ -86,9 +90,37 @@ public class JPalette<T> extends JPanel {
                        }\r
                });\r
 \r
+               JButton up = new JButton("\u2191");\r
+               up.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               int row = selected.getSelectedRow();\r
+                               if (row > 0) {\r
+                                       T o = selectedModel.list.remove(row);\r
+                                       selectedModel.list.add(row - 1, o);\r
+                                       selectedModel.fireTableDataChanged();\r
+                               }\r
+                       }\r
+               });\r
+\r
+               JButton down = new JButton("\u2193");\r
+               down.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               int row = selected.getSelectedRow();\r
+                               if (row < selected.getRowCount() - 1) {\r
+                                       T o = selectedModel.list.remove(row);\r
+                                       selectedModel.list.add(row + 1, o);\r
+                                       selectedModel.fireTableDataChanged();\r
+                               }\r
+                       }\r
+               });\r
+\r
                JPanel controls = new JPanel(new GridLayout(0, 1, 0, 5));\r
                controls.add(add);\r
                controls.add(subtract);\r
+               if (controlOrder) {\r
+                       controls.add(up);\r
+                       controls.add(down);\r
+               }\r
 \r
                JPanel center = new JPanel(new GridBagLayout());\r
                center.add(controls);\r
index cd3f46be1825c46a65ec917d533e1eef795420c6..2994b763e18514f7fd9f462579a789d5b421b890 100644 (file)
@@ -277,7 +277,7 @@ public abstract class RepositoriesPanel extends JPanel {
        protected abstract void subscribeFeeds(List<FeedModel> feeds);\r
 \r
        protected abstract void updateUsersTable();\r
-       \r
+\r
        protected abstract void updateTeamsTable();\r
 \r
        protected void disableManagement() {\r
@@ -357,6 +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.setVisible(true);\r
                final RepositoryModel newRepository = dialog.getRepository();\r
                final List<String> permittedUsers = dialog.getPermittedUsers();\r
@@ -369,7 +371,8 @@ public abstract class RepositoriesPanel extends JPanel {
 \r
                        @Override\r
                        protected Boolean doRequest() throws IOException {\r
-                               boolean success = gitblit.createRepository(newRepository, permittedUsers, permittedTeams);\r
+                               boolean success = gitblit.createRepository(newRepository, permittedUsers,\r
+                                               permittedTeams);\r
                                if (success) {\r
                                        gitblit.refreshRepositories();\r
                                        if (permittedUsers.size() > 0) {\r
@@ -405,7 +408,8 @@ public abstract class RepositoriesPanel extends JPanel {
         * @param repository\r
         */\r
        protected void editRepository(final RepositoryModel repository) {\r
-               EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion(), repository);\r
+               EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion(),\r
+                               repository);\r
                dialog.setLocationRelativeTo(RepositoriesPanel.this);\r
                List<String> usernames = gitblit.getUsernames();\r
                List<String> members = gitblit.getPermittedUsernames(repository);\r
@@ -413,6 +417,8 @@ 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.setVisible(true);\r
                final RepositoryModel revisedRepository = dialog.getRepository();\r
                final List<String> permittedUsers = dialog.getPermittedUsers();\r
index 3aae2e3b11bd28bdac488181b4859950c1bc4b3a..72a7f00720664cc0b0cd8db0a08273fbf9e32267 100644 (file)
@@ -35,6 +35,8 @@ public class ServerSettings implements Serializable {
 \r
        private static final long serialVersionUID = 1L;\r
 \r
+       public List<String> pushScripts;\r
+\r
        public ServerSettings() {\r
                settings = new TreeMap<String, SettingModel>();\r
        }\r