From 3a2c57e652e5b688261fee02baa3853526e9893a Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 17 Dec 2011 15:17:46 -0500 Subject: [PATCH] Edit and store per-repository mail recipients in site and RPC --- src/com/gitblit/GitBlit.java | 14 ++++++++++++-- src/com/gitblit/MailExecutor.java | 11 ++++++++--- .../gitblit/client/EditRepositoryDialog.java | 9 ++++++++- src/com/gitblit/models/RepositoryModel.java | 1 + .../gitblit/wicket/GitBlitWebApp.properties | 4 +++- .../wicket/pages/EditRepositoryPage.html | 7 ++++--- .../wicket/pages/EditRepositoryPage.java | 19 ++++++++++++++++--- 7 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 2719734d..8afa6df3 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -731,6 +731,8 @@ public class GitBlit implements ServletContextListener { "gitblit", null, "preReceiveScript"))); model.postReceiveScripts = new ArrayList(Arrays.asList(config.getStringList( "gitblit", null, "postReceiveScript"))); + model.mailRecipients = new ArrayList(Arrays.asList(config.getStringList( + "gitblit", null, "mailRecipient"))); } r.close(); return model; @@ -950,8 +952,16 @@ public class GitBlit implements ServletContextListener { config.setString("gitblit", null, "federationStrategy", repository.federationStrategy.name()); config.setBoolean("gitblit", null, "isFederated", repository.isFederated); - config.setStringList("gitblit", null, "preReceiveScript", repository.preReceiveScripts); - config.setStringList("gitblit", null, "postReceiveScript", repository.postReceiveScripts); + if (repository.preReceiveScripts != null) { + config.setStringList("gitblit", null, "preReceiveScript", repository.preReceiveScripts); + } + if (repository.postReceiveScripts != null) { + config.setStringList("gitblit", null, "postReceiveScript", + repository.postReceiveScripts); + } + if (repository.mailRecipients != null) { + config.setStringList("gitblit", null, "mailRecipient", repository.mailRecipients); + } try { config.save(); } catch (IOException e) { diff --git a/src/com/gitblit/MailExecutor.java b/src/com/gitblit/MailExecutor.java index 56a4ab58..77dc80ba 100644 --- a/src/com/gitblit/MailExecutor.java +++ b/src/com/gitblit/MailExecutor.java @@ -154,7 +154,12 @@ public class MailExecutor implements Runnable { InternetAddress from = new InternetAddress(fromAddress, "Gitblit"); message.setFrom(from); - Set uniques = new HashSet(toAddresses); + // determine unique set of addresses + Set uniques = new HashSet(); + for (String address : toAddresses) { + uniques.add(address.toLowerCase()); + } + Pattern validEmail = Pattern .compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); List tos = new ArrayList(); @@ -168,8 +173,8 @@ public class MailExecutor implements Runnable { } catch (Throwable t) { } } - } - message.setRecipients(Message.RecipientType.TO, + } + message.setRecipients(Message.RecipientType.BCC, tos.toArray(new InternetAddress[tos.size()])); message.setSentDate(new Date()); } catch (Exception e) { diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index 0b6ef59a..a70a6178 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -52,7 +52,6 @@ import javax.swing.ListCellRenderer; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.FederationStrategy; import com.gitblit.models.RepositoryModel; -import com.gitblit.models.TeamModel; import com.gitblit.utils.StringUtils; /** @@ -89,6 +88,8 @@ public class EditRepositoryDialog extends JDialog { private JCheckBox skipSummaryMetrics; private JCheckBox isFrozen; + + private JTextField mailRecipientsField; private JComboBox accessRestriction; @@ -159,6 +160,9 @@ public class EditRepositoryDialog extends JDialog { anRepository.skipSummaryMetrics); isFrozen = new JCheckBox(Translation.get("gb.isFrozenDescription"), anRepository.isFrozen); + mailRecipientsField = new JTextField(anRepository.mailRecipients == null ? "" + : StringUtils.flattenStrings(anRepository.mailRecipients, " "), 50); + accessRestriction = new JComboBox(AccessRestrictionType.values()); accessRestriction.setRenderer(new AccessRestrictionRenderer()); accessRestriction.setSelectedItem(anRepository.accessRestriction); @@ -190,6 +194,7 @@ public class EditRepositoryDialog extends JDialog { fieldsPanel .add(newFieldPanel(Translation.get("gb.skipSummaryMetrics"), skipSummaryMetrics)); fieldsPanel.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen)); + fieldsPanel.add(newFieldPanel(Translation.get("gb.mailRecipients"), mailRecipientsField)); usersPalette = new JPalette(); JPanel accessPanel = new JPanel(new BorderLayout(5, 5)); @@ -347,6 +352,8 @@ public class EditRepositoryDialog extends JDialog { repository.skipSizeCalculation = skipSizeCalculation.isSelected(); repository.skipSummaryMetrics = skipSummaryMetrics.isSelected(); repository.isFrozen = isFrozen.isSelected(); + + repository.mailRecipients = StringUtils.getStringsFromValue(mailRecipientsField.getText().trim(), " "); repository.accessRestriction = (AccessRestrictionType) accessRestriction.getSelectedItem(); repository.federationStrategy = (FederationStrategy) federationStrategy.getSelectedItem(); diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java index c5423f03..fc1de8ac 100644 --- a/src/com/gitblit/models/RepositoryModel.java +++ b/src/com/gitblit/models/RepositoryModel.java @@ -57,6 +57,7 @@ public class RepositoryModel implements Serializable, Comparable preReceiveScripts; public List postReceiveScripts; + public List mailRecipients; public RepositoryModel() { this("", "", "", new Date(0)); diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index c9afbc97..181aed9c 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -195,4 +195,6 @@ gb.teamMemberships = team memberships gb.newTeam = new team gb.permittedTeams = permitted teams gb.emptyRepository = empty repository -gb.repositoryUrl = repository url \ No newline at end of file +gb.repositoryUrl = repository url +gb.mailRecipients = mail recipients +gb.mailRecipientsDescription = space-delimited, used by sendemail Groovy hook \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/com/gitblit/wicket/pages/EditRepositoryPage.html index 9e221898..43e42acf 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -21,14 +21,15 @@       +  
-
- -   +   diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index 1a5ec3dd..56e44f88 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -33,6 +33,8 @@ import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.IChoiceRenderer; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; @@ -53,6 +55,8 @@ public class EditRepositoryPage extends RootSubPage { private boolean isAdmin; + private IModel mailRecipients; + public EditRepositoryPage() { // create constructor super(); @@ -86,8 +90,7 @@ public class EditRepositoryPage extends RootSubPage { Collections.sort(repositoryUsers); } federationSets.addAll(repositoryModel.federationSets); - } - + } final String oldName = repositoryModel.name; // users palette @@ -169,6 +172,13 @@ public class EditRepositoryPage extends RootSubPage { } } + // set mail recipients + String ml = mailRecipients.getObject(); + if (!StringUtils.isEmpty(ml)) { + List list = StringUtils.getStringsFromValue(ml.trim(), " "); + repositoryModel.mailRecipients = list; + } + // save the repository GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate); @@ -186,7 +196,7 @@ public class EditRepositoryPage extends RootSubPage { repositoryUsers.add(repositoryModel.owner); } GitBlit.self().setRepositoryUsers(repositoryModel, repositoryUsers); - + // save the team access list Iterator teams = teamsPalette.getSelectedChoices(); List repositoryTeams = new ArrayList(); @@ -230,6 +240,9 @@ public class EditRepositoryPage extends RootSubPage { form.add(new CheckBox("showReadme")); form.add(new CheckBox("skipSizeCalculation")); form.add(new CheckBox("skipSummaryMetrics")); + mailRecipients = new Model(repositoryModel.mailRecipients == null ? "" + : StringUtils.flattenStrings(repositoryModel.mailRecipients, " ")); + form.add(new TextField("mailRecipients", mailRecipients)); form.add(usersPalette); form.add(teamsPalette); form.add(federationSetsPalette); -- 2.39.5