]> source.dussan.org Git - gitblit.git/commitdiff
Implemented Team hook scripts
authorJames Moger <james.moger@gitblit.com>
Tue, 27 Dec 2011 22:50:39 +0000 (17:50 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 27 Dec 2011 22:50:39 +0000 (17:50 -0500)
docs/01_setup.mkd
docs/04_releases.mkd
src/com/gitblit/ConfigUserService.java
src/com/gitblit/FileUserService.java
src/com/gitblit/GitBlit.java
src/com/gitblit/GitServlet.java
src/com/gitblit/models/TeamModel.java
src/com/gitblit/wicket/pages/EditRepositoryPage.java
src/com/gitblit/wicket/pages/EditTeamPage.html
src/com/gitblit/wicket/pages/EditTeamPage.java

index e400a0b19f10f6258073cc57831d64cb3ed105f9..5a3336b2f6a21d26065295e3cf0c19798518ecae 100644 (file)
@@ -196,6 +196,7 @@ The `users.conf` file uses a Git-style configuration format:
                user = babaracus\r
                repository = topsecret.git\r
                mailingList = list@ateam.org\r
+               postReceiveScript = sendmail\r
 \r
 The `users.conf` file allows flexibility for adding new fields to a UserModel object that the original `users.properties` file does not afford without imposing the complexity of relying on an embedded SQL database. \r
 \r
@@ -251,13 +252,14 @@ The Groovy hook mechanism allows for dynamic extension of Gitblit to execute cus
 3. Script filenames must not have spaces!\r
 4. Scripts must be explicitly specified to be executed, no scripts are *automatically* executed by name or extension.\r
 5. A script can be specified to run on *all repositories* by adding the script file name to *groovy.preReceiveScripts* or *groovy.postReceiveScripts* in `gitblit.properties` or `web.xml`.\r
-6. Scripts may also be specified per-repository in the repository's settings.\r
-7. Globally specified scripts are excluded from the list of available scripts in a repository's settings \r
-8. Globally specified scripts are executed first, in their listed order, followed by per-repository scripts, in their listed order.\r
-9. A script may only be defined once in a pre-receive chain and once in a post-receive chain.  \r
+6. Scripts can be specified for a team.\r
+7. Scripts may also be specified per-repository in the repository's settings.\r
+8. Globally-specified scripts and team-specified scripts are excluded from the list of available scripts in a repository's settings \r
+9. Globally-specified scripts are executed first, in their listed order; followed by team-specified scripts in their listed order by alphabetical team order; followed by per-repository scripts, in their listed order.\r
+10. A script may only be defined once in a pre-receive chain and once in a post-receive chain.  \r
 You may execute the same script on pre-receive and post-receive, just not multiple times within a pre-receive or post-receive event.\r
-10. Gitblit does not differentiate between what can be a pre-receive script and what can be a post-receive script.\r
-11. If a script *returns false* then the hook chain is aborted and none of the subsequent scripts will execute.\r
+11. Gitblit does not differentiate between what can be a pre-receive script and what can be a post-receive script.\r
+12. If a script *returns false* then the hook chain is aborted and none of the subsequent scripts will execute.\r
 \r
 Some sample scripts are included in the GO and WAR distributions to show you how you can tap into Gitblit with the provided bound variables.  Additional implementation details may be specified in the header comment of these examples.\r
 \r
index e03089f495baa3d0c20c196dae658da328201d55..db47d4164d181debd21e593c876f405309321902 100644 (file)
@@ -5,7 +5,7 @@
 \r
 - updated: Gitblit GO is now monolithic like the WAR build. (issue 30)  \r
 This change helps adoption of GO in environments without an internet connection or with a restricted connection.\r
-- added: Groovy 1.8.4 and a push hook script mechanism.  Hook scripts can be set per-repository or globally for all repositories.  \r
+- added: Groovy 1.8.4 and a push hook script mechanism.  Hook scripts can be set per-repository, pre-team, or globally for all repositories.  \r
 Unfortunately this adds another 6 MB to the 8MB Gitblit package, but it allows for a *very* powerful, flexible, platform-independent hook script mechanism.  \r
     **New:** *groovy.scriptsFolder = groovy*  \r
     **New:** *groovy.preReceiveScripts =*  \r
index b899d9241d9d1cfeb7d9b74073e65593d5435f59..7e4600cf0de0efc5d0c3e1216f159f9209c54546 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
+import java.util.Collections;\r
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -62,9 +63,13 @@ public class ConfigUserService implements IUserService {
        private static final String REPOSITORY = "repository";\r
 \r
        private static final String ROLE = "role";\r
-       \r
+\r
        private static final String MAILINGLIST = "mailingList";\r
 \r
+       private static final String PRERECEIVE = "preReceiveScript";\r
+\r
+       private static final String POSTRECEIVE = "postReceiveScript";\r
+\r
        private final File realmFile;\r
 \r
        private final Logger logger = LoggerFactory.getLogger(ConfigUserService.class);\r
@@ -303,6 +308,7 @@ public class ConfigUserService implements IUserService {
        public List<String> getAllTeamNames() {\r
                read();\r
                List<String> list = new ArrayList<String>(teams.keySet());\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -328,6 +334,7 @@ public class ConfigUserService implements IUserService {
                } catch (Throwable t) {\r
                        logger.error(MessageFormat.format("Failed to get teamnames for role {0}!", role), t);\r
                }\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -468,6 +475,7 @@ public class ConfigUserService implements IUserService {
        public List<String> getAllUsernames() {\r
                read();\r
                List<String> list = new ArrayList<String>(users.keySet());\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -493,6 +501,7 @@ public class ConfigUserService implements IUserService {
                } catch (Throwable t) {\r
                        logger.error(MessageFormat.format("Failed to get usernames for role {0}!", role), t);\r
                }\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -652,12 +661,23 @@ public class ConfigUserService implements IUserService {
                        }\r
 \r
                        // null check on "final" mailing lists because JSON-sourced\r
-                       // TeamModel\r
-                       // can have a null users object\r
+                       // TeamModel can have a null users object\r
                        if (model.mailingLists != null) {\r
                                config.setStringList(TEAM, model.name, MAILINGLIST, new ArrayList<String>(\r
                                                model.mailingLists));\r
                        }\r
+\r
+                       // null check on "final" preReceiveScripts because JSON-sourced\r
+                       // TeamModel can have a null preReceiveScripts object\r
+                       if (model.preReceiveScripts != null) {\r
+                               config.setStringList(TEAM, model.name, PRERECEIVE, model.preReceiveScripts);\r
+                       }\r
+\r
+                       // null check on "final" postReceiveScripts because JSON-sourced\r
+                       // TeamModel can have a null postReceiveScripts object\r
+                       if (model.postReceiveScripts != null) {\r
+                               config.setStringList(TEAM, model.name, POSTRECEIVE, model.postReceiveScripts);\r
+                       }\r
                }\r
 \r
                config.save();\r
@@ -724,7 +744,12 @@ public class ConfigUserService implements IUserService {
                                        team.addRepositories(Arrays.asList(config.getStringList(TEAM, teamname,\r
                                                        REPOSITORY)));\r
                                        team.addUsers(Arrays.asList(config.getStringList(TEAM, teamname, USER)));\r
-                                       team.addMailingLists(Arrays.asList(config.getStringList(TEAM, teamname, MAILINGLIST)));\r
+                                       team.addMailingLists(Arrays.asList(config.getStringList(TEAM, teamname,\r
+                                                       MAILINGLIST)));\r
+                                       team.preReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM,\r
+                                                       teamname, PRERECEIVE)));\r
+                                       team.postReceiveScripts.addAll(Arrays.asList(config.getStringList(TEAM,\r
+                                                       teamname, POSTRECEIVE)));\r
 \r
                                        teams.put(team.name.toLowerCase(), team);\r
 \r
index 27892f71c099d4aa0c02a1ca56ad920a4363fe96..88c7d79000882e60d0b0a855de26a69fec21882f 100644 (file)
@@ -20,6 +20,7 @@ import java.io.FileWriter;
 import java.io.IOException;\r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -334,6 +335,7 @@ public class FileUserService extends FileSettings implements IUserService {
                        }\r
                        list.add(user);\r
                }\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -368,6 +370,7 @@ public class FileUserService extends FileSettings implements IUserService {
                } catch (Throwable t) {\r
                        logger.error(MessageFormat.format("Failed to get usernames for role {0}!", role), t);\r
                }\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -619,11 +622,17 @@ public class FileUserService extends FileSettings implements IUserService {
                                        List<String> repositories = new ArrayList<String>();\r
                                        List<String> users = new ArrayList<String>();\r
                                        List<String> mailingLists = new ArrayList<String>();\r
+                                       List<String> preReceive = new ArrayList<String>();\r
+                                       List<String> postReceive = new ArrayList<String>();\r
                                        for (String role : roles) {\r
                                                if (role.charAt(0) == '!') {\r
                                                        users.add(role.substring(1));\r
                                                } else if (role.charAt(0) == '&') {\r
-                                                               mailingLists.add(role.substring(1));\r
+                                                       mailingLists.add(role.substring(1));\r
+                                               } else if (role.charAt(0) == '^') {\r
+                                                       preReceive.add(role.substring(1));\r
+                                               } else if (role.charAt(0) == '%') {\r
+                                                       postReceive.add(role.substring(1));\r
                                                } else {\r
                                                        repositories.add(role);\r
                                                }\r
@@ -656,6 +665,7 @@ public class FileUserService extends FileSettings implements IUserService {
        @Override\r
        public List<String> getAllTeamNames() {\r
                List<String> list = new ArrayList<String>(teams.keySet());\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -691,6 +701,7 @@ public class FileUserService extends FileSettings implements IUserService {
                } catch (Throwable t) {\r
                        logger.error(MessageFormat.format("Failed to get teamnames for role {0}!", role), t);\r
                }\r
+               Collections.sort(list);\r
                return list;\r
        }\r
 \r
@@ -841,6 +852,16 @@ public class FileUserService extends FileSettings implements IUserService {
                        sb.append(address);\r
                        sb.append(',');\r
                }\r
+               for (String script : model.preReceiveScripts) {\r
+                       sb.append('^');\r
+                       sb.append(script);\r
+                       sb.append(',');\r
+               }\r
+               for (String script : model.postReceiveScripts) {\r
+                       sb.append('%');\r
+                       sb.append(script);\r
+                       sb.append(',');\r
+               }\r
                // trim trailing comma\r
                sb.setLength(sb.length() - 1);\r
                allUsers.remove("@" + teamname);\r
index a46806063dd7f873d1a82d3e9f72fe0cc2758ba4..d82e3c2f37dd07a427688a4b190b53b78a8f9ecc 100644 (file)
@@ -28,11 +28,12 @@ import java.util.Arrays;
 import java.util.Collection;\r
 import java.util.Collections;\r
 import java.util.HashMap;\r
-import java.util.HashSet;\r
+import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Map.Entry;\r
 import java.util.Set;\r
+import java.util.TreeSet;\r
 import java.util.concurrent.ConcurrentHashMap;\r
 import java.util.concurrent.Executors;\r
 import java.util.concurrent.ScheduledExecutorService;\r
@@ -1444,13 +1445,12 @@ public class GitBlit implements ServletContextListener {
        }\r
 \r
        /**\r
-        * Returns the list of all available Groovy push hook scripts that are not\r
-        * already specified globally for all repositories. Script files must have\r
+        * Returns the list of all Groovy push hook scripts. Script files must have\r
         * .groovy extension\r
         * \r
         * @return list of available hook scripts\r
         */\r
-       public List<String> getAvailableScripts() {\r
+       public List<String> getAllScripts() {\r
                File groovyFolder = getGroovyScriptsFolder();\r
                File[] files = groovyFolder.listFiles(new FileFilter() {\r
                        @Override\r
@@ -1458,55 +1458,115 @@ public class GitBlit implements ServletContextListener {
                                return pathname.isFile() && pathname.getName().endsWith(".groovy");\r
                        }\r
                });\r
-\r
-               Set<String> globals = new HashSet<String>();\r
-               String[] keys = { Keys.groovy.preReceiveScripts, Keys.groovy.postReceiveScripts };\r
-               for (String key : keys) {\r
-                       for (String script : getStrings(key)) {\r
-                               if (script.endsWith(".groovy")) {\r
-                                       globals.add(script.substring(0, script.lastIndexOf('.')));\r
-                               } else {\r
-                                       globals.add(script);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               // create list of available scripts by excluding scripts that are\r
-               // globally specified\r
                List<String> scripts = new ArrayList<String>();\r
                if (files != null) {\r
                        for (File file : files) {\r
                                String script = file.getName().substring(0, file.getName().lastIndexOf('.'));\r
-                               if (!globals.contains(script)) {\r
-                                       scripts.add(script);\r
-                               }\r
+                               scripts.add(script);\r
                        }\r
                }\r
                return scripts;\r
        }\r
-       \r
-       public List<String> getInheritedPreReceiveScripts(RepositoryModel repository) {\r
-               Set<String> globals = new HashSet<String>();\r
+\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 : getStrings(Keys.groovy.preReceiveScripts)) {\r
                        if (script.endsWith(".groovy")) {\r
-                               globals.add(script.substring(0, script.lastIndexOf('.')));\r
+                               scripts.add(script.substring(0, script.lastIndexOf('.')));\r
                        } else {\r
-                               globals.add(script);\r
+                               scripts.add(script);\r
+                       }\r
+               }\r
+\r
+               // Team Scripts\r
+               if (repository != null) {\r
+                       for (String teamname : userService.getTeamnamesForRepositoryRole(repository.name)) {\r
+                               TeamModel team = userService.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 : getAllScripts()) {\r
+                       if (!inherited.contains(script)) {\r
+                               scripts.add(script);\r
                        }\r
                }\r
-               return new ArrayList<String>(globals);\r
+               return scripts;\r
        }\r
-       \r
-       public List<String> getInheritedPostReceiveScripts(RepositoryModel repository) {\r
-               Set<String> globals = new HashSet<String>();\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 : getStrings(Keys.groovy.postReceiveScripts)) {\r
                        if (script.endsWith(".groovy")) {\r
-                               globals.add(script.substring(0, script.lastIndexOf('.')));\r
+                               scripts.add(script.substring(0, script.lastIndexOf('.')));\r
                        } else {\r
-                               globals.add(script);\r
+                               scripts.add(script);\r
+                       }\r
+               }\r
+               // Team Scripts\r
+               if (repository != null) {\r
+                       for (String teamname : userService.getTeamnamesForRepositoryRole(repository.name)) {\r
+                               TeamModel team = userService.getTeamModel(teamname);\r
+                               scripts.addAll(team.postReceiveScripts);\r
                        }\r
                }\r
-               return new ArrayList<String>(globals);\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 : getAllScripts()) {\r
+                       if (!inherited.contains(script)) {\r
+                               scripts.add(script);\r
+                       }\r
+               }\r
+               return scripts;\r
        }\r
 \r
        /**\r
@@ -1572,7 +1632,7 @@ public class GitBlit implements ServletContextListener {
                                setting.currentValue = settings.getString(key, "");\r
                        }\r
                }\r
-               settingsModel.pushScripts = getAvailableScripts();\r
+               settingsModel.pushScripts = getAllScripts();\r
                return settingsModel;\r
        }\r
 \r
index 36e1c3ed5e52838a645c9801bbae58d50639d6bf..967efac60da55e5b8c2f0083e645018991b4e468 100644 (file)
@@ -99,9 +99,9 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
        }\r
 \r
        /**\r
-        * Transitional wrapper class to configure the JGit 1.2 GitFilter.\r
-        * This GitServlet will probably be replaced by a GitFilter so that Gitblit\r
-        * can serve Git repositories on the root URL and not a /git sub-url.\r
+        * Transitional wrapper class to configure the JGit 1.2 GitFilter. This\r
+        * GitServlet will probably be replaced by a GitFilter so that Gitblit can\r
+        * serve Git repositories on the root URL and not a /git sub-url.\r
         * \r
         * @author James Moger\r
         * \r
@@ -160,9 +160,9 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                 */\r
                @Override\r
                public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {\r
-                       Set<String> scripts = new LinkedHashSet<String>();\r
-                       scripts.addAll(GitBlit.getStrings(Keys.groovy.preReceiveScripts));\r
                        RepositoryModel repository = getRepositoryModel(rp);\r
+                       Set<String> scripts = new LinkedHashSet<String>();\r
+                       scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));\r
                        scripts.addAll(repository.preReceiveScripts);\r
                        UserModel user = getUserModel(rp);\r
                        runGroovy(repository, user, commands, scripts);\r
@@ -188,9 +188,9 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                                logger.info("skipping post-receive hooks, no refs created, updated, or removed");\r
                                return;\r
                        }\r
-                       Set<String> scripts = new LinkedHashSet<String>();\r
-                       scripts.addAll(GitBlit.getStrings(Keys.groovy.postReceiveScripts));\r
                        RepositoryModel repository = getRepositoryModel(rp);\r
+                       Set<String> scripts = new LinkedHashSet<String>();\r
+                       scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));\r
                        scripts.addAll(repository.postReceiveScripts);\r
                        UserModel user = getUserModel(rp);\r
                        runGroovy(repository, user, commands, scripts);\r
index 3258ef6c0bfb2fbd0c9366ef8e0f2a4e417ff0a6..3d176e59e6001d2cd0f719093d41a9e5b7e4bc0c 100644 (file)
@@ -16,6 +16,7 @@
 package com.gitblit.models;\r
 \r
 import java.io.Serializable;\r
+import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.HashSet;\r
 import java.util.List;\r
@@ -37,6 +38,8 @@ public class TeamModel implements Serializable, Comparable<TeamModel> {
        public final Set<String> users = new HashSet<String>();\r
        public final Set<String> repositories = new HashSet<String>();\r
        public final Set<String> mailingLists = new HashSet<String>();\r
+       public final List<String> preReceiveScripts = new ArrayList<String>();\r
+       public final List<String> postReceiveScripts = new ArrayList<String>();\r
 \r
        public TeamModel(String name) {\r
                this.name = name;\r
index 69d21191d3dd4abc190970a7ea212d84bd47a570..0f3a0bbe41acbe8541e055f62d3c34dbed165c40 100644 (file)
@@ -121,8 +121,8 @@ public class EditRepositoryPage extends RootSubPage {
                }\r
                final Palette<String> preReceivePalette = new Palette<String>("preReceiveScripts",\r
                                new ListModel<String>(preReceiveScripts), new CollectionModel<String>(GitBlit\r
-                                               .self().getAvailableScripts()), new ChoiceRenderer<String>("", ""), 12,\r
-                               true);\r
+                                               .self().getPreReceiveScriptsUnused(repositoryModel)),\r
+                               new ChoiceRenderer<String>("", ""), 12, true);\r
 \r
                // post-receive palette\r
                if (repositoryModel.postReceiveScripts != null) {\r
@@ -130,8 +130,8 @@ public class EditRepositoryPage extends RootSubPage {
                }\r
                final Palette<String> postReceivePalette = new Palette<String>("postReceiveScripts",\r
                                new ListModel<String>(postReceiveScripts), new CollectionModel<String>(GitBlit\r
-                                               .self().getAvailableScripts()), new ChoiceRenderer<String>("", ""), 12,\r
-                               true);\r
+                                               .self().getPostReceiveScriptsUnused(repositoryModel)),\r
+                               new ChoiceRenderer<String>("", ""), 12, true);\r
 \r
                CompoundPropertyModel<RepositoryModel> model = new CompoundPropertyModel<RepositoryModel>(\r
                                repositoryModel);\r
@@ -293,9 +293,11 @@ public class EditRepositoryPage extends RootSubPage {
                form.add(teamsPalette);\r
                form.add(federationSetsPalette);\r
                form.add(preReceivePalette);\r
-               form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self().getInheritedPreReceiveScripts(repositoryModel)));\r
+               form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self()\r
+                               .getPreReceiveScriptsInherited(repositoryModel)));\r
                form.add(postReceivePalette);\r
