]> source.dussan.org Git - gitblit.git/commitdiff
Add "email me on my ticket changes" preference
authorJames Moger <james.moger@gitblit.com>
Thu, 5 Jun 2014 14:24:39 +0000 (10:24 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 5 Jun 2014 14:24:39 +0000 (10:24 -0400)
src/main/java/com/gitblit/ConfigUserService.java
src/main/java/com/gitblit/models/UserPreferences.java
src/main/java/com/gitblit/tickets/TicketNotifier.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/pages/UserPage.html
src/main/java/com/gitblit/wicket/pages/UserPage.java

index b5dfde3b0ae96893ac3fb595a3a086f320f8b008..9759eff7802ac9fc4423d603113725b46e29f649 100644 (file)
@@ -96,6 +96,8 @@ public class ConfigUserService implements IUserService {
 \r
        private static final String LOCALE = "locale";\r
 \r
+       private static final String EMAILONMYTICKETCHANGES = "emailMeOnMyTicketChanges";\r
+\r
        private static final String ACCOUNTTYPE = "accountType";\r
 \r
        private static final String DISABLED = "disabled";\r
@@ -711,6 +713,7 @@ public class ConfigUserService implements IUserService {
                                        String val = model.getPreferences().getLocale().getLanguage() + "_" + model.getPreferences().getLocale().getCountry();\r
                                        config.setString(USER, model.username, LOCALE, val);\r
                                }\r
+                               config.setBoolean(USER, model.username, EMAILONMYTICKETCHANGES, model.getPreferences().isEmailMeOnMyTicketChanges());\r
                        }\r
 \r
                        // user roles\r
@@ -887,6 +890,7 @@ public class ConfigUserService implements IUserService {
 \r
                                        // preferences\r
                                        user.getPreferences().setLocale(config.getString(USER, username, LOCALE));\r
+                                       user.getPreferences().setEmailMeOnMyTicketChanges(config.getBoolean(USER, username, EMAILONMYTICKETCHANGES, true));\r
 \r
                                        // user roles\r
                                        Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(\r
index 61db353cf5fb290f8ec928c59de3243b0749d74c..c95b0da5be34c26ed95fa027d137d152ab3edf83 100644 (file)
@@ -39,6 +39,8 @@ public class UserPreferences implements Serializable {
 
        private String locale;
 
+       private Boolean emailMeOnMyTicketChanges;
+
        private final Map<String, UserRepositoryPreferences> repositoryPreferences = new TreeMap<String, UserRepositoryPreferences>();
 
        public UserPreferences(String username) {
@@ -100,4 +102,15 @@ public class UserPreferences implements Serializable {
                Collections.sort(list);
                return list;
        }
+
+       public boolean isEmailMeOnMyTicketChanges() {
+               if (emailMeOnMyTicketChanges == null) {
+                       return true;
+               }
+               return emailMeOnMyTicketChanges;
+       }
+
+       public void setEmailMeOnMyTicketChanges(boolean value) {
+               this.emailMeOnMyTicketChanges = value;
+       }
 }
index 9a5e4e1d75bed1e4dadf5cc4f0798f22ef040104..07371b1b0591768941ca027c2957eb315e046459 100644 (file)
@@ -545,7 +545,6 @@ public class TicketNotifier {
                                }
                        }
                }
-               mailing.setRecipients(toAddresses);
 
                //
                // CC recipients
@@ -554,7 +553,7 @@ public class TicketNotifier {
 
                // repository owners
                if (!ArrayUtils.isEmpty(repository.owners)) {
-                       tos.addAll(repository.owners);
+                       ccs.addAll(repository.owners);
                }
 
                // cc users mentioned in last comment
@@ -595,6 +594,14 @@ public class TicketNotifier {
                }
                ccAddresses.addAll(settings.getStrings(Keys.mail.mailingLists));
 
+               // respect the author's email preference
+               UserModel lastAuthor = userManager.getUserModel(lastChange.author);
+               if (!lastAuthor.getPreferences().isEmailMeOnMyTicketChanges()) {
+                       toAddresses.remove(lastAuthor.emailAddress);
+                       ccAddresses.remove(lastAuthor.emailAddress);
+               }
+
+               mailing.setRecipients(toAddresses);
                mailing.setCCs(ccAddresses);
        }
 
index 90d30f29de024c76a6f498a13be5208820fa4a7e..c80d45ced9e13971a3db34b8f05fbea74c098ba1 100644 (file)
@@ -728,6 +728,8 @@ gb.accountPreferences = Account Preferences
 gb.accountPreferencesDescription = Specify your account preferences
 gb.languagePreference = Language Preference
 gb.languagePreferenceDescription = Select your preferred translation for Gitblit
+gb.emailMeOnMyTicketChanges = Email me on my ticket changes
+gb.emailMeOnMyTicketChangesDescription  = Send me an email notification for changes that I make to a ticket
 gb.displayNameDescription = The preferred name for display
 gb.emailAddressDescription = The primary email address for receiving notifications
 gb.sshKeys = SSH Keys
index d71cb2b5596a6bb0041495e1725d4f8bb7f28c7e..017fcb1f3fc1ccc235acd1790f392ecb371e672f 100644 (file)
@@ -64,7 +64,8 @@
                <form wicket:id="prefsForm">\r
                        <div wicket:id="displayName"></div>\r
                        <div wicket:id="emailAddress"></div>\r
-                       <div wicket:id="language"></div>        \r
+                       <div wicket:id="language"></div>\r
+                       <div wicket:id="emailMeOnMyTicketChanges"></div>\r
                        \r
                        <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /></div>\r
                </form> \r
index 940489637f1b326ad914e3b65d07f30a2a00cdbb..505f55d96a628fde60ecc3af317e06e034472610 100644 (file)
@@ -48,6 +48,7 @@ import com.gitblit.wicket.GitBlitWebApp;
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.GitblitRedirectException;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.panels.BooleanOption;\r
 import com.gitblit.wicket.panels.ChoiceOption;\r
 import com.gitblit.wicket.panels.ProjectRepositoryPanel;\r
 import com.gitblit.wicket.panels.SshKeysPanel;\r
@@ -219,6 +220,7 @@ public class UserPage extends RootPage {
                final IModel<String> displayName = Model.of(user.getDisplayName());\r
                final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress);\r
                final IModel<Language> language = Model.of(preferredLanguage);\r
+               final IModel<Boolean> emailMeOnMyTicketChanges = Model.of(user.getPreferences().isEmailMeOnMyTicketChanges());\r
 \r
                prefs.add(new TextOption("displayName",\r
                                getString("gb.displayName"),\r
@@ -236,6 +238,11 @@ public class UserPage extends RootPage {
                                language,\r
                                languages));\r
 \r
+               prefs.add(new BooleanOption("emailMeOnMyTicketChanges",\r
+                               getString("gb.emailMeOnMyTicketChanges"),\r
+                               getString("gb.emailMeOnMyTicketChangesDescription"),\r
+                               emailMeOnMyTicketChanges).setVisible(app().notifier().isSendingMail()));\r
+\r
                prefs.add(new AjaxButton("save") {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -253,6 +260,8 @@ public class UserPage extends RootPage {
                                        user.getPreferences().setLocale(lang.code);\r
                                }\r
 \r
+                               user.getPreferences().setEmailMeOnMyTicketChanges(emailMeOnMyTicketChanges.getObject());\r
+\r
                                try {\r
                                        app().gitblit().reviseUser(user.username, user);\r
 \r