Sort permissions in project access tab
Rather than displaying this in random order, we now sort the right objects by category and then group, as this the order the columns appear on the page in. It helps make it easier to locate who can perform a particular action on this project. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -15,32 +15,36 @@
|
|||||||
package com.google.gerrit.server.rpc.project;
|
package com.google.gerrit.server.rpc.project;
|
||||||
|
|
||||||
import com.google.gerrit.client.admin.ProjectDetail;
|
import com.google.gerrit.client.admin.ProjectDetail;
|
||||||
|
import com.google.gerrit.client.data.ApprovalType;
|
||||||
|
import com.google.gerrit.client.data.ApprovalTypes;
|
||||||
import com.google.gerrit.client.reviewdb.AccountGroup;
|
import com.google.gerrit.client.reviewdb.AccountGroup;
|
||||||
import com.google.gerrit.client.reviewdb.Project;
|
import com.google.gerrit.client.reviewdb.Project;
|
||||||
import com.google.gerrit.client.reviewdb.ProjectRight;
|
import com.google.gerrit.client.reviewdb.ProjectRight;
|
||||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
|
||||||
import com.google.gerrit.client.rpc.NoSuchEntityException;
|
import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||||
|
import com.google.gerrit.server.account.GroupCache;
|
||||||
import com.google.gerrit.server.config.WildProjectName;
|
import com.google.gerrit.server.config.WildProjectName;
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
import com.google.gerrit.server.project.ProjectState;
|
import com.google.gerrit.server.project.ProjectState;
|
||||||
import com.google.gerrit.server.rpc.Handler;
|
import com.google.gerrit.server.rpc.Handler;
|
||||||
import com.google.gwtorm.client.OrmException;
|
|
||||||
import com.google.gwtorm.client.ResultSet;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
class ProjectDetailFactory extends Handler<ProjectDetail> {
|
class ProjectDetailFactory extends Handler<ProjectDetail> {
|
||||||
interface Factory {
|
interface Factory {
|
||||||
ProjectDetailFactory create(@Assisted("name") Project.NameKey name);
|
ProjectDetailFactory create(@Assisted("name") Project.NameKey name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ApprovalTypes approvalTypes;
|
||||||
|
private final GroupCache groupCache;
|
||||||
private final ProjectCache projectCache;
|
private final ProjectCache projectCache;
|
||||||
private final ReviewDb db;
|
|
||||||
private final Project.NameKey wildProject;
|
private final Project.NameKey wildProject;
|
||||||
private final Project.NameKey projectName;
|
private final Project.NameKey projectName;
|
||||||
|
|
||||||
@@ -48,17 +52,19 @@ class ProjectDetailFactory extends Handler<ProjectDetail> {
|
|||||||
private Map<AccountGroup.Id, AccountGroup> groups;
|
private Map<AccountGroup.Id, AccountGroup> groups;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ProjectDetailFactory(final ProjectCache projectCache, final ReviewDb db,
|
ProjectDetailFactory(final ApprovalTypes approvalTypes,
|
||||||
|
final GroupCache groupCache, final ProjectCache projectCache,
|
||||||
@WildProjectName final Project.NameKey wp,
|
@WildProjectName final Project.NameKey wp,
|
||||||
@Assisted("name") final Project.NameKey name) {
|
@Assisted("name") final Project.NameKey name) {
|
||||||
|
this.approvalTypes = approvalTypes;
|
||||||
|
this.groupCache = groupCache;
|
||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
this.db = db;
|
|
||||||
this.wildProject = wp;
|
this.wildProject = wp;
|
||||||
this.projectName = name;
|
this.projectName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectDetail call() throws OrmException, NoSuchEntityException {
|
public ProjectDetail call() throws NoSuchEntityException {
|
||||||
final ProjectState e = projectCache.get(projectName);
|
final ProjectState e = projectCache.get(projectName);
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
throw new NoSuchEntityException();
|
throw new NoSuchEntityException();
|
||||||
@@ -68,7 +74,6 @@ class ProjectDetailFactory extends Handler<ProjectDetail> {
|
|||||||
detail.setProject(e.getProject());
|
detail.setProject(e.getProject());
|
||||||
|
|
||||||
groups = new HashMap<AccountGroup.Id, AccountGroup>();
|
groups = new HashMap<AccountGroup.Id, AccountGroup>();
|
||||||
|
|
||||||
final List<ProjectRight> rights = new ArrayList<ProjectRight>();
|
final List<ProjectRight> rights = new ArrayList<ProjectRight>();
|
||||||
for (final ProjectRight p : e.getRights()) {
|
for (final ProjectRight p : e.getRights()) {
|
||||||
rights.add(p);
|
rights.add(p);
|
||||||
@@ -80,8 +85,32 @@ class ProjectDetailFactory extends Handler<ProjectDetail> {
|
|||||||
wantGroup(p.getAccountGroupId());
|
wantGroup(p.getAccountGroupId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadGroups();
|
loadGroups();
|
||||||
|
|
||||||
|
Collections.sort(rights, new Comparator<ProjectRight>() {
|
||||||
|
@Override
|
||||||
|
public int compare(final ProjectRight a, final ProjectRight b) {
|
||||||
|
int rc = categoryOf(a).compareTo(categoryOf(b));
|
||||||
|
if (rc == 0) {
|
||||||
|
rc = groupOf(a).compareTo(groupOf(b));
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String categoryOf(final ProjectRight r) {
|
||||||
|
final ApprovalType type =
|
||||||
|
approvalTypes.getApprovalType(r.getApprovalCategoryId());
|
||||||
|
if (type == null) {
|
||||||
|
return r.getApprovalCategoryId().get();
|
||||||
|
}
|
||||||
|
return type.getCategory().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String groupOf(final ProjectRight r) {
|
||||||
|
return groups.get(r.getAccountGroupId()).getName();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
detail.setRights(rights);
|
detail.setRights(rights);
|
||||||
detail.setGroups(groups);
|
detail.setGroups(groups);
|
||||||
return detail;
|
return detail;
|
||||||
@@ -91,11 +120,11 @@ class ProjectDetailFactory extends Handler<ProjectDetail> {
|
|||||||
groups.put(id, null);
|
groups.put(id, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGroups() throws OrmException {
|
private void loadGroups() {
|
||||||
final ResultSet<AccountGroup> r = db.accountGroups().get(groups.keySet());
|
final Set<AccountGroup.Id> toGet = groups.keySet();
|
||||||
groups.clear();
|
groups = new HashMap<AccountGroup.Id, AccountGroup>();
|
||||||
for (final AccountGroup g : r) {
|
for (AccountGroup.Id groupId : toGet) {
|
||||||
groups.put(g.getId(), g);
|
groups.put(groupId, groupCache.get(groupId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user