-               form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self().getInheritedPostReceiveScripts(repositoryModel)));\r
+               form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self()\r
+                               .getPostReceiveScriptsInherited(repositoryModel)));\r
 \r
                form.add(new Button("save"));\r
                Button cancel = new Button("cancel") {\r
index 36dd26a785eba166039000be728177cc0c68387b..b680bc975508e9c50dbe982025df48e28cdcc6eb 100644 (file)
@@ -17,6 +17,9 @@
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.teamMembers"></wicket:message></th><td style="padding:2px;"><span wicket:id="users"></span></td></tr>\r
                                <tr><td colspan="2"><hr></hr></td></tr>\r
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.restrictedRepositories"></wicket:message></th><td style="padding:2px;"><span wicket:id="repositories"></span></td></tr>\r
+                               <tr><td colspan="2"><h3><wicket:message key="gb.hookScripts"></wicket:message> &nbsp;<small><wicket:message key="gb.hookScriptsDescription"></wicket:message></small></h3></td></tr>    \r
+                               <tr><th style="vertical-align: top;"><wicket:message key="gb.preReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPreReceive"></span></th><td style="padding:2px;"><span wicket:id="preReceiveScripts"></span></td></tr>\r
+                               <tr><th style="vertical-align: top;"><wicket:message key="gb.postReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPostReceive"></span></th><td style="padding:2px;"><span wicket:id="postReceiveScripts"></span></td></tr>\r
                                <tr><td colspan='2'><div class="actions"><input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="3" /> &nbsp; <input class="btn primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="4" /></div></td></tr>\r
                        </tbody>\r
                </table>\r
index c5c240fd845d8732d0af6f9a37036cb5beb4aab8..8a0540f1385338f3fd6bba6a5e46011997a78789 100644 (file)
@@ -43,6 +43,7 @@ import com.gitblit.models.TeamModel;
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.RequiresAdminRole;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.panels.BulletListPanel;\r
 \r
 @RequiresAdminRole\r
 public class EditTeamPage extends RootSubPage {\r
@@ -73,7 +74,7 @@ public class EditTeamPage extends RootSubPage {
                } else {\r
                        super.setupPage(getString("gb.edit"), teamModel.name);\r
                }\r
-               \r
+\r
                CompoundPropertyModel<TeamModel> model = new CompoundPropertyModel<TeamModel>(teamModel);\r
 \r
                List<String> repos = new ArrayList<String>();\r
@@ -84,17 +85,42 @@ public class EditTeamPage extends RootSubPage {
                        }\r
                }\r
                StringUtils.sortRepositorynames(repos);\r
-               \r
+\r
                List<String> teamUsers = new ArrayList<String>(teamModel.users);\r
                Collections.sort(teamUsers);\r
-               \r
+               List<String> preReceiveScripts = new ArrayList<String>();\r
+               List<String> postReceiveScripts = new ArrayList<String>();\r
+\r
                final String oldName = teamModel.name;\r
+\r
+               // repositories palette\r
                final Palette<String> repositories = new Palette<String>("repositories",\r
                                new ListModel<String>(new ArrayList<String>(teamModel.repositories)),\r
                                new CollectionModel<String>(repos), new ChoiceRenderer<String>("", ""), 10, false);\r
+\r
+               // users palette\r
                final Palette<String> users = new Palette<String>("users", new ListModel<String>(\r
                                new ArrayList<String>(teamUsers)), new CollectionModel<String>(GitBlit.self()\r
                                .getAllUsernames()), new ChoiceRenderer<String>("", ""), 10, false);\r
+\r
+               // pre-receive palette\r
+               if (teamModel.preReceiveScripts != null) {\r
+                       preReceiveScripts.addAll(teamModel.preReceiveScripts);\r
+               }\r
+               final Palette<String> preReceivePalette = new Palette<String>("preReceiveScripts",\r
+                               new ListModel<String>(preReceiveScripts), new CollectionModel<String>(GitBlit\r
+                                               .self().getPreReceiveScriptsUnused(null)), new ChoiceRenderer<String>("",\r
+                                               ""), 12, true);\r
+\r
+               // post-receive palette\r
+               if (teamModel.postReceiveScripts != null) {\r
+                       postReceiveScripts.addAll(teamModel.postReceiveScripts);\r
+               }\r
+               final Palette<String> postReceivePalette = new Palette<String>("postReceiveScripts",\r
+                               new ListModel<String>(postReceiveScripts), new CollectionModel<String>(GitBlit\r
+                                               .self().getPostReceiveScriptsUnused(null)), new ChoiceRenderer<String>("",\r
+                                               ""), 12, true);\r
+\r
                Form<TeamModel> form = new Form<TeamModel>("editForm", model) {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -147,7 +173,25 @@ public class EditTeamPage extends RootSubPage {
                                        teamModel.mailingLists.clear();\r
                                        teamModel.mailingLists.addAll(list);\r
                                }\r
-                               \r
+\r
+                               // pre-receive scripts\r
+                               List<String> preReceiveScripts = new ArrayList<String>();\r
+                               Iterator<String> pres = preReceivePalette.getSelectedChoices();\r
+                               while (pres.hasNext()) {\r
+                                       preReceiveScripts.add(pres.next());\r
+                               }\r
+                               teamModel.preReceiveScripts.clear();\r
+                               teamModel.preReceiveScripts.addAll(preReceiveScripts);\r
+\r
+                               // post-receive scripts\r
+                               List<String> postReceiveScripts = new ArrayList<String>();\r
+                               Iterator<String> post = postReceivePalette.getSelectedChoices();\r
+                               while (post.hasNext()) {\r
+                                       postReceiveScripts.add(post.next());\r
+                               }\r
+                               teamModel.postReceiveScripts.clear();\r
+                               teamModel.postReceiveScripts.addAll(postReceiveScripts);\r
+\r
                                try {\r
                                        GitBlit.self().updateTeamModel(oldName, teamModel, isCreate);\r
                                } catch (GitBlitException e) {\r
@@ -173,8 +217,14 @@ public class EditTeamPage extends RootSubPage {
                mailingLists = new Model<String>(teamModel.mailingLists == null ? ""\r
                                : StringUtils.flattenStrings(teamModel.mailingLists, " "));\r
                form.add(new TextField<String>("mailingLists", mailingLists));\r
-               \r
+\r
                form.add(repositories);\r
+               form.add(preReceivePalette);\r
+               form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self()\r
+                               .getPreReceiveScriptsInherited(null)));\r
+               form.add(postReceivePalette);\r
+               form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self()\r
+                               .getPostReceiveScriptsInherited(null)));\r
 \r
                form.add(new Button("save"));\r
                Button cancel = new Button("cancel") {\r