Search in sources :

Example 6 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class AbandonIT method batchAbandonChangeProject.

@Test
public void batchAbandonChangeProject() throws Exception {
    String project1Name = name("Project1");
    String project2Name = name("Project2");
    gApi.projects().create(project1Name);
    gApi.projects().create(project2Name);
    TestRepository<InMemoryRepository> project1 = cloneProject(new Project.NameKey(project1Name));
    TestRepository<InMemoryRepository> project2 = cloneProject(new Project.NameKey(project2Name));
    CurrentUser user = atrScope.get().getUser();
    PushOneCommit.Result a = createChange(project1, "master", "x", "x", "x", "");
    List<ChangeControl> controlA = changeFinder.find(a.getChangeId(), user);
    assertThat(controlA).hasSize(1);
    PushOneCommit.Result b = createChange(project2, "master", "x", "x", "x", "");
    List<ChangeControl> controlB = changeFinder.find(b.getChangeId(), user);
    assertThat(controlB).hasSize(1);
    List<ChangeControl> list = ImmutableList.of(controlA.get(0), controlB.get(0));
    exception.expect(ResourceConflictException.class);
    exception.expectMessage(String.format("Project name \"%s\" doesn't match \"%s\"", project2Name, project1Name));
    changeAbandoner.batchAbandon(batchUpdateFactory, new Project.NameKey(project1Name), user, list);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) CurrentUser(com.google.gerrit.server.CurrentUser) ChangeControl(com.google.gerrit.server.project.ChangeControl) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class DashboardsCollection method parse.

@Override
public DashboardResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException, ConfigInvalidException {
    ProjectControl myCtl = parent.getControl();
    if (id.toString().equals("default")) {
        return DashboardResource.projectDefault(myCtl);
    }
    List<String> parts = Lists.newArrayList(Splitter.on(':').limit(2).split(id.get()));
    if (parts.size() != 2) {
        throw new ResourceNotFoundException(id);
    }
    CurrentUser user = myCtl.getUser();
    String ref = parts.get(0);
    String path = parts.get(1);
    for (ProjectState ps : myCtl.getProjectState().tree()) {
        try {
            return parse(ps.controlFor(user), ref, path, myCtl);
        } catch (AmbiguousObjectException | ConfigInvalidException | IncorrectObjectTypeException e) {
            throw new ResourceNotFoundException(id);
        } catch (ResourceNotFoundException e) {
            continue;
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : AmbiguousObjectException(org.eclipse.jgit.errors.AmbiguousObjectException) CurrentUser(com.google.gerrit.server.CurrentUser) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 8 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class Schema_150_to_151_Test method setUp.

@Before
public void setUp() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    IdentifiedUser user = userFactory.create(userId);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Provider(com.google.inject.Provider) Before(org.junit.Before)

Example 9 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class BatchUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    user = userFactory.create(userId);
    project = new Project.NameKey("test");
    InMemoryRepository inMemoryRepo = repoManager.createRepository(project);
    repo = new TestRepository<>(inMemoryRepo);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) CurrentUser(com.google.gerrit.server.CurrentUser) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) Provider(com.google.inject.Provider) Project(com.google.gerrit.reviewdb.client.Project) Injector(com.google.inject.Injector) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Before(org.junit.Before)

Example 10 with CurrentUser

use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentNotesFormatRealAuthor.

@Test
public void patchLineCommentNotesFormatRealAuthor() throws Exception {
    Change c = newChange();
    CurrentUser ownerAsOtherUser = userFactory.runAs(null, otherUserId, changeOwner);
    ChangeUpdate update = newUpdate(c, ownerAsOtherUser);
    String uuid = "uuid";
    String message = "comment";
    CommentRange range = new CommentRange(1, 1, 2, 1);
    Timestamp time = TimeUtil.nowTs();
    PatchSet.Id psId = c.currentPatchSetId();
    RevId revId = new RevId("abcd1234abcd1234abcd1234abcd1234abcd1234");
    Comment comment = newComment(psId, "file", uuid, range, range.getEndLine(), otherUser, null, time, message, (short) 1, revId.get(), false);
    comment.setRealAuthor(changeOwner.getAccountId());
    update.setPatchSetId(psId);
    update.putComment(Status.PUBLISHED, comment);
    update.commit();
    ChangeNotes notes = newNotes(c);
    try (RevWalk walk = new RevWalk(repo)) {
        ArrayList<Note> notesInTree = Lists.newArrayList(notes.revisionNoteMap.noteMap.iterator());
        Note note = Iterables.getOnlyElement(notesInTree);
        byte[] bytes = walk.getObjectReader().open(note.getData(), Constants.OBJ_BLOB).getBytes();
        String noteString = new String(bytes, UTF_8);
        if (!testJson()) {
            assertThat(noteString).isEqualTo("Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n" + "Patch-set: 1\n" + "File: file\n" + "\n" + "1:1-2:1\n" + ChangeNoteUtil.formatTime(serverIdent, time) + "\n" + "Author: Other Account <2@gerrit>\n" + "Real-author: Change Owner <1@gerrit>\n" + "Unresolved: false\n" + "UUID: uuid\n" + "Bytes: 7\n" + "comment\n" + "\n");
        }
    }
    assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(revId, comment));
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CurrentUser(com.google.gerrit.server.CurrentUser) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ChangeNotesRevWalk(com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk) Timestamp(java.sql.Timestamp) RevId(com.google.gerrit.reviewdb.client.RevId) Note(org.eclipse.jgit.notes.Note) Test(org.junit.Test)

Aggregations

CurrentUser (com.google.gerrit.server.CurrentUser)44 Account (com.google.gerrit.reviewdb.client.Account)14 AuthException (com.google.gerrit.extensions.restapi.AuthException)11 Provider (com.google.inject.Provider)8 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7 Change (com.google.gerrit.reviewdb.client.Change)6 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)6 Project (com.google.gerrit.reviewdb.client.Project)6 RequestContext (com.google.gerrit.server.util.RequestContext)6 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 OrmException (com.google.gwtorm.server.OrmException)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)5 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)5 HashMap (java.util.HashMap)5 LabelType (com.google.gerrit.common.data.LabelType)4 LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)4 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)4 ChangeControl (com.google.gerrit.server.project.ChangeControl)4