Search in sources :

Example 1 with BranchResource

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);
    }
}
Also used : Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) BranchResource(com.google.gerrit.server.project.BranchResource) AuthException(com.google.gerrit.extensions.restapi.AuthException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 2 with BranchResource

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;
}
Also used : BranchInfo(com.google.gerrit.extensions.api.projects.BranchInfo) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) BranchResource(com.google.gerrit.server.project.BranchResource) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) UiAction(com.google.gerrit.extensions.webui.UiAction)

Aggregations

BranchResource (com.google.gerrit.server.project.BranchResource)2 Project (com.google.gerrit.entities.Project)1 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)1 ActionInfo (com.google.gerrit.extensions.common.ActionInfo)1 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 UiAction (com.google.gerrit.extensions.webui.UiAction)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1