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));
}
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);
}
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);
}
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());
}
}
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());
}
}
Aggregations