Search in sources :

Example 1 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class CreateChangeIT method setSignedOffByFooter.

// TODO(davido): Expose setting of account preferences in the API
private void setSignedOffByFooter() throws Exception {
    RestResponse r = adminRestSession.get("/accounts/" + admin.email + "/preferences");
    r.assertOK();
    GeneralPreferencesInfo i = newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class);
    i.signedOffBy = true;
    r = adminRestSession.put("/accounts/" + admin.email + "/preferences", i);
    r.assertOK();
    GeneralPreferencesInfo o = newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class);
    assertThat(o.signedOffBy).isTrue();
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo)

Example 2 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class NotificationMailFormatIT method userReceivesPlaintextEmail.

@Test
public void userReceivesPlaintextEmail() throws Exception {
    // Set user preference to receive only plaintext content
    GeneralPreferencesInfo i = new GeneralPreferencesInfo();
    i.emailFormat = EmailFormat.PLAINTEXT;
    gApi.accounts().id(admin.getId().toString()).setPreferences(i);
    // Create change as admin and review as user
    PushOneCommit.Result r = createChange();
    setApiUser(user);
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.recommend());
    // Check that admin has received only plaintext content
    assertThat(sender.getMessages()).hasSize(1);
    FakeEmailSender.Message m = sender.getMessages().get(0);
    assertThat(m.body()).isNotNull();
    assertThat(m.htmlBody()).isNull();
    assertMailReplyTo(m, admin.email);
    assertMailReplyTo(m, user.email);
    // Reset user preference
    setApiUser(admin);
    i.emailFormat = EmailFormat.HTML_PLAINTEXT;
    gApi.accounts().id(admin.getId().toString()).setPreferences(i);
}
Also used : FakeEmailSender(com.google.gerrit.testutil.FakeEmailSender) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class GeneralPreferences method createDefault.

public static GeneralPreferences createDefault() {
    GeneralPreferencesInfo d = GeneralPreferencesInfo.defaults();
    GeneralPreferences p = createObject().cast();
    p.changesPerPage(d.changesPerPage);
    p.showSiteHeader(d.showSiteHeader);
    p.useFlashClipboard(d.useFlashClipboard);
    p.downloadScheme(d.downloadScheme);
    p.downloadCommand(d.downloadCommand);
    p.dateFormat(d.getDateFormat());
    p.timeFormat(d.getTimeFormat());
    p.highlightAssigneeInChangeTable(d.highlightAssigneeInChangeTable);
    p.relativeDateInChangeTable(d.relativeDateInChangeTable);
    p.sizeBarInChangeTable(d.sizeBarInChangeTable);
    p.legacycidInChangeTable(d.legacycidInChangeTable);
    p.muteCommonPathPrefixes(d.muteCommonPathPrefixes);
    p.signedOffBy(d.signedOffBy);
    p.emailFormat(d.emailFormat);
    p.reviewCategoryStrategy(d.getReviewCategoryStrategy());
    p.diffView(d.getDiffView());
    p.emailStrategy(d.emailStrategy);
    p.defaultBaseForMerges(d.defaultBaseForMerges);
    return p;
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo)

Example 4 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class GeneralPreferencesIT method getAndSetPreferences.

