}\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
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
\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
};\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
\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
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
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
}\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
}\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
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
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
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
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