]> source.dussan.org Git - gitblit.git/commitdiff
Edit and store per-repository mail recipients in site and RPC
authorJames Moger <james.moger@gitblit.com>
Sat, 17 Dec 2011 20:17:46 +0000 (15:17 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 17 Dec 2011 20:17:46 +0000 (15:17 -0500)
src/com/gitblit/GitBlit.java
src/com/gitblit/MailExecutor.java
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/models/RepositoryModel.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/pages/EditRepositoryPage.html
src/com/gitblit/wicket/pages/EditRepositoryPage.java

index 2719734d552631d2f7f1520c4f24baa1cef616ed..8afa6df31f917e2818bd964ac797be232087ed0c 100644 (file)
@@ -731,6 +731,8 @@ public class GitBlit implements ServletContextListener {
                                        "gitblit", null, "preReceiveScript")));\r
                        model.postReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(\r
                                        "gitblit", null, "postReceiveScript")));\r
+                       model.mailRecipients = new ArrayList<String>(Arrays.asList(config.getStringList(\r
+                                       "gitblit", null, "mailRecipient")));\r
                }\r
                r.close();\r
                return model;\r
@@ -950,8 +952,16 @@ public class GitBlit implements ServletContextListener {
                config.setString("gitblit", null, "federationStrategy",\r
                                repository.federationStrategy.name());\r
                config.setBoolean("gitblit", null, "isFederated", repository.isFederated);\r
-               config.setStringList("gitblit", null, "preReceiveScript", repository.preReceiveScripts);\r
-               config.setStringList("gitblit", null, "postReceiveScript", repository.postReceiveScripts);\r
+               if (repository.preReceiveScripts != null) {\r
+                       config.setStringList("gitblit", null, "preReceiveScript", repository.preReceiveScripts);\r
+               }\r
+               if (repository.postReceiveScripts != null) {\r
+                       config.setStringList("gitblit", null, "postReceiveScript",\r
+                                       repository.postReceiveScripts);\r
+               }\r
+               if (repository.mailRecipients != null) {\r
+                       config.setStringList("gitblit", null, "mailRecipient", repository.mailRecipients);\r
+               }\r
                try {\r
                        config.save();\r
                } catch (IOException e) {\r
index 56a4ab58c8c5dac61826c3693e3bd0bc4c92de2a..77dc80ba017218cd5002aef6bd57c7020cff0038 100644 (file)
@@ -154,7 +154,12 @@ public class MailExecutor implements Runnable {
                        InternetAddress from = new InternetAddress(fromAddress, "Gitblit");\r
                        message.setFrom(from);\r
 \r
-                       Set<String> uniques = new HashSet<String>(toAddresses);\r
+                       // determine unique set of addresses\r
+                       Set<String> uniques = new HashSet<String>();\r
+                       for (String address : toAddresses) {\r
+                               uniques.add(address.toLowerCase());\r
+                       }\r
+                       \r
                        Pattern validEmail = Pattern\r
                                        .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})(\\]?)$");\r
                        List<InternetAddress> tos = new ArrayList<InternetAddress>();\r
@@ -168,8 +173,8 @@ public class MailExecutor implements Runnable {
                                        } catch (Throwable t) {\r
                                        }\r
                                }\r