@Test
public void getAndSetPreferences() throws Exception {
    GeneralPreferencesInfo o = gApi.accounts().id(user42.id.toString()).getPreferences();
    assertPrefs(o, GeneralPreferencesInfo.defaults(), "my", "changeTable");
    assertThat(o.my).hasSize(7);
    assertThat(o.changeTable).isEmpty();
    GeneralPreferencesInfo i = GeneralPreferencesInfo.defaults();
    // change all default values
    i.changesPerPage *= -1;
    i.showSiteHeader ^= true;
    i.useFlashClipboard ^= true;
    i.downloadCommand = DownloadCommand.REPO_DOWNLOAD;
    i.dateFormat = DateFormat.US;
    i.timeFormat = TimeFormat.HHMM_24;
    i.emailStrategy = EmailStrategy.DISABLED;
    i.emailFormat = EmailFormat.PLAINTEXT;
    i.defaultBaseForMerges = DefaultBase.AUTO_MERGE;
    i.expandInlineDiffs ^= true;
    i.highlightAssigneeInChangeTable ^= true;
    i.relativeDateInChangeTable ^= true;
    i.sizeBarInChangeTable ^= true;
    i.legacycidInChangeTable ^= true;
    i.muteCommonPathPrefixes ^= true;
    i.signedOffBy ^= true;
    i.reviewCategoryStrategy = ReviewCategoryStrategy.ABBREV;
    i.diffView = DiffView.UNIFIED_DIFF;
    i.my = new ArrayList<>();
    i.my.add(new MenuItem("name", "url"));
    i.changeTable = new ArrayList<>();
    i.changeTable.add("Status");
    i.urlAliases = new HashMap<>();
    i.urlAliases.put("foo", "bar");
    o = gApi.accounts().id(user42.getId().toString()).setPreferences(i);
    assertPrefs(o, i, "my");
    assertThat(o.my).hasSize(1);
    assertThat(o.changeTable).hasSize(1);
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) MenuItem(com.google.gerrit.extensions.client.MenuItem) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with GeneralPreferencesInfo

use of com.google.gerrit.extensions.client.GeneralPreferencesInfo in project gerrit by GerritCodeReview.

the class GeneralPreferencesIT method overwriteConfiguredDefaults.

@Test
public void overwriteConfiguredDefaults() throws Exception {
    GeneralPreferencesInfo d = GeneralPreferencesInfo.defaults();
    int configuredChangesPerPage = d.changesPerPage * 2;
    GeneralPreferencesInfo update = new GeneralPreferencesInfo();
    update.changesPerPage = configuredChangesPerPage;
    gApi.config().server().setDefaultPreferences(update);
    GeneralPreferencesInfo o = gApi.accounts().id(admin.getId().toString()).getPreferences();
    assertThat(o.changesPerPage).isEqualTo(configuredChangesPerPage);
    assertPrefs(o, d, "my", "changeTable", "changesPerPage");
    int newChangesPerPage = configuredChangesPerPage * 2;
    GeneralPreferencesInfo i = new GeneralPreferencesInfo();
    i.changesPerPage = newChangesPerPage;
    GeneralPreferencesInfo a = gApi.accounts().id(admin.getId().toString()).setPreferences(i);
    assertThat(a.changesPerPage).isEqualTo(newChangesPerPage);
    assertPrefs(a, d, "my", "changeTable", "changesPerPage");
    a = gApi.accounts().id(admin.getId().toString()).getPreferences();
    assertThat(a.changesPerPage).isEqualTo(newChangesPerPage);
    assertPrefs(a, d, "my", "changeTable", "changesPerPage");
    // overwrite the configured default with original hard-coded default
    i = new GeneralPreferencesInfo();
    i.changesPerPage = d.changesPerPage;
    a = gApi.accounts().id(admin.getId().toString()).setPreferences(i);
    assertThat(a.changesPerPage).isEqualTo(d.changesPerPage);
    assertPrefs(a, d, "my", "changeTable", "changesPerPage");
    a = gApi.accounts().id(admin.getId().toString()).getPreferences();
    assertThat(a.changesPerPage).isEqualTo(d.changesPerPage);
    assertPrefs(a, d, "my", "changeTable", "changesPerPage");
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

GeneralPreferencesInfo (com.google.gerrit.extensions.client.GeneralPreferencesInfo)19 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 Test (org.junit.Test)8 Repository (org.eclipse.jgit.lib.Repository)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 Account (com.google.gerrit.reviewdb.client.Account)3 VersionedAccountPreferences (com.google.gerrit.server.account.VersionedAccountPreferences)3 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)2 HashMap (java.util.HashMap)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RestResponse (com.google.gerrit.acceptance.RestResponse)1 Capable (com.google.gerrit.common.data.Capable)1 MenuItem (com.google.gerrit.extensions.client.MenuItem)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1 Change (com.google.gerrit.reviewdb.client.Change)1