Search in sources :

Example 56 with Account

use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.

the class OutgoingEmail method getFromLine.

protected String getFromLine() {
    final Account account = args.accountCache.get(fromId).getAccount();
    final String name = account.getFullName();
    final String email = account.getPreferredEmail();
    StringBuilder f = new StringBuilder();
    if ((name != null && !name.isEmpty()) || (email != null && !email.isEmpty())) {
        f.append("From");
        if (name != null && !name.isEmpty()) {
            f.append(" ").append(name);
        }
        if (email != null && !email.isEmpty()) {
            f.append(" <").append(email).append(">");
        }
        f.append(":\n\n");
    }
    return f.toString();
}
Also used : Account(com.google.gerrit.reviewdb.client.Account)

Example 57 with Account

use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.

the class IdentifiedUserTest method setUp.

@Before
public void setUp() throws Exception {
    final FakeAccountCache accountCache = new FakeAccountCache();
    final Realm mockRealm = new FakeRealm() {

        HashSet<String> emails = new HashSet<>(Arrays.asList(TEST_CASES));

        @Override
        public boolean hasEmailAddress(IdentifiedUser who, String email) {
            return emails.contains(email);
        }

        @Override
        public Set<String> getEmailAddresses(IdentifiedUser who) {
            return emails;
        }
    };
    AbstractModule mod = new AbstractModule() {

        @Override
        protected void configure() {
            bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(config);
            bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
            bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
            bind(AccountCache.class).toInstance(accountCache);
            bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
            bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
            bind(Realm.class).toInstance(mockRealm);
        }
    };
    Injector injector = Guice.createInjector(mod);
    injector.injectMembers(this);
    Account account = new Account(new Account.Id(1), TimeUtil.nowTs());
    Account.Id ownerId = account.getId();
    identifiedUser = identifiedUserFactory.create(ownerId);
    /* Trigger identifiedUser to load the email addresses from mockRealm */
    identifiedUser.getEmailAddresses();
}
Also used : GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Account(com.google.gerrit.reviewdb.client.Account) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) CapabilityControl(com.google.gerrit.server.account.CapabilityControl) AbstractModule(com.google.inject.AbstractModule) AccountCache(com.google.gerrit.server.account.AccountCache) FakeAccountCache(com.google.gerrit.testutil.FakeAccountCache) FakeRealm(com.google.gerrit.server.account.FakeRealm) DisableReverseDnsLookup(com.google.gerrit.server.config.DisableReverseDnsLookup) Injector(com.google.inject.Injector) FakeAccountCache(com.google.gerrit.testutil.FakeAccountCache) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 58 with Account

use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.

the class WatchConfigTest method parseInvalidWatchConfig.

@Test
public void parseInvalidWatchConfig() throws Exception {
    Config cfg = new Config();
    cfg.fromText("[project \"myProject\"]\n" + "  notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n" + "  notify = branch:master [INVALID, NEW_CHANGES]\n" + "[project \"otherProject\"]\n" + "  notify = [NEW_PATCHSETS]\n");
    WatchConfig.parse(new Account.Id(1000000), cfg, this);
    assertThat(validationErrors).hasSize(1);
    assertThat(validationErrors.get(0).getMessage()).isEqualTo("watch.config: Invalid notify type INVALID in project watch of" + " account 1000000 for project myProject: branch:master" + " [INVALID, NEW_CHANGES]");
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Config(org.eclipse.jgit.lib.Config) Test(org.junit.Test)

Example 59 with Account

use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method createAccount.

private Account.Id createAccount(String username, String fullName, String email, boolean active) throws Exception {
    try (ManualRequestContext ctx = oneOffRequestContext.open()) {
        Account.Id id = accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
        if (email != null) {
            accountManager.link(id, AuthRequest.forEmail(email));
        }
        Account a = db.accounts().get(id);
        a.setFullName(fullName);
        a.setPreferredEmail(email);
        a.setActive(active);
        db.accounts().update(ImmutableList.of(a));
        accountCache.evict(id);
        return id;
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ManualRequestContext(com.google.gerrit.server.util.ManualRequestContext)

Example 60 with Account

use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method setUpDatabase.

protected void setUpDatabase() throws Exception {
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    Account userAccount = db.accounts().get(userId);
    String email = "user@example.com";
    externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email));
    userAccount.setPreferredEmail(email);
    db.accounts().update(ImmutableList.of(userAccount));
    user = userFactory.create(userId);
    requestContext.setContext(newRequestContext(userAccount.getId()));
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Aggregations

Account (com.google.gerrit.reviewdb.client.Account)75 ArrayList (java.util.ArrayList)13 OrmException (com.google.gwtorm.server.OrmException)11 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)10 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)8 HashSet (java.util.HashSet)8 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)7 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)7 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7 PersonIdent (org.eclipse.jgit.lib.PersonIdent)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)6 CurrentUser (com.google.gerrit.server.CurrentUser)6 Ref (org.eclipse.jgit.lib.Ref)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)4