use of com.google.gerrit.extensions.restapi.AuthException in project gerrit by GerritCodeReview.
the class ApprovalsUtil method checkApprovals.
private static void checkApprovals(Map<String, Short> approvals, ChangeControl changeCtl) throws AuthException {
for (Map.Entry<String, Short> vote : approvals.entrySet()) {
String name = vote.getKey();
Short value = vote.getValue();
PermissionRange range = changeCtl.getRange(Permission.forLabel(name));
if (range == null || !range.contains(value)) {
throw new AuthException(String.format("applying label \"%s\": %d is restricted", name, value));
}
}
}
use of com.google.gerrit.extensions.restapi.AuthException in project gerrit by GerritCodeReview.
the class PostPrivate method applyImpl.
@Override
public Response<String> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input) throws RestApiException, UpdateException {
if (!canSetPrivate(rsrc)) {
throw new AuthException("not allowed to mark private");
}
if (rsrc.getChange().isPrivate()) {
return Response.ok("");
}
ChangeControl control = rsrc.getControl();
SetPrivateOp op = new SetPrivateOp(cmUtil, true, input);
try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
u.addOp(control.getId(), op).execute();
}
return Response.created("");
}
use of com.google.gerrit.extensions.restapi.AuthException in project gerrit by GerritCodeReview.
the class DeletePrivate method applyImpl.
@Override
protected Response<String> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input) throws RestApiException, UpdateException {
if (!canDeletePrivate(rsrc)) {
throw new AuthException("not allowed to unmark private");
}
if (!rsrc.getChange().isPrivate()) {
throw new ResourceConflictException("change is not private");
}
ChangeControl control = rsrc.getControl();
SetPrivateOp op = new SetPrivateOp(cmUtil, false, input);
try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
u.addOp(control.getId(), op).execute();
}
return Response.none();
}
use of com.google.gerrit.extensions.restapi.AuthException in project gerrit by GerritCodeReview.
the class ListChangeDrafts method apply.
@Override
public Map<String, List<CommentInfo>> apply(ChangeResource rsrc) throws AuthException, OrmException {
if (!rsrc.getControl().getUser().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getControl());
List<Comment> drafts = commentsUtil.draftByChangeAuthor(db.get(), cd.notes(), rsrc.getControl().getUser().getAccountId());
return commentJson.get().setFillAccounts(false).setFillPatchSet(true).newCommentFormatter().format(drafts);
}
use of com.google.gerrit.extensions.restapi.AuthException in project gerrit by GerritCodeReview.
the class PutDescription method apply.
@Override
public Response<String> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException {
if (input == null) {
// Delete would set description to null.
input = new Input();
}
if (resource.toAccountGroup() == null) {
throw new MethodNotAllowedException();
} else if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
if (group == null) {
throw new ResourceNotFoundException();
}
group.setDescription(Strings.emptyToNull(input.description));
db.get().accountGroups().update(Collections.singleton(group));
groupCache.evict(group);
return Strings.isNullOrEmpty(input.description) ? Response.<String>none() : Response.ok(input.description);
}
Aggregations