Merge "Add a dropdown to control email notifications on user preference page"
This commit is contained in:
		@@ -1947,6 +1947,12 @@ link:rest-api-config.html#top-menu-item-info[TopMenuItemInfo] entities.
 | 
			
		||||
|`url_aliases`                  |optional|
 | 
			
		||||
A map of URL path pairs, where the first URL path is an alias for the
 | 
			
		||||
second URL path.
 | 
			
		||||
|`email_notifications`          ||
 | 
			
		||||
The type of email strategy to use. On `ENABLED`, the user will receive emails
 | 
			
		||||
from Gerrit. On `CC_ON_OWN_COMMENTS` the user will also receive emails for
 | 
			
		||||
their own comments. On `DISABLED` the user will not receive any email
 | 
			
		||||
notifications from Gerrit.
 | 
			
		||||
Allowed values are `ENABLED`, `CC_ON_OWN_COMMENTS`, `DISABLED`.
 | 
			
		||||
|============================================
 | 
			
		||||
 | 
			
		||||
[[preferences-input]]
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DateFormat;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DiffView;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.EmailStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ReviewCategoryStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.TimeFormat;
 | 
			
		||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
			
		||||
@@ -44,7 +45,6 @@ public class AccountPreferencesInfo extends JavaScriptObject {
 | 
			
		||||
    p.useFlashClipboard(defaultPrefs.isUseFlashClipboard());
 | 
			
		||||
    p.downloadScheme(defaultPrefs.getDownloadUrl());
 | 
			
		||||
    p.downloadCommand(defaultPrefs.getDownloadCommand());
 | 
			
		||||
    p.copySelfOnEmail(defaultPrefs.isCopySelfOnEmails());
 | 
			
		||||
    p.dateFormat(defaultPrefs.getDateFormat());
 | 
			
		||||
    p.timeFormat(defaultPrefs.getTimeFormat());
 | 
			
		||||
    p.relativeDateInChangeTable(defaultPrefs.isRelativeDateInChangeTable());
 | 
			
		||||
@@ -53,6 +53,7 @@ public class AccountPreferencesInfo extends JavaScriptObject {
 | 
			
		||||
    p.muteCommonPathPrefixes(defaultPrefs.isMuteCommonPathPrefixes());
 | 
			
		||||
    p.reviewCategoryStrategy(defaultPrefs.getReviewCategoryStrategy());
 | 
			
		||||
    p.diffView(defaultPrefs.getDiffView());
 | 
			
		||||
    p.emailStrategy(defaultPrefs.getEmailStrategy());
 | 
			
		||||
    return p;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -82,9 +83,6 @@ public class AccountPreferencesInfo extends JavaScriptObject {
 | 
			
		||||
  private final native String downloadCommandRaw()
 | 
			
		||||
  /*-{ return this.download_command }-*/;
 | 
			
		||||
 | 
			
		||||
  public final native boolean copySelfOnEmail()
 | 
			
		||||
  /*-{ return this.copy_self_on_email || false }-*/;
 | 
			
		||||
 | 
			
		||||
  public final DateFormat dateFormat() {
 | 
			
		||||
    String s = dateFormatRaw();
 | 
			
		||||
    return s != null ? DateFormat.valueOf(s) : null;
 | 
			
		||||
@@ -125,6 +123,14 @@ public class AccountPreferencesInfo extends JavaScriptObject {
 | 
			
		||||
  private final native String diffViewRaw()
 | 
			
		||||
  /*-{ return this.diff_view }-*/;
 | 
			
		||||
 | 
			
		||||
  public final EmailStrategy emailStrategy() {
 | 
			
		||||
    String s = emailStrategyRaw();
 | 
			
		||||
    return s != null ? EmailStrategy.valueOf(s) : null;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private final native String emailStrategyRaw()
 | 
			
		||||
  /*-{ return this.email_strategy }-*/;
 | 
			
		||||
 | 
			
		||||
  public final native JsArray<TopMenuItem> my()
 | 
			
		||||
  /*-{ return this.my; }-*/;
 | 
			
		||||
 | 
			
		||||
@@ -146,9 +152,6 @@ public class AccountPreferencesInfo extends JavaScriptObject {
 | 
			
		||||
  public final native void downloadCommandRaw(String d)
 | 
			
		||||
  /*-{ this.download_command = d }-*/;
 | 
			
		||||
 | 
			
		||||
  public final native void copySelfOnEmail(boolean c)
 | 
			
		||||
  /*-{ this.copy_self_on_email = c }-*/;
 | 
			
		||||
 | 
			
		||||
  public final void dateFormat(DateFormat f) {
 | 
			
		||||
    dateFormatRaw(f != null ? f.toString() : null);
 | 
			
		||||
  }
 | 
			
		||||
@@ -185,6 +188,12 @@ public class AccountPreferencesInfo extends JavaScriptObject {
 | 
			
		||||
  private final native void diffViewRaw(String d)
 | 
			
		||||
  /*-{ this.diff_view = d }-*/;
 | 
			
		||||
 | 
			
		||||
  public final void emailStrategy(EmailStrategy s) {
 | 
			
		||||
    emailStrategyRaw(s != null ? s.toString() : null);
 | 
			
		||||
  }
 | 
			
		||||
  private final native void emailStrategyRaw(String s)
 | 
			
		||||
  /*-{ this.email_strategy = s }-*/;
 | 
			
		||||
 | 
			
		||||
  public final void setMyMenus(List<TopMenuItem> myMenus) {
 | 
			
		||||
    initMy();
 | 
			
		||||
    for (TopMenuItem n : myMenus) {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,6 @@ public interface AccountConstants extends Constants {
 | 
			
		||||
  String contextWholeFile();
 | 
			
		||||
  String showSiteHeader();
 | 
			
		||||
  String useFlashClipboard();
 | 
			
		||||
  String copySelfOnEmails();
 | 
			
		||||
  String reviewCategoryLabel();
 | 
			
		||||
  String messageShowInReviewCategoryNone();
 | 
			
		||||
  String messageShowInReviewCategoryName();
 | 
			
		||||
@@ -159,4 +158,9 @@ public interface AccountConstants extends Constants {
 | 
			
		||||
  String welcomeAgreementText();
 | 
			
		||||
  String welcomeAgreementLater();
 | 
			
		||||
  String welcomeContinue();
 | 
			
		||||
 | 
			
		||||
  String messageEnabled();
 | 
			
		||||
  String messageCCMeOnMyComments();
 | 
			
		||||
  String messageDisabled();
 | 
			
		||||
  String emailFieldLabel();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,6 @@ registeredOn = Registered
 | 
			
		||||
accountId = Account ID
 | 
			
		||||
showSiteHeader = Show Site Header
 | 
			
		||||
useFlashClipboard = Use Flash Clipboard Widget
 | 
			
		||||
copySelfOnEmails = CC Me On Comments I Write
 | 
			
		||||
reviewCategoryLabel = Display In Review Category
 | 
			
		||||
messageShowInReviewCategoryNone = None (default)
 | 
			
		||||
messageShowInReviewCategoryName = Show Name
 | 
			
		||||
@@ -15,6 +14,11 @@ messageShowInReviewCategoryEmail = Show Email
 | 
			
		||||
messageShowInReviewCategoryUsername = Show Username
 | 
			
		||||
messageShowInReviewCategoryAbbrev = Show Abbreviated Name
 | 
			
		||||
 | 
			
		||||
emailFieldLabel = Email Notifications:
 | 
			
		||||
messageEnabled = Enabled
 | 
			
		||||
messageCCMeOnMyComments = CC Me On Comments I Write
 | 
			
		||||
messageDisabled = Disabled
 | 
			
		||||
 | 
			
		||||
maximumPageSizeFieldLabel = Maximum Page Size:
 | 
			
		||||
diffViewLabel = Diff View:
 | 
			
		||||
dateFormatLabel = Date/Time Format:
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@ import com.google.gerrit.client.rpc.Natives;
 | 
			
		||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
 | 
			
		||||
import com.google.gerrit.client.ui.OnEditEnabler;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.EmailStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ReviewCategoryStrategy;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.event.dom.client.ClickEvent;
 | 
			
		||||
@@ -50,7 +51,6 @@ import java.util.List;
 | 
			
		||||
public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
  private CheckBox showSiteHeader;
 | 
			
		||||
  private CheckBox useFlashClipboard;
 | 
			
		||||
  private CheckBox copySelfOnEmails;
 | 
			
		||||
  private CheckBox relativeDateInChangeTable;
 | 
			
		||||
  private CheckBox sizeBarInChangeTable;
 | 
			
		||||
  private CheckBox legacycidInChangeTable;
 | 
			
		||||
@@ -60,6 +60,7 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
  private ListBox timeFormat;
 | 
			
		||||
  private ListBox reviewCategoryStrategy;
 | 
			
		||||
  private ListBox diffView;
 | 
			
		||||
  private ListBox emailStrategy;
 | 
			
		||||
  private StringListPanel myMenus;
 | 
			
		||||
  private Button save;
 | 
			
		||||
 | 
			
		||||
@@ -69,7 +70,6 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
 | 
			
		||||
    showSiteHeader = new CheckBox(Util.C.showSiteHeader());
 | 
			
		||||
    useFlashClipboard = new CheckBox(Util.C.useFlashClipboard());
 | 
			
		||||
    copySelfOnEmails = new CheckBox(Util.C.copySelfOnEmails());
 | 
			
		||||
    maximumPageSize = new ListBox();
 | 
			
		||||
    for (final short v : PAGESIZE_CHOICES) {
 | 
			
		||||
      maximumPageSize.addItem(Util.M.rowsPerPage(v), String.valueOf(v));
 | 
			
		||||
@@ -92,6 +92,20 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
        Util.C.messageShowInReviewCategoryAbbrev(),
 | 
			
		||||
        AccountGeneralPreferences.ReviewCategoryStrategy.ABBREV.name());
 | 
			
		||||
 | 
			
		||||
    emailStrategy = new ListBox();
 | 
			
		||||
    emailStrategy.addItem(Util.C.messageEnabled(),
 | 
			
		||||
        AccountGeneralPreferences.EmailStrategy.ENABLED.name());
 | 
			
		||||
    emailStrategy
 | 
			
		||||
        .addItem(
 | 
			
		||||
            Util.C.messageCCMeOnMyComments(),
 | 
			
		||||
            AccountGeneralPreferences.EmailStrategy.CC_ON_OWN_COMMENTS
 | 
			
		||||
                .name());
 | 
			
		||||
    emailStrategy
 | 
			
		||||
        .addItem(
 | 
			
		||||
            Util.C.messageDisabled(),
 | 
			
		||||
            AccountGeneralPreferences.EmailStrategy.DISABLED
 | 
			
		||||
                .name());
 | 
			
		||||
 | 
			
		||||
    diffView = new ListBox();
 | 
			
		||||
    diffView.addItem(
 | 
			
		||||
        com.google.gerrit.client.changes.Util.C.sideBySide(),
 | 
			
		||||
@@ -141,7 +155,7 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    muteCommonPathPrefixes = new CheckBox(Util.C.muteCommonPathPrefixes());
 | 
			
		||||
 | 
			
		||||
    boolean flashClippy = !UserAgent.hasJavaScriptClipboard() && UserAgent.Flash.isInstalled();
 | 
			
		||||
    final Grid formGrid = new Grid(10 + (flashClippy ? 1 : 0), 2);
 | 
			
		||||
    final Grid formGrid = new Grid(11 + (flashClippy ? 1 : 0), 2);
 | 
			
		||||
 | 
			
		||||
    int row = 0;
 | 
			
		||||
    formGrid.setText(row, labelIdx, "");
 | 
			
		||||
@@ -154,10 +168,6 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
      row++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    formGrid.setText(row, labelIdx, "");
 | 
			
		||||
    formGrid.setWidget(row, fieldIdx, copySelfOnEmails);
 | 
			
		||||
    row++;
 | 
			
		||||
 | 
			
		||||
    formGrid.setText(row, labelIdx, Util.C.reviewCategoryLabel());
 | 
			
		||||
    formGrid.setWidget(row, fieldIdx, reviewCategoryStrategy);
 | 
			
		||||
    row++;
 | 
			
		||||
@@ -186,6 +196,10 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    formGrid.setWidget(row, fieldIdx, muteCommonPathPrefixes);
 | 
			
		||||
    row++;
 | 
			
		||||
 | 
			
		||||
    formGrid.setText(row, labelIdx, Util.C.emailFieldLabel());
 | 
			
		||||
    formGrid.setWidget(row, fieldIdx, emailStrategy);
 | 
			
		||||
    row++;
 | 
			
		||||
 | 
			
		||||
    formGrid.setText(row, labelIdx, Util.C.diffViewLabel());
 | 
			
		||||
    formGrid.setWidget(row, fieldIdx, diffView);
 | 
			
		||||
 | 
			
		||||
@@ -208,7 +222,6 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    final OnEditEnabler e = new OnEditEnabler(save);
 | 
			
		||||
    e.listenTo(showSiteHeader);
 | 
			
		||||
    e.listenTo(useFlashClipboard);
 | 
			
		||||
    e.listenTo(copySelfOnEmails);
 | 
			
		||||
    e.listenTo(maximumPageSize);
 | 
			
		||||
    e.listenTo(dateFormat);
 | 
			
		||||
    e.listenTo(timeFormat);
 | 
			
		||||
@@ -218,6 +231,7 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    e.listenTo(muteCommonPathPrefixes);
 | 
			
		||||
    e.listenTo(diffView);
 | 
			
		||||
    e.listenTo(reviewCategoryStrategy);
 | 
			
		||||
    e.listenTo(emailStrategy);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
@@ -240,7 +254,6 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
  private void enable(final boolean on) {
 | 
			
		||||
    showSiteHeader.setEnabled(on);
 | 
			
		||||
    useFlashClipboard.setEnabled(on);
 | 
			
		||||
    copySelfOnEmails.setEnabled(on);
 | 
			
		||||
    maximumPageSize.setEnabled(on);
 | 
			
		||||
    dateFormat.setEnabled(on);
 | 
			
		||||
    timeFormat.setEnabled(on);
 | 
			
		||||
@@ -250,12 +263,12 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    muteCommonPathPrefixes.setEnabled(on);
 | 
			
		||||
    reviewCategoryStrategy.setEnabled(on);
 | 
			
		||||
    diffView.setEnabled(on);
 | 
			
		||||
    emailStrategy.setEnabled(on);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void display(AccountPreferencesInfo p) {
 | 
			
		||||
    showSiteHeader.setValue(p.showSiteHeader());
 | 
			
		||||
    useFlashClipboard.setValue(p.useFlashClipboard());
 | 
			
		||||
    copySelfOnEmails.setValue(p.copySelfOnEmail());
 | 
			
		||||
    setListBox(maximumPageSize, DEFAULT_PAGESIZE, p.changesPerPage());
 | 
			
		||||
    setListBox(dateFormat, AccountGeneralPreferences.DateFormat.STD, //
 | 
			
		||||
        p.dateFormat());
 | 
			
		||||
@@ -271,6 +284,9 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    setListBox(diffView,
 | 
			
		||||
        AccountGeneralPreferences.DiffView.SIDE_BY_SIDE,
 | 
			
		||||
        p.diffView());
 | 
			
		||||
    setListBox(emailStrategy,
 | 
			
		||||
        AccountGeneralPreferences.EmailStrategy.ENABLED,
 | 
			
		||||
        p.emailStrategy());
 | 
			
		||||
    display(p.my());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -337,7 +353,6 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    AccountPreferencesInfo p = AccountPreferencesInfo.create();
 | 
			
		||||
    p.showSiteHeader(showSiteHeader.getValue());
 | 
			
		||||
    p.useFlashClipboard(useFlashClipboard.getValue());
 | 
			
		||||
    p.copySelfOnEmail(copySelfOnEmails.getValue());
 | 
			
		||||
    p.changesPerPage(getListBox(maximumPageSize, DEFAULT_PAGESIZE));
 | 
			
		||||
    p.dateFormat(getListBox(dateFormat,
 | 
			
		||||
        AccountGeneralPreferences.DateFormat.STD,
 | 
			
		||||
@@ -355,6 +370,8 @@ public class MyPreferencesScreen extends SettingsScreen {
 | 
			
		||||
    p.diffView(getListBox(diffView,
 | 
			
		||||
        AccountGeneralPreferences.DiffView.SIDE_BY_SIDE,
 | 
			
		||||
        AccountGeneralPreferences.DiffView.values()));
 | 
			
		||||
    p.emailStrategy(getListBox(emailStrategy,
 | 
			
		||||
        EmailStrategy.ENABLED, EmailStrategy.values()));
 | 
			
		||||
 | 
			
		||||
    List<TopMenuItem> items = new ArrayList<>();
 | 
			
		||||
    for (List<String> v : myMenus.getValues()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -76,6 +76,12 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
    UNIFIED_DIFF
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static enum EmailStrategy {
 | 
			
		||||
    ENABLED,
 | 
			
		||||
    CC_ON_OWN_COMMENTS,
 | 
			
		||||
    DISABLED
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static enum TimeFormat {
 | 
			
		||||
    /** 12-hour clock: 1:15 am, 2:13 pm */
 | 
			
		||||
    HHMM_12("h:mm a"),
 | 
			
		||||
@@ -120,9 +126,7 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
  @Column(id = 6, length = 20, notNull = false)
 | 
			
		||||
  protected String downloadCommand;
 | 
			
		||||
 | 
			
		||||
  /** If true we CC the user on their own changes. */
 | 
			
		||||
  @Column(id = 7)
 | 
			
		||||
  protected boolean copySelfOnEmail;
 | 
			
		||||
  // DELETED: id = 7 (copySelfOnEmail)
 | 
			
		||||
 | 
			
		||||
  @Column(id = 8, length = 10, notNull = false)
 | 
			
		||||
  protected String dateFormat;
 | 
			
		||||
@@ -155,6 +159,9 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
  @Column(id = 19)
 | 
			
		||||
  protected boolean muteCommonPathPrefixes;
 | 
			
		||||
 | 
			
		||||
  @Column(id = 20, length = 30, notNull = false)
 | 
			
		||||
  protected String emailStrategy;
 | 
			
		||||
 | 
			
		||||
  public AccountGeneralPreferences() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -242,14 +249,6 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isCopySelfOnEmails() {
 | 
			
		||||
    return copySelfOnEmail;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setCopySelfOnEmails(boolean includeSelfOnEmail) {
 | 
			
		||||
    copySelfOnEmail = includeSelfOnEmail;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isShowInfoInReviewCategory() {
 | 
			
		||||
    return getReviewCategoryStrategy() != ReviewCategoryStrategy.NONE;
 | 
			
		||||
  }
 | 
			
		||||
@@ -307,6 +306,17 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
    this.diffView = diffView.name();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public EmailStrategy getEmailStrategy() {
 | 
			
		||||
    if (emailStrategy == null) {
 | 
			
		||||
      return EmailStrategy.ENABLED;
 | 
			
		||||
    }
 | 
			
		||||
    return EmailStrategy.valueOf(emailStrategy);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setEmailStrategy(EmailStrategy strategy) {
 | 
			
		||||
    this.emailStrategy = strategy.name();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isSizeBarInChangeTable() {
 | 
			
		||||
    return sizeBarInChangeTable;
 | 
			
		||||
  }
 | 
			
		||||
@@ -336,7 +346,6 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
    maximumPageSize = DEFAULT_PAGESIZE;
 | 
			
		||||
    showSiteHeader = true;
 | 
			
		||||
    useFlashClipboard = true;
 | 
			
		||||
    copySelfOnEmail = false;
 | 
			
		||||
    reviewCategoryStrategy = null;
 | 
			
		||||
    downloadUrl = null;
 | 
			
		||||
    downloadCommand = null;
 | 
			
		||||
@@ -347,5 +356,6 @@ public final class AccountGeneralPreferences {
 | 
			
		||||
    sizeBarInChangeTable = true;
 | 
			
		||||
    legacycidInChangeTable = false;
 | 
			
		||||
    muteCommonPathPrefixes = true;
 | 
			
		||||
    emailStrategy = null;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DateFormat;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DiffView;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.EmailStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ReviewCategoryStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.TimeFormat;
 | 
			
		||||
import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
			
		||||
@@ -104,7 +105,6 @@ public class GetPreferences implements RestReadView<AccountResource> {
 | 
			
		||||
    Boolean useFlashClipboard;
 | 
			
		||||
    String downloadScheme;
 | 
			
		||||
    DownloadCommand downloadCommand;
 | 
			
		||||
    Boolean copySelfOnEmail;
 | 
			
		||||
    DateFormat dateFormat;
 | 
			
		||||
    TimeFormat timeFormat;
 | 
			
		||||
    Boolean relativeDateInChangeTable;
 | 
			
		||||
@@ -113,6 +113,7 @@ public class GetPreferences implements RestReadView<AccountResource> {
 | 
			
		||||
    Boolean muteCommonPathPrefixes;
 | 
			
		||||
    ReviewCategoryStrategy reviewCategoryStrategy;
 | 
			
		||||
    DiffView diffView;
 | 
			
		||||
    EmailStrategy emailStrategy;
 | 
			
		||||
    List<TopMenu.MenuItem> my;
 | 
			
		||||
    Map<String, String> urlAliases;
 | 
			
		||||
 | 
			
		||||
@@ -124,7 +125,6 @@ public class GetPreferences implements RestReadView<AccountResource> {
 | 
			
		||||
        useFlashClipboard = p.isUseFlashClipboard() ? true : null;
 | 
			
		||||
        downloadScheme = p.getDownloadUrl();
 | 
			
		||||
        downloadCommand = p.getDownloadCommand();
 | 
			
		||||
        copySelfOnEmail = p.isCopySelfOnEmails() ? true : null;
 | 
			
		||||
        dateFormat = p.getDateFormat();
 | 
			
		||||
        timeFormat = p.getTimeFormat();
 | 
			
		||||
        relativeDateInChangeTable = p.isRelativeDateInChangeTable() ? true : null;
 | 
			
		||||
@@ -133,6 +133,7 @@ public class GetPreferences implements RestReadView<AccountResource> {
 | 
			
		||||
        muteCommonPathPrefixes = p.isMuteCommonPathPrefixes() ? true : null;
 | 
			
		||||
        reviewCategoryStrategy = p.getReviewCategoryStrategy();
 | 
			
		||||
        diffView = p.getDiffView();
 | 
			
		||||
        emailStrategy = p.getEmailStrategy();
 | 
			
		||||
      }
 | 
			
		||||
      loadFromAllUsers(v, allUsers);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@ import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DateFormat;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DiffView;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.EmailStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ReviewCategoryStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.TimeFormat;
 | 
			
		||||
import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
			
		||||
@@ -64,7 +65,6 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
 | 
			
		||||
    public Boolean useFlashClipboard;
 | 
			
		||||
    public String downloadScheme;
 | 
			
		||||
    public DownloadCommand downloadCommand;
 | 
			
		||||
    public Boolean copySelfOnEmail;
 | 
			
		||||
    public DateFormat dateFormat;
 | 
			
		||||
    public TimeFormat timeFormat;
 | 
			
		||||
    public Boolean relativeDateInChangeTable;
 | 
			
		||||
@@ -73,6 +73,7 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
 | 
			
		||||
    public Boolean muteCommonPathPrefixes;
 | 
			
		||||
    public ReviewCategoryStrategy reviewCategoryStrategy;
 | 
			
		||||
    public DiffView diffView;
 | 
			
		||||
    public EmailStrategy emailStrategy;
 | 
			
		||||
    public List<TopMenu.MenuItem> my;
 | 
			
		||||
    public Map<String, String> urlAliases;
 | 
			
		||||
  }
 | 
			
		||||
@@ -146,9 +147,6 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
 | 
			
		||||
      if (i.downloadCommand != null) {
 | 
			
		||||
        p.setDownloadCommand(i.downloadCommand);
 | 
			
		||||
      }
 | 
			
		||||
      if (i.copySelfOnEmail != null) {
 | 
			
		||||
        p.setCopySelfOnEmails(i.copySelfOnEmail);
 | 
			
		||||
      }
 | 
			
		||||
      if (i.dateFormat != null) {
 | 
			
		||||
        p.setDateFormat(i.dateFormat);
 | 
			
		||||
      }
 | 
			
		||||
@@ -173,6 +171,9 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
 | 
			
		||||
      if (i.diffView != null) {
 | 
			
		||||
        p.setDiffView(i.diffView);
 | 
			
		||||
      }
 | 
			
		||||
      if (i.emailStrategy != null) {
 | 
			
		||||
        p.setEmailStrategy(i.emailStrategy);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      db.get().accounts().update(Collections.singleton(a));
 | 
			
		||||
      db.get().commit();
 | 
			
		||||
 
 | 
			
		||||
@@ -48,13 +48,14 @@ public class SetPreferences implements RestModifyView<ConfigResource, Input> {
 | 
			
		||||
      IOException, ConfigInvalidException {
 | 
			
		||||
    if (i.changesPerPage != null || i.showSiteHeader != null
 | 
			
		||||
        || i.useFlashClipboard != null || i.downloadScheme != null
 | 
			
		||||
        || i.downloadCommand != null || i.copySelfOnEmail != null
 | 
			
		||||
        || i.downloadCommand != null
 | 
			
		||||
        || i.dateFormat != null || i.timeFormat != null
 | 
			
		||||
        || i.relativeDateInChangeTable != null
 | 
			
		||||
        || i.sizeBarInChangeTable != null
 | 
			
		||||
        || i.legacycidInChangeTable != null
 | 
			
		||||
        || i.muteCommonPathPrefixes != null
 | 
			
		||||
        || i.reviewCategoryStrategy != null) {
 | 
			
		||||
        || i.reviewCategoryStrategy != null
 | 
			
		||||
        || i.emailStrategy != null) {
 | 
			
		||||
      throw new BadRequestException("unsupported option");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 | 
			
		||||
import com.google.common.collect.Sets;
 | 
			
		||||
import com.google.gerrit.common.errors.EmailException;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Account;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.EmailStrategy;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.UserIdentity;
 | 
			
		||||
import com.google.gerrit.server.account.AccountState;
 | 
			
		||||
import com.google.gerrit.server.mail.EmailHeader.AddressList;
 | 
			
		||||
@@ -95,28 +96,29 @@ public abstract class OutgoingEmail {
 | 
			
		||||
    if (shouldSendMessage()) {
 | 
			
		||||
      if (fromId != null) {
 | 
			
		||||
        final Account fromUser = args.accountCache.get(fromId).getAccount();
 | 
			
		||||
        EmailStrategy strategy =
 | 
			
		||||
            fromUser.getGeneralPreferences().getEmailStrategy();
 | 
			
		||||
 | 
			
		||||
        if (fromUser.getGeneralPreferences().isCopySelfOnEmails()) {
 | 
			
		||||
        if (strategy == EmailStrategy.CC_ON_OWN_COMMENTS) {
 | 
			
		||||
          // If we are impersonating a user, make sure they receive a CC of
 | 
			
		||||
          // this message so they can always review and audit what we sent
 | 
			
		||||
          // on their behalf to others.
 | 
			
		||||
          //
 | 
			
		||||
          add(RecipientType.CC, fromId);
 | 
			
		||||
 | 
			
		||||
        } else if (rcptTo.remove(fromId)) {
 | 
			
		||||
          // If they don't want a copy, but we queued one up anyway,
 | 
			
		||||
          // drop them from the recipient lists.
 | 
			
		||||
          //
 | 
			
		||||
          final String fromEmail = fromUser.getPreferredEmail();
 | 
			
		||||
          for (Iterator<Address> i = smtpRcptTo.iterator(); i.hasNext();) {
 | 
			
		||||
            if (i.next().email.equals(fromEmail)) {
 | 
			
		||||
              i.remove();
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          for (EmailHeader hdr : headers.values()) {
 | 
			
		||||
            if (hdr instanceof AddressList) {
 | 
			
		||||
              ((AddressList) hdr).remove(fromEmail);
 | 
			
		||||
            }
 | 
			
		||||
          removeUser(fromUser);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check the preferences of all recipients. If any user has disabled
 | 
			
		||||
        // his email notifications then drop him from recipients' list
 | 
			
		||||
        for (Account.Id id : rcptTo) {
 | 
			
		||||
          Account thisUser = args.accountCache.get(id).getAccount();
 | 
			
		||||
          if (thisUser.getGeneralPreferences().getEmailStrategy()
 | 
			
		||||
                  == EmailStrategy.DISABLED) {
 | 
			
		||||
            removeUser(thisUser);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if (smtpRcptTo.isEmpty()) {
 | 
			
		||||
@@ -476,6 +478,20 @@ public abstract class OutgoingEmail {
 | 
			
		||||
    return r.toString();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void removeUser(Account user) {
 | 
			
		||||
    String fromEmail = user.getPreferredEmail();
 | 
			
		||||
    for (Iterator<Address> j = smtpRcptTo.iterator(); j.hasNext();) {
 | 
			
		||||
      if (j.next().email.equals(fromEmail)) {
 | 
			
		||||
        j.remove();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    for (EmailHeader hdr : headers.values()) {
 | 
			
		||||
      if (hdr instanceof AddressList) {
 | 
			
		||||
        ((AddressList) hdr).remove(fromEmail);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static String safeToString(Object obj) {
 | 
			
		||||
    return obj != null ? obj.toString() : "";
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ import java.util.List;
 | 
			
		||||
/** A version of the database schema. */
 | 
			
		||||
public abstract class SchemaVersion {
 | 
			
		||||
  /** The current schema version. */
 | 
			
		||||
  public static final Class<Schema_115> C = Schema_115.class;
 | 
			
		||||
  public static final Class<Schema_116> C = Schema_116.class;
 | 
			
		||||
 | 
			
		||||
  public static int getBinaryVersion() {
 | 
			
		||||
    return guessVersion(C);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,43 @@
 | 
			
		||||
// Copyright (C) 2014 The Android Open Source Project
 | 
			
		||||
//
 | 
			
		||||
// Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
// you may not use this file except in compliance with the License.
 | 
			
		||||
// You may obtain a copy of the License at
 | 
			
		||||
//
 | 
			
		||||
// http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
//
 | 
			
		||||
// Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
// distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
// See the License for the specific language governing permissions and
 | 
			
		||||
// limitations under the License.
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.server.schema;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
			
		||||
import com.google.gwtorm.jdbc.JdbcSchema;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
import com.google.inject.Provider;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.sql.Statement;
 | 
			
		||||
 | 
			
		||||
public class Schema_116 extends SchemaVersion {
 | 
			
		||||
  @Inject
 | 
			
		||||
  Schema_116(Provider<Schema_115> prior) {
 | 
			
		||||
    super(prior);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected void migrateData(ReviewDb db, UpdateUI ui) throws SQLException {
 | 
			
		||||
    ui.message("Migrate user preference copySelfOnEmail to emailStrategy");
 | 
			
		||||
    try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement()) {
 | 
			
		||||
      stmt.executeUpdate("UPDATE accounts SET "
 | 
			
		||||
          + "EMAIL_STRATEGY='ENABLED' "
 | 
			
		||||
          + "WHERE (COPY_SELF_ON_EMAIL='N')");
 | 
			
		||||
      stmt.executeUpdate("UPDATE accounts SET "
 | 
			
		||||
          + "EMAIL_STRATEGY='CC_ON_OWN_COMMENTS' "
 | 
			
		||||
          + "WHERE (COPY_SELF_ON_EMAIL='Y')");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user