Search in sources :

Example 41 with IdentifiedUser

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

the class UniversalGroupBackendTest method otherMemberships.

@Test
public void otherMemberships() {
    final AccountGroup.UUID handled = new AccountGroup.UUID("handled");
    final AccountGroup.UUID notHandled = new AccountGroup.UUID("not handled");
    final IdentifiedUser member = createNiceMock(IdentifiedUser.class);
    final IdentifiedUser notMember = createNiceMock(IdentifiedUser.class);
    GroupBackend backend = createMock(GroupBackend.class);
    expect(backend.handles(handled)).andStubReturn(true);
    expect(backend.handles(not(eq(handled)))).andStubReturn(false);
    expect(backend.membershipsOf(anyObject(IdentifiedUser.class))).andStubAnswer(new IAnswer<GroupMembership>() {

        @Override
        public GroupMembership answer() throws Throwable {
            Object[] args = getCurrentArguments();
            GroupMembership membership = createMock(GroupMembership.class);
            expect(membership.contains(eq(handled))).andStubReturn(args[0] == member);
            expect(membership.contains(not(eq(notHandled)))).andStubReturn(false);
            replay(membership);
            return membership;
        }
    });
    replay(member, notMember, backend);
    backends = new DynamicSet<>();
    backends.add(backend);
    backend = new UniversalGroupBackend(backends);
    GroupMembership checker = backend.membershipsOf(member);
    assertFalse(checker.contains(REGISTERED_USERS));
    assertFalse(checker.contains(OTHER_UUID));
    assertTrue(checker.contains(handled));
    assertFalse(checker.contains(notHandled));
    checker = backend.membershipsOf(notMember);
    assertFalse(checker.contains(handled));
    assertFalse(checker.contains(notHandled));
}
Also used : SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) UUID(com.google.gerrit.reviewdb.client.AccountGroup.UUID) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) UUID(com.google.gerrit.reviewdb.client.AccountGroup.UUID) Test(org.junit.Test)

Example 42 with IdentifiedUser

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

the class PRED_current_user_2 method createUser.

public Term createUser(Prolog engine, Term key) {
    if (!(key instanceof StructureTerm) || key.arity() != 1 || !((StructureTerm) key).functor().equals(user)) {
        throw new IllegalTypeException(this, 1, "user(int)", key);
    }
    Term idTerm = key.arg(0);
    CurrentUser user;
    if (idTerm instanceof IntegerTerm) {
        Map<Account.Id, IdentifiedUser> cache = StoredValues.USERS.get(engine);
        Account.Id accountId = new Account.Id(((IntegerTerm) idTerm).intValue());
        user = cache.get(accountId);
        if (user == null) {
            IdentifiedUser.GenericFactory userFactory = userFactory(engine);
            IdentifiedUser who = userFactory.create(accountId);
            cache.put(accountId, who);
            user = who;
        }
    } else if (idTerm.equals(anonymous)) {
        user = StoredValues.ANONYMOUS_USER.get(engine);
    } else {
        throw new IllegalTypeException(this, 1, "user(int)", key);
    }
    return new JavaObjectTerm(user);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) IllegalTypeException(com.googlecode.prolog_cafe.exceptions.IllegalTypeException) CurrentUser(com.google.gerrit.server.CurrentUser) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 43 with IdentifiedUser

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

the class BatchProgramModule method configure.

