From a4231d30c4d2765c80f57df79cd1d4d39a9795ea Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Tue, 30 Oct 2012 17:05:30 -0400 Subject: [PATCH] Added null checkinng and logging for edit user permissions (issue 155) --- src/com/gitblit/client/EditRepositoryDialog.java | 88 ++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index 0adf8a8..b4b6629 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -24,6 +24,8 @@ import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.text.MessageFormat; import java.util.ArrayList; @@ -37,6 +39,7 @@ import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -59,6 +62,7 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.AuthorizationControl; import com.gitblit.Constants.FederationStrategy; +import com.gitblit.Constants.RegistrantType; import com.gitblit.models.RegistrantAccessPermission; import com.gitblit.models.RepositoryModel; import com.gitblit.utils.ArrayUtils; @@ -116,6 +120,10 @@ private JComboBox ownerField; private JComboBox headRefField; + + private JComboBox gcPeriod; + + private JTextField gcThreshold; private RegistrantPermissionsPanel usersPalette; @@ -189,6 +197,13 @@ anRepository.availableRefs.toArray()); headRefField.setSelectedItem(anRepository.HEAD); } + + Integer [] gcPeriods = { 1, 2, 3, 4, 5, 7, 10, 14 }; + gcPeriod = new JComboBox(gcPeriods); + gcPeriod.setSelectedItem(anRepository.gcPeriod); + + gcThreshold = new JTextField(8); + gcThreshold.setText(anRepository.gcThreshold); ownerField = new JComboBox(); @@ -218,13 +233,41 @@ accessRestriction = new JComboBox(AccessRestrictionType.values()); accessRestriction.setRenderer(new AccessRestrictionRenderer()); accessRestriction.setSelectedItem(anRepository.accessRestriction); + accessRestriction.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + AccessRestrictionType art = (AccessRestrictionType) accessRestriction.getSelectedItem(); + EditRepositoryDialog.this.setupAccessPermissions(art); + } + } + }); boolean authenticated = anRepository.authorizationControl != null && AuthorizationControl.AUTHENTICATED.equals(anRepository.authorizationControl); allowAuthenticated = new JRadioButton(Translation.get("gb.allowAuthenticatedDescription")); allowAuthenticated.setSelected(authenticated); + allowAuthenticated.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + usersPalette.setEnabled(false); + teamsPalette.setEnabled(false); + } + } + }); + allowNamed = new JRadioButton(Translation.get("gb.allowNamedDescription")); allowNamed.setSelected(!authenticated); + allowNamed.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + usersPalette.setEnabled(true); + teamsPalette.setEnabled(true); + } + } + }); ButtonGroup group = new ButtonGroup(); group.add(allowAuthenticated); @@ -255,7 +298,8 @@ fieldsPanel .add(newFieldPanel(Translation.get("gb.origin"), originField)); fieldsPanel.add(newFieldPanel(Translation.get("gb.headRef"), headRefField)); - fieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField)); + fieldsPanel.add(newFieldPanel(Translation.get("gb.gcPeriod"), gcPeriod)); + fieldsPanel.add(newFieldPanel(Translation.get("gb.gcThreshold"), gcThreshold)); fieldsPanel.add(newFieldPanel(Translation.get("gb.enableTickets"), useTickets)); @@ -281,10 +325,15 @@ clonePushPanel .add(newFieldPanel(Translation.get("gb.verifyCommitter"), verifyCommitter)); - usersPalette = new RegistrantPermissionsPanel(); - JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5)); - northAccessPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"), + usersPalette = new RegistrantPermissionsPanel(RegistrantType.USER); + + JPanel northFieldsPanel = new JPanel(new GridLayout(0, 1, 0, 5)); + northFieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField)); + northFieldsPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"), accessRestriction), BorderLayout.NORTH); + + JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5)); + northAccessPanel.add(northFieldsPanel, BorderLayout.NORTH); northAccessPanel.add(newFieldPanel(Translation.get("gb.authorizationControl"), authorizationPanel), BorderLayout.CENTER); northAccessPanel.add(clonePushPanel, BorderLayout.SOUTH); @@ -294,7 +343,7 @@ accessPanel.add(newFieldPanel(Translation.get("gb.userPermissions"), usersPalette), BorderLayout.CENTER); - teamsPalette = new RegistrantPermissionsPanel(); + teamsPalette = new RegistrantPermissionsPanel(RegistrantType.TEAM); JPanel teamsPanel = new JPanel(new BorderLayout(5, 5)); teamsPanel.add( newFieldPanel(Translation.get("gb.teamPermissions"), @@ -349,6 +398,8 @@ panel.addTab(Translation.get("gb.customFields"), customFieldsScrollPane); + setupAccessPermissions(anRepository.accessRestriction); + JButton createButton = new JButton(Translation.get("gb.save")); createButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { @@ -402,6 +453,25 @@ panel.add(fieldLabel); panel.add(comp); return panel; + } + + private void setupAccessPermissions(AccessRestrictionType art) { + if (AccessRestrictionType.NONE.equals(art)) { + usersPalette.setEnabled(false); + teamsPalette.setEnabled(false); + + allowAuthenticated.setEnabled(false); + allowNamed.setEnabled(false); + } else { + allowAuthenticated.setEnabled(true); + allowNamed.setEnabled(true); + + if (allowNamed.isSelected()) { + usersPalette.setEnabled(true); + teamsPalette.setEnabled(true); + } + } + } private boolean validateFields() { @@ -481,6 +551,8 @@ : ownerField.getSelectedItem().toString(); repository.HEAD = headRefField.getSelectedItem() == null ? null : headRefField.getSelectedItem().toString(); + repository.gcPeriod = (Integer) gcPeriod.getSelectedItem(); + repository.gcThreshold = gcThreshold.getText(); repository.useTickets = useTickets.isSelected(); repository.useDocs = useDocs.isSelected(); repository.showRemoteBranches = showRemoteBranches.isSelected(); @@ -538,6 +610,7 @@ public void setAccessRestriction(AccessRestrictionType restriction) { this.accessRestriction.setSelectedItem(restriction); + setupAccessPermissions(restriction); } public void setAuthorizationControl(AuthorizationControl authorization) { @@ -659,14 +732,15 @@ * restriction. * */ - private class AccessRestrictionRenderer extends JLabel implements - ListCellRenderer { + private class AccessRestrictionRenderer extends DefaultListCellRenderer { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof AccessRestrictionType) { AccessRestrictionType restriction = (AccessRestrictionType) value; switch (restriction) { -- Gitblit v1.9.1