Search in sources :

Example 76 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AccountIT method self.

@Test
public void self() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        AccountInfo info = gApi.accounts().self().get();
        assertUser(info, admin);
        info = gApi.accounts().id("self").get();
        assertUser(info, admin);
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 77 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AccountIT method createByAccountCreator.

private Account.Id createByAccountCreator(int expectedAccountReindexCalls) throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String name = "foo";
        TestAccount foo = accountCreator.create(name);
        AccountInfo info = gApi.accounts().id(foo.id().get()).get();
        assertThat(info.username).isEqualTo(name);
        assertThat(info.name).isEqualTo(name);
        accountIndexedCounter.assertReindexOf(foo, expectedAccountReindexCalls);
        assertUserBranch(foo.id(), name, null);
        return foo.id();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 78 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AccountIT method putStatus.

@Test
public void putStatus() throws Exception {
    List<String> statuses = ImmutableList.of("OOO", "Busy");
    AccountInfo info;
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        for (String status : statuses) {
            gApi.accounts().self().setStatus(status);
            info = gApi.accounts().self().get();
            assertUser(info, admin, status);
            accountIndexedCounter.assertReindexOf(admin);
        }
        gApi.accounts().self().setStatus(null);
        info = gApi.accounts().self().get();
        assertUser(info, admin);
        accountIndexedCounter.assertReindexOf(admin);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 79 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class ChangeJson method checkOnly.

private ChangeInfo checkOnly(ChangeData cd) {
    ChangeNotes notes;
    try {
        notes = cd.notes();
    } catch (StorageException e) {
        String msg = "Error loading change";
        logger.atWarning().withCause(e).log(msg + " %s", cd.getId());
        ChangeInfo info = new ChangeInfo();
        info._number = cd.getId().get();
        ProblemInfo p = new ProblemInfo();
        p.message = msg;
        info.problems = Lists.newArrayList(p);
        return info;
    }
    ConsistencyChecker.Result result = checkerProvider.get().check(notes, fix);
    ChangeInfo info = new ChangeInfo();
    Change c = result.change();
    if (c != null) {
        info.project = c.getProject().get();
        info.branch = c.getDest().shortName();
        info.topic = c.getTopic();
        info.changeId = c.getKey().get();
        info.subject = c.getSubject();
        info.status = c.getStatus().asChangeStatus();
        info.owner = new AccountInfo(c.getOwner().get());
        info.setCreated(c.getCreatedOn());
        info.setUpdated(c.getLastUpdatedOn());
        info._number = c.getId().get();
        info.problems = result.problems();
        info.isPrivate = c.isPrivate() ? true : null;
        info.workInProgress = c.isWorkInProgress() ? true : null;
        info.hasReviewStarted = c.hasReviewStarted();
        finish(info);
    } else {
        info._number = result.id().get();
        info.problems = result.problems();
    }
    return info;
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ProblemInfo(com.google.gerrit.extensions.common.ProblemInfo) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 80 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class ChangeJson method removableReviewers.

private Collection<AccountInfo> removableReviewers(ChangeData cd, ChangeInfo out) throws PermissionBackendException {
    // Although this is called removableReviewers, this method also determines
    // which CCs are removable.
    // 
    // For reviewers, we need to look at each approval, because the reviewer
    // should only be considered removable if *all* of their approvals can be
    // removed. First, add all reviewers with *any* removable approval to the
    // "removable" set. Along the way, if we encounter a non-removable approval,
    // add the reviewer to the "fixed" set. Before we return, remove all members
    // of "fixed" from "removable", because not all of their approvals can be
    // removed.
    Collection<LabelInfo> labels = out.labels.values();
    Set<Account.Id> fixed = Sets.newHashSetWithExpectedSize(labels.size());
    Set<Account.Id> removable = new HashSet<>();
    // Add all reviewers, which will later be removed if they are in the "fixed" set.
    removable.addAll(out.reviewers.getOrDefault(ReviewerState.REVIEWER, Collections.emptySet()).stream().filter(a -> a._accountId != null).map(a -> Account.id(a._accountId)).collect(Collectors.toSet()));
    // Check if the user has the permission to remove a reviewer. This means we can bypass the
    // testRemoveReviewer check for a specific reviewer in the loop saving potentially many
    // permission checks.
    boolean canRemoveAnyReviewer = permissionBackend.user(userProvider.get()).change(cd).test(ChangePermission.REMOVE_REVIEWER);
    for (LabelInfo label : labels) {
        if (label.all == null) {
            continue;
        }
        for (ApprovalInfo ai : label.all) {
            Account.Id id = Account.id(ai._accountId);
            if (!canRemoveAnyReviewer && !removeReviewerControl.testRemoveReviewer(cd, userProvider.get(), id, MoreObjects.firstNonNull(ai.value, 0))) {
                fixed.add(id);
            }
        }
    }
    // CCs are simpler than reviewers. They are removable if the ChangeControl
    // would permit a non-negative approval by that account to be removed, in
    // which case add them to removable. We don't need to add unremovable CCs to
    // "fixed" because we only visit each CC once here.
    Collection<AccountInfo> ccs = out.reviewers.get(ReviewerState.CC);
    if (ccs != null) {
        for (AccountInfo ai : ccs) {
            if (ai._accountId != null) {
                Account.Id id = Account.id(ai._accountId);
                if (canRemoveAnyReviewer || removeReviewerControl.testRemoveReviewer(cd, userProvider.get(), id, 0)) {
                    removable.add(id);
                }
            }
        }
    }
    // Subtract any reviewers with non-removable approvals from the "removable"
    // set. This also subtracts any CCs that for some reason also hold
    // unremovable approvals.
    removable.removeAll(fixed);
    List<AccountInfo> result = Lists.newArrayListWithCapacity(removable.size());
    for (Account.Id id : removable) {
        result.add(accountLoader.get(id));
    }
    // Reviewers added by email are always removable
    for (Collection<AccountInfo> infos : out.reviewers.values()) {
        for (AccountInfo info : infos) {
            if (info._accountId == null) {
                result.add(info);
            }
        }
    }
    return result;
}
Also used : AttentionSetUtil.additionsOnly(com.google.gerrit.server.util.AttentionSetUtil.additionsOnly) REVIEWER_UPDATES(com.google.gerrit.extensions.client.ListChangesOption.REVIEWER_UPDATES) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ListMultimap(com.google.common.collect.ListMultimap) TrackingIdInfo(com.google.gerrit.extensions.common.TrackingIdInfo) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) ReviewerSet(com.google.gerrit.server.ReviewerSet) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Config(org.eclipse.jgit.lib.Config) Map(java.util.Map) LABELS(com.google.gerrit.extensions.client.ListChangesOption.LABELS) AttentionSetUtil.removalsOnly(com.google.gerrit.server.util.AttentionSetUtil.removalsOnly) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Timer0(com.google.gerrit.metrics.Timer0) Set(java.util.Set) ReviewerStatusUpdate(com.google.gerrit.server.ReviewerStatusUpdate) SubmitRecord(com.google.gerrit.entities.SubmitRecord) SUBMITTABLE(com.google.gerrit.extensions.client.ListChangesOption.SUBMITTABLE) SubmitTypeRecord(com.google.gerrit.entities.SubmitTypeRecord) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) DETAILED_ACCOUNTS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_ACCOUNTS) MetricMaker(com.google.gerrit.metrics.MetricMaker) FluentLogger(com.google.common.flogger.FluentLogger) Joiner(com.google.common.base.Joiner) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Singleton(com.google.inject.Singleton) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ArrayList(java.util.ArrayList) CURRENT_COMMIT(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT) ChangeMessage(com.google.gerrit.entities.ChangeMessage) Lists(com.google.common.collect.Lists) Description(com.google.gerrit.metrics.Description) PatchSet(com.google.gerrit.entities.PatchSet) Address(com.google.gerrit.entities.Address) RefState(com.google.gerrit.index.RefState) CURRENT_ACTIONS(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_ACTIONS) StorageException(com.google.gerrit.exceptions.StorageException) Units(com.google.gerrit.metrics.Description.Units) MoreObjects(com.google.common.base.MoreObjects) Throwables(com.google.common.base.Throwables) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) ReviewerUpdateInfo(com.google.gerrit.extensions.common.ReviewerUpdateInfo) SubmitRuleOptions(com.google.gerrit.server.project.SubmitRuleOptions) LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) Project(com.google.gerrit.entities.Project) TrackingFooters(com.google.gerrit.server.config.TrackingFooters) ReviewerByEmailSet(com.google.gerrit.server.ReviewerByEmailSet) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) ALL_REVISIONS(com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS) Inject(com.google.inject.Inject) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Assisted(com.google.inject.assistedinject.Assisted) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) RemoveReviewerControl(com.google.gerrit.server.project.RemoveReviewerControl) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) GpgException(com.google.gerrit.server.GpgException) REVIEWED(com.google.gerrit.extensions.client.ListChangesOption.REVIEWED) RefNames(com.google.gerrit.entities.RefNames) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) CHECK(com.google.gerrit.extensions.client.ListChangesOption.CHECK) ChangedLines(com.google.gerrit.server.query.change.ChangeData.ChangedLines) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Url(com.google.gerrit.extensions.restapi.Url) Optional(java.util.Optional) AttentionSetUtil(com.google.gerrit.server.util.AttentionSetUtil) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) AccountLoader(com.google.gerrit.server.account.AccountLoader) FixInput(com.google.gerrit.extensions.api.changes.FixInput) ChangePermission(com.google.gerrit.server.permissions.ChangePermission) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) SKIP_DIFFSTAT(com.google.gerrit.extensions.client.ListChangesOption.SKIP_DIFFSTAT) ChangeMessagesUtil.createChangeMessageInfo(com.google.gerrit.server.ChangeMessagesUtil.createChangeMessageInfo) Change(com.google.gerrit.entities.Change) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) PluginDefinedInfo(com.google.gerrit.extensions.common.PluginDefinedInfo) TRACKING_IDS(com.google.gerrit.extensions.client.ListChangesOption.TRACKING_IDS) ProblemInfo(com.google.gerrit.extensions.common.ProblemInfo) CurrentUser(com.google.gerrit.server.CurrentUser) QueryResult(com.google.gerrit.index.query.QueryResult) Status(com.google.gerrit.entities.SubmitRecord.Status) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) AccountInfoComparator(com.google.gerrit.server.account.AccountInfoComparator) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CHANGE_ACTIONS(com.google.gerrit.extensions.client.ListChangesOption.CHANGE_ACTIONS) Maps(com.google.common.collect.Maps) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeField(com.google.gerrit.server.index.change.ChangeField) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) SUBMIT_REQUIREMENTS(com.google.gerrit.extensions.client.ListChangesOption.SUBMIT_REQUIREMENTS) COMMIT_FOOTERS(com.google.gerrit.extensions.client.ListChangesOption.COMMIT_FOOTERS) ALL_COMMITS(com.google.gerrit.extensions.client.ListChangesOption.ALL_COMMITS) Collections(java.util.Collections) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) Account(com.google.gerrit.entities.Account) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) HashSet(java.util.HashSet)

Aggregations

AccountInfo (com.google.gerrit.extensions.common.AccountInfo)112 Test (org.junit.Test)74 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)39 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)29 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)23 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)20 Account (com.google.gerrit.entities.Account)19 ArrayList (java.util.ArrayList)18 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)17 TestAccount (com.google.gerrit.acceptance.TestAccount)16 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)15 Message (com.google.gerrit.testing.FakeEmailSender.Message)15 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)14 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)13 Collection (java.util.Collection)12 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 HashMap (java.util.HashMap)10