@SuppressWarnings("rawtypes")
@Override
protected void configure() {
    install(reviewDbModule);
    install(new DiffExecutorModule());
    install(new ReceiveCommitsExecutorModule());
    install(BatchUpdate.module());
    install(PatchListCacheImpl.module());
    // Plugins are not loaded and we're just running through each change
    // once, so don't worry about cache removal.
    bind(new TypeLiteral<DynamicSet<CacheRemovalListener>>() {
    }).toInstance(DynamicSet.<CacheRemovalListener>emptySet());
    bind(new TypeLiteral<DynamicMap<Cache<?, ?>>>() {
    }).toInstance(DynamicMap.<Cache<?, ?>>emptyMap());
    bind(new TypeLiteral<List<CommentLinkInfo>>() {
    }).toProvider(CommentLinkProvider.class).in(SINGLETON);
    bind(new TypeLiteral<DynamicMap<ChangeQueryProcessor.ChangeAttributeFactory>>() {
    }).toInstance(DynamicMap.<ChangeQueryProcessor.ChangeAttributeFactory>emptyMap());
    bind(String.class).annotatedWith(CanonicalWebUrl.class).toProvider(CanonicalWebUrlProvider.class);
    bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toProvider(DisableReverseDnsLookupProvider.class).in(SINGLETON);
    bind(Realm.class).to(FakeRealm.class);
    bind(IdentifiedUser.class).toProvider(Providers.<IdentifiedUser>of(null));
    bind(ReplacePatchSetSender.Factory.class).toProvider(Providers.<ReplacePatchSetSender.Factory>of(null));
    bind(CurrentUser.class).to(IdentifiedUser.class);
    factory(MergeUtil.Factory.class);
    factory(PatchSetInserter.Factory.class);
    factory(RebaseChangeOp.Factory.class);
    // As Reindex is a batch program, don't assume the index is available for
    // the change cache.
    bind(SearchingChangeCacheImpl.class).toProvider(Providers.<SearchingChangeCacheImpl>of(null));
    bind(new TypeLiteral<ImmutableSet<GroupReference>>() {
    }).annotatedWith(AdministrateServerGroups.class).toInstance(ImmutableSet.<GroupReference>of());
    bind(new TypeLiteral<Set<AccountGroup.UUID>>() {
    }).annotatedWith(GitUploadPackGroups.class).toInstance(Collections.<AccountGroup.UUID>emptySet());
    bind(new TypeLiteral<Set<AccountGroup.UUID>>() {
    }).annotatedWith(GitReceivePackGroups.class).toInstance(Collections.<AccountGroup.UUID>emptySet());
    install(new BatchGitModule());
    install(new DefaultPermissionBackendModule());
    install(new DefaultCacheFactory.Module());
    install(new ExternalIdModule());
    install(new GroupModule());
    install(new NoteDbModule(cfg));
    install(new PrologModule());
    install(AccountByEmailCacheImpl.module());
    install(AccountCacheImpl.module());
    install(GroupCacheImpl.module());
    install(GroupIncludeCacheImpl.module());
    install(ProjectCacheImpl.module());
    install(SectionSortCache.module());
    install(ChangeKindCacheImpl.module());
    install(MergeabilityCacheImpl.module());
    install(TagCache.module());
    factory(CapabilityCollection.Factory.class);
    factory(CapabilityControl.Factory.class);
    factory(ChangeData.Factory.class);
    factory(ProjectState.Factory.class);
    bind(ChangeJson.Factory.class).toProvider(Providers.<ChangeJson.Factory>of(null));
    bind(AccountVisibility.class).toProvider(AccountVisibilityProvider.class).in(SINGLETON);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) CurrentUser(com.google.gerrit.server.CurrentUser) CapabilityControl(com.google.gerrit.server.account.CapabilityControl) NoteDbModule(com.google.gerrit.server.notedb.NoteDbModule) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) AdministrateServerGroups(com.google.gerrit.server.config.AdministrateServerGroups) GroupModule(com.google.gerrit.server.group.GroupModule) CacheRemovalListener(com.google.gerrit.server.cache.CacheRemovalListener) TypeLiteral(com.google.inject.TypeLiteral) ImmutableSet(com.google.common.collect.ImmutableSet) GitUploadPackGroups(com.google.gerrit.server.config.GitUploadPackGroups) MergeUtil(com.google.gerrit.server.git.MergeUtil) List(java.util.List) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) CommentLinkProvider(com.google.gerrit.server.project.CommentLinkProvider) SearchingChangeCacheImpl(com.google.gerrit.server.git.SearchingChangeCacheImpl) ChangeJson(com.google.gerrit.server.change.ChangeJson) GitReceivePackGroups(com.google.gerrit.server.config.GitReceivePackGroups) DisableReverseDnsLookupProvider(com.google.gerrit.server.config.DisableReverseDnsLookupProvider) PrologModule(com.google.gerrit.rules.PrologModule) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) ChangeQueryProcessor(com.google.gerrit.server.query.change.ChangeQueryProcessor) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) RebaseChangeOp(com.google.gerrit.server.change.RebaseChangeOp) CapabilityCollection(com.google.gerrit.server.account.CapabilityCollection) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ChangeData(com.google.gerrit.server.query.change.ChangeData) AccountVisibilityProvider(com.google.gerrit.server.account.AccountVisibilityProvider) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) ExternalIdModule(com.google.gerrit.server.account.externalids.ExternalIdModule) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) ProjectState(com.google.gerrit.server.project.ProjectState) ReceiveCommitsExecutorModule(com.google.gerrit.server.git.ReceiveCommitsExecutorModule) ReplacePatchSetSender(com.google.gerrit.server.mail.send.ReplacePatchSetSender) TagCache(com.google.gerrit.server.git.TagCache) SectionSortCache(com.google.gerrit.server.project.SectionSortCache) Cache(com.google.common.cache.Cache)

