use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class BaseCommand method handleError.
private int handleError(Throwable e) {
if ((e.getClass() == IOException.class && "Pipe closed".equals(e.getMessage())) || //
(e.getClass() == SshException.class && "Already closed".equals(e.getMessage())) || //
e.getClass() == InterruptedIOException.class) {
//
return 127;
}
if (!(e instanceof UnloggedFailure)) {
final StringBuilder m = new StringBuilder();
m.append("Internal server error");
if (user.isIdentifiedUser()) {
final IdentifiedUser u = user.asIdentifiedUser();
m.append(" (user ");
m.append(u.getUserName().orElse(null));
m.append(" account ");
m.append(u.getAccountId());
m.append(")");
}
m.append(" during ");
m.append(context.getCommandLine());
logCauseIfRelevant(e, m);
}
if (e instanceof Failure) {
final Failure f = (Failure) e;
try {
err.write((f.getMessage() + "\n").getBytes(ENC));
err.flush();
} catch (IOException e2) {
// Ignored
} catch (RuntimeException e2) {
logger.atWarning().withCause(e2).log("Cannot send failure message to client");
}
return f.exitCode;
}
try {
err.write("fatal: internal server error\n".getBytes(ENC));
err.flush();
} catch (IOException e2) {
// Ignored
} catch (RuntimeException e2) {
logger.atWarning().withCause(e2).log("Cannot send internal server error message to client");
}
return 128;
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class EqualsLabelPredicate method match.
protected boolean match(ChangeData cd, short value, Account.Id approver) {
if (value != expVal) {
return false;
}
if (account != null) {
// case when account in query is numeric
if (!account.equals(approver) && !isMagicUser()) {
return false;
}
// case when account in query = owner
if (account.equals(ChangeQueryBuilder.OWNER_ACCOUNT_ID) && !cd.change().getOwner().equals(approver)) {
return false;
}
// case when account in query = non_uploader
if (account.equals(ChangeQueryBuilder.NON_UPLOADER_ACCOUNT_ID) && cd.currentPatchSet().uploader().equals(approver)) {
return false;
}
}
IdentifiedUser reviewer = userFactory.create(approver);
if (group != null && !reviewer.getEffectiveGroups().contains(group)) {
return false;
}
// Check the user has 'READ' permission.
try {
PermissionBackend.ForChange perm = permissionBackend.absentUser(approver).change(cd);
if (!projectCache.get(cd.project()).map(ProjectState::statePermitsRead).orElse(false)) {
return false;
}
perm.check(ChangePermission.READ);
return true;
} catch (PermissionBackendException | AuthException e) {
return false;
}
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class DeleteSshKey method apply.
@Override
public Response<?> apply(AccountResource.SshKey rsrc, Input input) throws AuthException, RepositoryNotFoundException, IOException, ConfigInvalidException, PermissionBackendException {
if (!self.get().hasSameAccountId(rsrc.getUser())) {
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
}
IdentifiedUser user = rsrc.getUser();
authorizedKeys.deleteKey(user.getAccountId(), rsrc.getSshKey().seq());
try {
deleteKeySenderFactory.create(user, rsrc.getSshKey()).send();
} catch (EmailException e) {
logger.atSevere().withCause(e).log("Cannot send SSH key deletion message to %s", user.getAccount().preferredEmail());
}
user.getUserName().ifPresent(sshKeyCache::evict);
return Response.none();
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class UploaderinPredicate method match.
@Override
public boolean match(ChangeData cd) {
PatchSet latestPatchSet = cd.currentPatchSet();
if (latestPatchSet == null) {
return false;
}
IdentifiedUser uploader = userFactory.create(latestPatchSet.uploader());
return uploader.getEffectiveGroups().contains(uuid);
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class PutAssignee method apply.
@Override
public Response<AccountInfo> apply(ChangeResource rsrc, AssigneeInput input) throws RestApiException, UpdateException, IOException, PermissionBackendException, ConfigInvalidException {
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 = accountResolver.resolve(input.assignee).asUniqueUser();
try {
permissionBackend.absentUser(assignee.getAccountId()).change(rsrc.getNotes()).check(ChangePermission.READ);
} catch (AuthException e) {
throw new AuthException("read not permitted for " + input.assignee, e);
}
try (BatchUpdate bu = updateFactory.create(rsrc.getChange().getProject(), rsrc.getUser(), TimeUtil.now())) {
SetAssigneeOp op = assigneeFactory.create(assignee);
bu.addOp(rsrc.getId(), op);
ReviewerSet currentReviewers = approvalsUtil.getReviewers(rsrc.getNotes());
if (!currentReviewers.all().contains(assignee.getAccountId())) {
ReviewerModification reviewersAddition = addAssigneeAsCC(rsrc, input.assignee);
reviewersAddition.op.suppressEmail();
bu.addOp(rsrc.getId(), reviewersAddition.op);
}
bu.execute();
return Response.ok(accountLoaderFactory.create(true).fillOne(assignee.getAccountId()));
}
}
Aggregations