-                       }\r
-                       message.setRecipients(Message.RecipientType.TO,\r
+                       }                       \r
+                       message.setRecipients(Message.RecipientType.BCC,\r
                                        tos.toArray(new InternetAddress[tos.size()]));\r
                        message.setSentDate(new Date());\r
                } catch (Exception e) {\r
index 0b6ef59aed3a0fdc3d2091b87c9555b112c92eaf..a70a61789419dfc24a6be0488ba293d503f43dc2 100644 (file)
@@ -52,7 +52,6 @@ import javax.swing.ListCellRenderer;
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.FederationStrategy;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.TeamModel;\r
 import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
@@ -89,6 +88,8 @@ public class EditRepositoryDialog extends JDialog {
        private JCheckBox skipSummaryMetrics;\r
 \r
        private JCheckBox isFrozen;\r
+       \r
+       private JTextField mailRecipientsField;\r
 \r
        private JComboBox accessRestriction;\r
 \r
@@ -159,6 +160,9 @@ public class EditRepositoryDialog extends JDialog {
                                anRepository.skipSummaryMetrics);\r
                isFrozen = new JCheckBox(Translation.get("gb.isFrozenDescription"), anRepository.isFrozen);\r
 \r
+               mailRecipientsField = new JTextField(anRepository.mailRecipients == null ? ""\r
+                               : StringUtils.flattenStrings(anRepository.mailRecipients, " "), 50);\r
+               \r
                accessRestriction = new JComboBox(AccessRestrictionType.values());\r
                accessRestriction.setRenderer(new AccessRestrictionRenderer());\r
                accessRestriction.setSelectedItem(anRepository.accessRestriction);\r
@@ -190,6 +194,7 @@ public class EditRepositoryDialog extends JDialog {
                fieldsPanel\r
                                .add(newFieldPanel(Translation.get("gb.skipSummaryMetrics"), skipSummaryMetrics));\r
                fieldsPanel.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));\r
+               fieldsPanel.add(newFieldPanel(Translation.get("gb.mailRecipients"), mailRecipientsField));\r
 \r
                usersPalette = new JPalette<String>();\r
                JPanel accessPanel = new JPanel(new BorderLayout(5, 5));\r
@@ -347,6 +352,8 @@ public class EditRepositoryDialog extends JDialog {
                repository.skipSizeCalculation = skipSizeCalculation.isSelected();\r
                repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();\r
                repository.isFrozen = isFrozen.isSelected();\r
+               \r
+               repository.mailRecipients = StringUtils.getStringsFromValue(mailRecipientsField.getText().trim(), " ");\r
 \r
                repository.accessRestriction = (AccessRestrictionType) accessRestriction.getSelectedItem();\r
                repository.federationStrategy = (FederationStrategy) federationStrategy.getSelectedItem();\r
index c5423f0321af8ab036bf92180c7bec40668ba67e..fc1de8acd16301e61def9206e416d19bab04c364 100644 (file)
@@ -57,6 +57,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
        public String size;\r
        public List<String> preReceiveScripts;\r
        public List<String> postReceiveScripts;\r
+       public List<String> mailRecipients;\r
 \r
        public RepositoryModel() {\r
                this("", "", "", new Date(0));\r
index c9afbc97aa8b6601996554a11155e648d5e75668..181aed9ccbc5959f3cfa27a2ec7bb56dcad725f4 100644 (file)
@@ -195,4 +195,6 @@ gb.teamMemberships = team memberships
 gb.newTeam = new team\r
 gb.permittedTeams = permitted teams\r
 gb.emptyRepository = empty repository\r
-gb.repositoryUrl = repository url
\ No newline at end of file
+gb.repositoryUrl = repository url\r
+gb.mailRecipients = mail recipients\r
+gb.mailRecipientsDescription = space-delimited, used by sendemail Groovy hook
\ No newline at end of file
index 9e22189828732490ee9ba71b57b0ba66a5b63bf4..43e42acf498a567b510254cc388ea599e6a4ada7 100644 (file)
                                <tr><th><wicket:message key="gb.skipSizeCalculation"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="skipSizeCalculation" tabindex="9" /> &nbsp;<i><wicket:message key="gb.skipSizeCalculationDescription"></wicket:message></i></td></tr>\r
                                <tr><th><wicket:message key="gb.skipSummaryMetrics"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="skipSummaryMetrics" tabindex="10" /> &nbsp;<i><wicket:message key="gb.skipSummaryMetricsDescription"></wicket:message></i></td></tr>\r
                                <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="isFrozen" tabindex="11" /> &nbsp;<i><wicket:message key="gb.isFrozenDescription"></wicket:message></i></td></tr>\r
+                               <tr><th><wicket:message key="gb.mailRecipients"></wicket:message></th><td class="edit"><input class="span9" type="text" wicket:id="mailRecipients" size="40" tabindex="12" /> &nbsp;<i><wicket:message key="gb.mailRecipientsDescription"></wicket:message></i></td></tr>\r
                                <tr><td colspan="2"><hr></hr></td></tr>\r
-                               <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select class="span6" wicket:id="accessRestriction" tabindex="12" /></td></tr>                                \r
+                               <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select class="span6" wicket:id="accessRestriction" tabindex="13" /></td></tr>                                \r
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.permittedUsers"></wicket:message></th><td style="padding:2px;"><span wicket:id="users"></span></td></tr>\r
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.permittedTeams"></wicket:message></th><td style="padding:2px;"><span wicket:id="teams"></span></td></tr>\r
                                <tr><td colspan="2"><hr></hr></td></tr>         \r
-                               <tr><th><wicket:message key="gb.federationStrategy"></wicket:message></th><td class="edit"><select class="span6" wicket:id="federationStrategy" tabindex="13" /></td></tr>\r
+                               <tr><th><wicket:message key="gb.federationStrategy"></wicket:message></th><td class="edit"><select class="span6" wicket:id="federationStrategy" tabindex="14" /></td></tr>\r
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.federationSets"></wicket:message></th><td style="padding:2px;"><span wicket:id="federationSets"></span></td></tr>\r
-                               <tr><th></th><td class="editButton"><input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="14" /> &nbsp; <input class="btn primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="15" /> </td></tr>\r
+                               <tr><th></th><td class="editButton"><input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="15" /> &nbsp; <input class="btn primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="16" /> </td></tr>\r
                        </tbody>\r
                </table>\r
        </form> \r
index 1a5ec3dd4057c44b60e6b588a1ed831b52d5c792..56e44f8886ca40a45325882bca4ff16d99f11c6f 100644 (file)
@@ -33,6 +33,8 @@ import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.IChoiceRenderer;\r
 import org.apache.wicket.markup.html.form.TextField;\r
 import org.apache.wicket.model.CompoundPropertyModel;\r
+import org.apache.wicket.model.IModel;\r
+import org.apache.wicket.model.Model;\r
 import org.apache.wicket.model.util.CollectionModel;\r
 import org.apache.wicket.model.util.ListModel;\r
 \r
@@ -53,6 +55,8 @@ public class EditRepositoryPage extends RootSubPage {
 \r
        private boolean isAdmin;\r
 \r
+       private IModel<String> mailRecipients;\r
+\r
        public EditRepositoryPage() {\r
                // create constructor\r
                super();\r
@@ -86,8 +90,7 @@ public class EditRepositoryPage extends RootSubPage {
                                Collections.sort(repositoryUsers);\r
                        }\r
                        federationSets.addAll(repositoryModel.federationSets);\r
-               }               \r
-               \r
+               }\r
 \r
                final String oldName = repositoryModel.name;\r
                // users palette\r
@@ -169,6 +172,13 @@ public class EditRepositoryPage extends RootSubPage {
                                                }\r
                                        }\r
 \r
+                                       // set mail recipients\r
+                                       String ml = mailRecipients.getObject();\r
+                                       if (!StringUtils.isEmpty(ml)) {\r
+                                               List<String> list = StringUtils.getStringsFromValue(ml.trim(), " ");\r
+                                               repositoryModel.mailRecipients = list;\r
+                                       }\r
+\r
                                        // save the repository\r
                                        GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate);\r
 \r
@@ -186,7 +196,7 @@ public class EditRepositoryPage extends RootSubPage {
                                                        repositoryUsers.add(repositoryModel.owner);\r
                                                }\r
                                                GitBlit.self().setRepositoryUsers(repositoryModel, repositoryUsers);\r
-                                               \r
+\r
                                                // save the team access list\r
                                                Iterator<String> teams = teamsPalette.getSelectedChoices();\r
                                                List<String> repositoryTeams = new ArrayList<String>();\r
@@ -230,6 +240,9 @@ public class EditRepositoryPage extends RootSubPage {
                form.add(new CheckBox("showReadme"));\r
                form.add(new CheckBox("skipSizeCalculation"));\r
                form.add(new CheckBox("skipSummaryMetrics"));\r
+               mailRecipients = new Model<String>(repositoryModel.mailRecipients == null ? ""\r
+                               : StringUtils.flattenStrings(repositoryModel.mailRecipients, " "));\r
+               form.add(new TextField<String>("mailRecipients", mailRecipients));\r
                form.add(usersPalette);\r
                form.add(teamsPalette);\r
                form.add(federationSetsPalette);\r