Example 44 with IdentifiedUser

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

the class LsUserRefs method run.

@Override
protected void run() throws Failure {
    Account userAccount;
    try {
        userAccount = accountResolver.find(db, userName);
    } catch (OrmException e) {
        throw die(e);
    }
    if (userAccount == null) {
        stdout.print("No single user could be found when searching for: " + userName + '\n');
        stdout.flush();
        return;
    }
    IdentifiedUser user = userFactory.create(userAccount.getId());
    ProjectControl userProjectControl = projectControl.forUser(user);
    try (Repository repo = repoManager.openRepository(userProjectControl.getProject().getNameKey())) {
        try {
            Map<String, Ref> refsMap = new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, repo, userProjectControl, db, true).filter(repo.getRefDatabase().getRefs(ALL), false);
            for (final String ref : refsMap.keySet()) {
                if (!onlyRefsHeads || ref.startsWith(RefNames.REFS_HEADS)) {
                    stdout.println(ref);
                }
            }
        } catch (IOException e) {
            throw new Failure(1, "fatal: Error reading refs: '" + projectControl.getProject().getNameKey(), e);
        }
    } catch (RepositoryNotFoundException e) {
        throw die("'" + projectControl.getProject().getNameKey() + "': not a git archive");
    } catch (IOException e) {
        throw die("Error opening: '" + projectControl.getProject().getNameKey());
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) OrmException(com.google.gwtorm.server.OrmException) VisibleRefFilter(com.google.gerrit.server.git.VisibleRefFilter) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 45 with IdentifiedUser

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

the class PutAssignee method applyImpl.

@Override
protected AccountInfo applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, AssigneeInput input) throws RestApiException, UpdateException, OrmException, IOException, PermissionBackendException {
    rsrc.permissions().check(ChangePermission.EDIT_ASSIGNEE);
    input.assignee = Strings.nullToEmpty(input.assignee).trim();
    if (input.assignee.isEmpty()) {
        throw new BadRequestException("missing assignee field");
    }
    IdentifiedUser assignee = accounts.parse(input.assignee);
    if (!assignee.getAccount().isActive()) {
        throw new UnprocessableEntityException(input.assignee + " is not active");
    }
    try {
        rsrc.permissions().database(db).user(assignee).check(ChangePermission.READ);
    } catch (AuthException e) {
        throw new AuthException("read not permitted for " + input.assignee);
    }
    try (BatchUpdate bu = updateFactory.create(db.get(), rsrc.getChange().getProject(), rsrc.getControl().getUser(), TimeUtil.nowTs())) {
        SetAssigneeOp op = assigneeFactory.create(assignee);
        bu.addOp(rsrc.getId(), op);
        PostReviewers.Addition reviewersAddition = addAssigneeAsCC(rsrc, input.assignee);
        bu.addOp(rsrc.getId(), reviewersAddition.op);
        bu.execute();
        return accountLoaderFactory.create(true).fillOne(assignee.getAccountId());
    }
}
Also used : Addition(com.google.gerrit.server.change.PostReviewers.Addition) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Aggregations

IdentifiedUser (com.google.gerrit.server.IdentifiedUser)48 AuthException (com.google.gerrit.extensions.restapi.AuthException)12 Account (com.google.gerrit.reviewdb.client.Account)10 Change (com.google.gerrit.reviewdb.client.Change)10 CurrentUser (com.google.gerrit.server.CurrentUser)8 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)7 Project (com.google.gerrit.reviewdb.client.Project)7 ChangeControl (com.google.gerrit.server.project.ChangeControl)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)5 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)5 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)5 OrmException (com.google.gwtorm.server.OrmException)5 Ref (org.eclipse.jgit.lib.Ref)5 Repository (org.eclipse.jgit.lib.Repository)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4