use of com.google.gerrit.server.project.BranchResource in project gerrit by GerritCodeReview.
the class BranchesCollection method parse.
@Override
public BranchResource parse(ProjectResource parent, IdString id) throws RestApiException, IOException, PermissionBackendException {
parent.getProjectState().checkStatePermitsRead();
Project.NameKey project = parent.getNameKey();
try (Repository repo = repoManager.openRepository(project)) {
Ref ref = repo.exactRef(RefNames.fullName(id.get()));
if (ref == null) {
throw new ResourceNotFoundException(id);
}
// ListBranches checks the target of a symbolic reference to determine access
// rights on the symbolic reference itself. This check prevents seeing a hidden
// branch simply because the symbolic reference name was visible.
permissionBackend.currentUser().project(project).ref(ref.isSymbolic() ? ref.getTarget().getName() : ref.getName()).check(RefPermission.READ);
return new BranchResource(parent.getProjectState(), parent.getUser(), ref);
} catch (AuthException notAllowed) {
throw new ResourceNotFoundException(id, notAllowed);
} catch (RepositoryNotFoundException noRepo) {
throw new ResourceNotFoundException(id, noRepo);
}
}
use of com.google.gerrit.server.project.BranchResource in project gerrit by GerritCodeReview.
the class ListBranches method createBranchInfo.
private BranchInfo createBranchInfo(PermissionBackend.ForRef perm, Ref ref, ProjectState projectState, CurrentUser user, Set<String> targets) {
BranchInfo info = new BranchInfo();
info.ref = ref.getName();
info.revision = ref.getObjectId() != null ? ref.getObjectId().name() : null;
if (isConfigRef(ref.getName())) {
// Never allow to delete the meta config branch.
info.canDelete = null;
} else {
info.canDelete = !targets.contains(ref.getName()) && perm.testOrFalse(RefPermission.DELETE) && projectState.statePermitsWrite() ? true : null;
}
BranchResource rsrc = new BranchResource(projectState, user, ref);
for (UiAction.Description d : uiActions.from(branchViews, rsrc)) {
if (info.actions == null) {
info.actions = new TreeMap<>();
}
info.actions.put(d.getId(), new ActionInfo(d));
}
ImmutableList<WebLinkInfo> links = webLinks.getBranchLinks(projectState.getName(), ref.getName());
info.webLinks = links.isEmpty() ? null : links;
return info;
}
Aggregations