Search in sources :

Example 81 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class LabelNormalizerTest method save.

private void save(ProjectConfig pc) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(pc.getProject().getNameKey(), user)) {
        pc.commit(md);
        projectCache.evictAndReindex(pc.getProject().getNameKey());
    }
}
Also used : MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 82 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method userQuery.

@GerritConfig(name = "accounts.visibility", value = "NONE")
@Test
public void userQuery() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChangeForBranch(repo, "stable"));
    Account.Id anotherUserId = accountManager.authenticate(authRequestFactory.createForUser("anotheruser")).getAccountId();
    String queryListText = "query1\tproject:repo\n" + "query2\tproject:repo status:open\n" + "query3\tproject:repo branch:stable\n" + "query4\tproject:repo branch:other";
    String anotherQueryListText = "query5\tproject:repo\n" + "query6\tproject:repo status:merged\n" + "query7\tproject:repo branch:stable\n" + "query8\tproject:repo branch:other";
    try (TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsersName);
        MetaDataUpdate anotherMd = metaDataUpdateFactory.create(allUsersName)) {
        VersionedAccountQueries queries = VersionedAccountQueries.forUser(userId);
        queries.load(md);
        queries.setQueryList(queryListText);
        queries.commit(md);
        VersionedAccountQueries anotherQueries = VersionedAccountQueries.forUser(anotherUserId);
        anotherQueries.load(anotherMd);
        anotherQueries.setQueryList(anotherQueryListText);
        anotherQueries.commit(anotherMd);
    }
    assertThatQueryException("query:foo").hasMessageThat().isEqualTo("Unknown named query: foo");
    assertThatQueryException("query:query1,user=" + anotherUserId).hasMessageThat().isEqualTo("Unknown named query: query1");
    assertThatQueryException("query:query1,user=test").hasMessageThat().isEqualTo("Account 'test' not found");
    requestContext.setContext(newRequestContext(anotherUserId));
    // account 1000000 is not visible to 'anotheruser' as they are not an admin
    assertThatQueryException("query:query1,user=" + userId).hasMessageThat().isEqualTo("Account '1000000' not found");
    requestContext.setContext(newRequestContext(userId));
    assertQuery("query:query1", change2, change1);
    assertQuery("query:query2", change2, change1);
    assertQuery("query:name=query5,user=" + anotherUserId, change2, change1);
    assertQuery("query:user=" + anotherUserId + ",name=query6");
    gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(change1.getChangeId()).current().submit();
    assertQuery("query:query2", change2);
    assertQuery("query:query3", change2);
    assertQuery("query:query4");
    assertQuery("query:query6,user=" + anotherUserId, change1);
    assertQuery("query:user=" + anotherUserId + ",query7", change2);
    assertQuery("query:query8,user=" + anotherUserId);
}
Also used : Account(com.google.gerrit.entities.Account) TestRepository(org.eclipse.jgit.junit.TestRepository) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) VersionedAccountQueries(com.google.gerrit.server.account.VersionedAccountQueries) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Example 83 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method reindex.

// reindex permissions are tested by {@link AccountIT#reindexPermissions}
@Test
public void reindex() throws Exception {
    AccountInfo user1 = newAccountWithFullName("tester", "Test Usre");
    // update account without reindex so that account index is stale
    Account.Id accountId = Account.id(user1._accountId);
    String newName = "Test User";
    try (Repository repo = repoManager.openRepository(allUsers)) {
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, repo);
        PersonIdent ident = serverIdent.get();
        md.getCommitBuilder().setAuthor(ident);
        md.getCommitBuilder().setCommitter(ident);
        new AccountConfig(accountId, allUsers, repo).load().setAccountDelta(AccountDelta.builder().setFullName(newName).build()).commit(md);
    }
    // Querying for the account here will not result in a stale document because
    // we load AccountStates from the cache after reading documents from the index
    // which means we always read fresh data when matching.
    // 
    // Reindex document
    gApi.accounts().id(user1.username).index();
    assertQuery("name:" + quote(user1.name));
    assertQuery("name:" + quote(newName), user1);
}
Also used : Account(com.google.gerrit.entities.Account) Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AccountConfig(com.google.gerrit.server.account.AccountConfig) Test(org.junit.Test)

Example 84 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method grant.

protected void grant(Project.NameKey project, String ref, String permission, boolean force, AccountGroup.UUID groupUUID) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        md.setMessage(String.format("Grant %s on %s", permission, ref));
        ProjectConfig config = projectConfigFactory.read(md);
        config.upsertAccessSection(ref, s -> {
            Permission.Builder p = s.upsertPermission(permission);
            PermissionRule.Builder rule = PermissionRule.builder(GroupReference.create(groupUUID, groupUUID.get())).setForce(force);
            p.add(rule);
        });
        config.commit(md);
        projectCache.evictAndReindex(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) PermissionRule(com.google.gerrit.entities.PermissionRule) Permission(com.google.gerrit.entities.Permission) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Aggregations

MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)84 Test (org.junit.Test)39 Repository (org.eclipse.jgit.lib.Repository)36 ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)28 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)22 TestRepository (org.eclipse.jgit.junit.TestRepository)17 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)15 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)15 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 Account (com.google.gerrit.entities.Account)13 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)12 PersonIdent (org.eclipse.jgit.lib.PersonIdent)11 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 Project (com.google.gerrit.entities.Project)6 LightweightPluginDaemonTest (com.google.gerrit.acceptance.LightweightPluginDaemonTest)5 TestAccount (com.google.gerrit.acceptance.TestAccount)5 AccessSection (com.google.gerrit.entities.AccessSection)5 GroupReference (com.google.gerrit.entities.GroupReference)5 LabelType (com.google.gerrit.entities.LabelType)5