Expose project permissionOnly status via JSON-RPC
This is required by the Mylyn Gerrit connector to filter out projects with Git repositories that only define refs/meta/config (i.e. repository contains only configuration data and no real content). Change-Id: I42f4cfb5e8c1a52be0e15741912e05199628b61c Signed-off-by: Sascha Scholz <sascha.scholz@gmail.com>
This commit is contained in:
@@ -29,6 +29,8 @@ import java.util.Set;
|
|||||||
public interface ProjectAdminService extends RemoteJsonService {
|
public interface ProjectAdminService extends RemoteJsonService {
|
||||||
void visibleProjects(AsyncCallback<List<Project>> callback);
|
void visibleProjects(AsyncCallback<List<Project>> callback);
|
||||||
|
|
||||||
|
void visibleProjectDetails(AsyncCallback<List<ProjectDetail>> callback);
|
||||||
|
|
||||||
void projectDetail(Project.NameKey projectName,
|
void projectDetail(Project.NameKey projectName,
|
||||||
AsyncCallback<ProjectDetail> callback);
|
AsyncCallback<ProjectDetail> callback);
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class ProjectDetail {
|
|||||||
public boolean canModifyAgreements;
|
public boolean canModifyAgreements;
|
||||||
public boolean canModifyAccess;
|
public boolean canModifyAccess;
|
||||||
public boolean canModifyState;
|
public boolean canModifyState;
|
||||||
|
public boolean isPermissionOnly;
|
||||||
|
|
||||||
public ProjectDetail() {
|
public ProjectDetail() {
|
||||||
}
|
}
|
||||||
@@ -50,4 +51,8 @@ public class ProjectDetail {
|
|||||||
public void setCanModifyAccess(final boolean cma) {
|
public void setCanModifyAccess(final boolean cma) {
|
||||||
canModifyAccess = cma;
|
canModifyAccess = cma;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPermissionOnly(final boolean ipo) {
|
||||||
|
isPermissionOnly = ipo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
private final DeleteBranches.Factory deleteBranchesFactory;
|
private final DeleteBranches.Factory deleteBranchesFactory;
|
||||||
private final ListBranches.Factory listBranchesFactory;
|
private final ListBranches.Factory listBranchesFactory;
|
||||||
private final VisibleProjects.Factory visibleProjectsFactory;
|
private final VisibleProjects.Factory visibleProjectsFactory;
|
||||||
|
private final VisibleProjectDetails.Factory visibleProjectDetailsFactory;
|
||||||
private final ProjectAccessFactory.Factory projectAccessFactory;
|
private final ProjectAccessFactory.Factory projectAccessFactory;
|
||||||
private final ProjectDetailFactory.Factory projectDetailFactory;
|
private final ProjectDetailFactory.Factory projectDetailFactory;
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
final DeleteBranches.Factory deleteBranchesFactory,
|
final DeleteBranches.Factory deleteBranchesFactory,
|
||||||
final ListBranches.Factory listBranchesFactory,
|
final ListBranches.Factory listBranchesFactory,
|
||||||
final VisibleProjects.Factory visibleProjectsFactory,
|
final VisibleProjects.Factory visibleProjectsFactory,
|
||||||
|
final VisibleProjectDetails.Factory visibleProjectDetailsFactory,
|
||||||
final ProjectAccessFactory.Factory projectAccessFactory,
|
final ProjectAccessFactory.Factory projectAccessFactory,
|
||||||
final ProjectDetailFactory.Factory projectDetailFactory) {
|
final ProjectDetailFactory.Factory projectDetailFactory) {
|
||||||
this.addBranchFactory = addBranchFactory;
|
this.addBranchFactory = addBranchFactory;
|
||||||
@@ -54,6 +56,7 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
this.deleteBranchesFactory = deleteBranchesFactory;
|
this.deleteBranchesFactory = deleteBranchesFactory;
|
||||||
this.listBranchesFactory = listBranchesFactory;
|
this.listBranchesFactory = listBranchesFactory;
|
||||||
this.visibleProjectsFactory = visibleProjectsFactory;
|
this.visibleProjectsFactory = visibleProjectsFactory;
|
||||||
|
this.visibleProjectDetailsFactory = visibleProjectDetailsFactory;
|
||||||
this.projectAccessFactory = projectAccessFactory;
|
this.projectAccessFactory = projectAccessFactory;
|
||||||
this.projectDetailFactory = projectDetailFactory;
|
this.projectDetailFactory = projectDetailFactory;
|
||||||
}
|
}
|
||||||
@@ -63,6 +66,11 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
visibleProjectsFactory.create().to(callback);
|
visibleProjectsFactory.create().to(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visibleProjectDetails(final AsyncCallback<List<ProjectDetail>> callback) {
|
||||||
|
visibleProjectDetailsFactory.create().to(callback);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void projectDetail(final Project.NameKey projectName,
|
public void projectDetail(final Project.NameKey projectName,
|
||||||
final AsyncCallback<ProjectDetail> callback) {
|
final AsyncCallback<ProjectDetail> callback) {
|
||||||
|
|||||||
@@ -17,27 +17,36 @@ package com.google.gerrit.httpd.rpc.project;
|
|||||||
import com.google.gerrit.common.data.ProjectDetail;
|
import com.google.gerrit.common.data.ProjectDetail;
|
||||||
import com.google.gerrit.httpd.rpc.Handler;
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
import com.google.gerrit.reviewdb.Project;
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.project.ProjectState;
|
import com.google.gerrit.server.project.ProjectState;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
import org.eclipse.jgit.lib.Ref;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
class ProjectDetailFactory extends Handler<ProjectDetail> {
|
class ProjectDetailFactory extends Handler<ProjectDetail> {
|
||||||
interface Factory {
|
interface Factory {
|
||||||
ProjectDetailFactory create(@Assisted Project.NameKey name);
|
ProjectDetailFactory create(@Assisted Project.NameKey name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ProjectControl.Factory projectControlFactory;
|
private final ProjectControl.Factory projectControlFactory;
|
||||||
|
private final GitRepositoryManager gitRepositoryManager;
|
||||||
|
|
||||||
private final Project.NameKey projectName;
|
private final Project.NameKey projectName;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ProjectDetailFactory(final ProjectControl.Factory projectControlFactory,
|
ProjectDetailFactory(final ProjectControl.Factory projectControlFactory,
|
||||||
|
final GitRepositoryManager gitRepositoryManager,
|
||||||
@Assisted final Project.NameKey name) {
|
@Assisted final Project.NameKey name) {
|
||||||
this.projectControlFactory = projectControlFactory;
|
this.projectControlFactory = projectControlFactory;
|
||||||
|
this.gitRepositoryManager = gitRepositoryManager;
|
||||||
this.projectName = name;
|
this.projectName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +67,26 @@ class ProjectDetailFactory extends Handler<ProjectDetail> {
|
|||||||
detail.setCanModifyDescription(userIsOwner);
|
detail.setCanModifyDescription(userIsOwner);
|
||||||
detail.setCanModifyMergeType(userIsOwner);
|
detail.setCanModifyMergeType(userIsOwner);
|
||||||
detail.setCanModifyState(userIsOwner);
|
detail.setCanModifyState(userIsOwner);
|
||||||
|
|
||||||
|
final Project.NameKey projectName = projectState.getProject().getNameKey();
|
||||||
|
Repository git;
|
||||||
|
try {
|
||||||
|
git = gitRepositoryManager.openRepository(projectName);
|
||||||
|
} catch (RepositoryNotFoundException err) {
|
||||||
|
throw new NoSuchProjectException(projectName);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Ref head = git.getRef(Constants.HEAD);
|
||||||
|
if (head != null && head.isSymbolic()
|
||||||
|
&& GitRepositoryManager.REF_CONFIG.equals(head.getLeaf().getName())) {
|
||||||
|
detail.setPermissionOnly(true);
|
||||||
|
}
|
||||||
|
} catch (IOException err) {
|
||||||
|
throw new NoSuchProjectException(projectName);
|
||||||
|
} finally {
|
||||||
|
git.close();
|
||||||
|
}
|
||||||
|
|
||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class ProjectModule extends RpcServletModule {
|
|||||||
factory(DeleteBranches.Factory.class);
|
factory(DeleteBranches.Factory.class);
|
||||||
factory(ListBranches.Factory.class);
|
factory(ListBranches.Factory.class);
|
||||||
factory(VisibleProjects.Factory.class);
|
factory(VisibleProjects.Factory.class);
|
||||||
|
factory(VisibleProjectDetails.Factory.class);
|
||||||
factory(ProjectAccessFactory.Factory.class);
|
factory(ProjectAccessFactory.Factory.class);
|
||||||
factory(ProjectDetailFactory.Factory.class);
|
factory(ProjectDetailFactory.Factory.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.httpd.rpc.project;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gerrit.common.data.ProjectDetail;
|
||||||
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class VisibleProjectDetails extends Handler<List<ProjectDetail>> {
|
||||||
|
|
||||||
|
interface Factory {
|
||||||
|
VisibleProjectDetails create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ProjectCache projectCache;
|
||||||
|
private final ProjectDetailFactory.Factory projectDetailFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
VisibleProjectDetails(final ProjectCache projectCache,
|
||||||
|
final ProjectDetailFactory.Factory projectDetailFactory) {
|
||||||
|
this.projectCache = projectCache;
|
||||||
|
this.projectDetailFactory = projectDetailFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProjectDetail> call() {
|
||||||
|
List<ProjectDetail> result = new ArrayList<ProjectDetail>();
|
||||||
|
for (Project.NameKey projectName : projectCache.all()) {
|
||||||
|
try {
|
||||||
|
result.add(projectDetailFactory.create(projectName).call());
|
||||||
|
} catch (NoSuchProjectException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(result, new Comparator<ProjectDetail>() {
|
||||||
|
public int compare(final ProjectDetail a, final ProjectDetail b) {
|
||||||
|
return a.project.getName().compareTo(b.project.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user