From 1e1b85270f93b3bca624c99b478f3a9a23be2395 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Sat, 29 Sep 2012 23:40:46 -0400 Subject: [PATCH] Preliminary implementation of server-side forking (issue 137) --- src/com/gitblit/client/EditRepositoryDialog.java | 115 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 88 insertions(+), 27 deletions(-) diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index cc22512..8ce076e 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -28,13 +28,14 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; -import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -46,6 +47,7 @@ import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; @@ -55,6 +57,7 @@ import javax.swing.ScrollPaneConstants; import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.Constants.AuthorizationControl; import com.gitblit.Constants.FederationStrategy; import com.gitblit.models.RepositoryModel; import com.gitblit.utils.ArrayUtils; @@ -98,6 +101,10 @@ private JTextField mailingListsField; private JComboBox accessRestriction; + + private JRadioButton allowAuthenticated; + + private JRadioButton allowNamed; private JComboBox federationStrategy; @@ -124,6 +131,8 @@ private Set<String> repositoryNames; private JPanel customFieldsPanel; + + private List<JTextField> customTextfields; public EditRepositoryDialog(int protocolVersion) { this(protocolVersion, new RepositoryModel()); @@ -204,6 +213,21 @@ accessRestriction = new JComboBox(AccessRestrictionType.values()); accessRestriction.setRenderer(new AccessRestrictionRenderer()); accessRestriction.setSelectedItem(anRepository.accessRestriction); + + boolean authenticated = anRepository.authorizationControl != null + && AuthorizationControl.AUTHENTICATED.equals(anRepository.authorizationControl); + allowAuthenticated = new JRadioButton(Translation.get("gb.allowAuthenticatedDescription")); + allowAuthenticated.setSelected(authenticated); + allowNamed = new JRadioButton(Translation.get("gb.allowNamedDescription")); + allowNamed.setSelected(!authenticated); + + ButtonGroup group = new ButtonGroup(); + group.add(allowAuthenticated); + group.add(allowNamed); + + JPanel authorizationPanel = new JPanel(new GridLayout(0, 1)); + authorizationPanel.add(allowAuthenticated); + authorizationPanel.add(allowNamed); // federation strategies - remove ORIGIN choice if this repository has // no origin. @@ -244,12 +268,15 @@ mailingListsField)); usersPalette = new JPalette<String>(); + JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5)); + northAccessPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"), + accessRestriction), BorderLayout.NORTH); + northAccessPanel.add(newFieldPanel(Translation.get("gb.authorizationControl"), + authorizationPanel), BorderLayout.CENTER); + JPanel accessPanel = new JPanel(new BorderLayout(5, 5)); - accessPanel.add( - newFieldPanel(Translation.get("gb.accessRestriction"), - accessRestriction), BorderLayout.NORTH); - accessPanel.add( - newFieldPanel(Translation.get("gb.permittedUsers"), + accessPanel.add(northAccessPanel, BorderLayout.NORTH); + accessPanel.add(newFieldPanel(Translation.get("gb.permittedUsers"), usersPalette), BorderLayout.CENTER); teamsPalette = new JPalette<String>(); @@ -387,6 +414,9 @@ error("Relative folder references (../) are prohibited."); return false; } + if (rname.endsWith("/")) { + rname = rname.substring(0, rname.length() - 1); + } // confirm valid characters in repository name Character c = StringUtils.findInvalidCharacter(rname); @@ -458,6 +488,8 @@ repository.accessRestriction = (AccessRestrictionType) accessRestriction .getSelectedItem(); + repository.authorizationControl = allowAuthenticated.isSelected() ? + AuthorizationControl.AUTHENTICATED : AuthorizationControl.NAMED; repository.federationStrategy = (FederationStrategy) federationStrategy .getSelectedItem(); @@ -470,19 +502,30 @@ repository.postReceiveScripts = postReceivePalette.getSelections(); // Custom Fields - repository.customFields = new HashMap<String, String>(); - - for (Component aCustomFieldPanel : customFieldsPanel.getComponents()) { - JTextField textField = (JTextField) ((JPanel)aCustomFieldPanel).getComponent(1); - repository.customFields.put(textField.getName(), textField.getText()); + repository.customFields = new LinkedHashMap<String, String>(); + if (customTextfields != null) { + for (JTextField field : customTextfields) { + String key = field.getName(); + String value = field.getText(); + repository.customFields.put(key, value); + } } - return true; } private void error(String message) { JOptionPane.showMessageDialog(EditRepositoryDialog.this, message, Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE); + } + + public void setAccessRestriction(AccessRestrictionType restriction) { + this.accessRestriction.setSelectedItem(restriction); + } + + public void setAuthorizationControl(AuthorizationControl authorization) { + boolean authenticated = authorization != null && AuthorizationControl.AUTHENTICATED.equals(authorization); + this.allowAuthenticated.setSelected(authenticated); + this.allowNamed.setSelected(!authenticated); } public void setUsers(String owner, List<String> all, List<String> selected) { @@ -555,24 +598,42 @@ return teamsPalette.getSelections(); } - public void setCustomFields(RepositoryModel repository, List<String> customFields) { + public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) { customFieldsPanel.removeAll(); + customTextfields = new ArrayList<JTextField>(); - for (String customFieldDef : customFields) { - String[] customFieldProperty = customFieldDef.split("="); - String fieldName = customFieldProperty[0]; - String fieldLabel = customFieldProperty[1]; - - JTextField textField = new JTextField(repository.customFields.get(fieldName), 50); - textField.setName(fieldName); - - customFieldsPanel.add(newFieldPanel(fieldLabel, 250, textField)); - } + final Insets insets = new Insets(5, 5, 5, 5); + JPanel fields = new JPanel(new GridLayout(0, 1, 0, 5)) { + + private static final long serialVersionUID = 1L; + + @Override + public Insets getInsets() { + return insets; + } + }; - if (customFields.size() < 14) { - customFieldsPanel.add(Box.createVerticalGlue()); - customFieldsPanel.add(Box.createRigidArea(new Dimension(300, 300 - (customFields.size() * 22)))); + for (Map.Entry<String, String> entry : customFields.entrySet()) { + String field = entry.getKey(); + String value = ""; + if (repository.customFields != null && repository.customFields.containsKey(field)) { + value = repository.customFields.get(field); + } + JTextField textField = new JTextField(value); + textField.setName(field); + + textField.setPreferredSize(new Dimension(450, 26)); + + fields.add(newFieldPanel(entry.getValue(), 250, textField)); + + customTextfields.add(textField); } + JScrollPane jsp = new JScrollPane(fields); + jsp.getVerticalScrollBar().setBlockIncrement(100); + jsp.getVerticalScrollBar().setUnitIncrement(100); + jsp.setViewportBorder(null); + customFieldsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); + customFieldsPanel.add(jsp); } /** -- Gitblit v1.9.1