From febe84e9bc668c804c31b0d96989e15483efca7a Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 6 Jul 2011 20:33:12 +0200 Subject: [PATCH] In ProjectAccessScreen add link to history of project.config in gitweb Looking at the access rights of a project, a project owner might be interested to understand why a certain access right was set as it is. Since the access rights are now persisted as a file inside the git repository (project.config in the refs/meta/config branch), looking at the history of this file and the corresponding commits might help to understand the current access rights. If the user is allowed to see the refs/meta/config branch this change adds a link to the history of the project.config file in gitweb to the ProjectAccessScreen, so that it can be accessed by a single click. Change-Id: Id1f30d1cb537c1e34c1a3e8d8420098b727b9076 Signed-off-by: Edwin Kempin --- .../google/gerrit/common/data/GitWebType.java | 25 +++++++++++++++++++ .../google/gerrit/common/data/GitwebLink.java | 10 ++++++++ .../gerrit/common/data/ProjectAccess.java | 18 +++++++++++++ .../client/admin/ProjectAccessEditor.java | 19 ++++++++++++++ .../client/admin/ProjectAccessEditor.ui.xml | 14 +++++++++++ .../rpc/project/ProjectAccessFactory.java | 4 +++ 6 files changed, 90 insertions(+) diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java index bf7b721fb2..eaee6e09b6 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java @@ -31,6 +31,7 @@ public class GitWebType { type.setProject("?p=${project}.git;a=summary"); type.setRevision("?p=${project}.git;a=commit;h=${commit}"); type.setBranch("?p=${project}.git;a=shortlog;h=${branch}"); + type.setFileHistory("?p=${project}.git;a=history;hb=${branch};f=${file}"); } else if (name.equalsIgnoreCase("cgit")) { type = new GitWebType(); @@ -38,6 +39,7 @@ public class GitWebType { type.setProject("${project}/summary"); type.setRevision("${project}/commit/?id=${commit}"); type.setBranch("${project}/log/?h=${branch}"); + type.setFileHistory("${project}/log/${file}?h=${branch}"); } else if (name.equalsIgnoreCase("custom")) { type = new GitWebType(); @@ -66,6 +68,9 @@ public class GitWebType { /** ParamertizedString for branch view url. */ private String branch; + /** ParamertizedString for file history view url. */ + private String fileHistory; + /** Private default constructor for gson. */ protected GitWebType() { } @@ -106,6 +111,15 @@ public class GitWebType { return revision; } + /** + * Get the String for file history view. + * + * @return The String for file history view + */ + public String getFileHistory() { + return fileHistory; + } + /** * Set the pattern for branch view. * @@ -149,4 +163,15 @@ public class GitWebType { revision = pattern; } } + + /** + * Set the pattern for file history view. + * + * @param pattern The pattern for file history view + */ + public void setFileHistory(final String pattern) { + if (pattern != null && !pattern.isEmpty()) { + fileHistory = pattern; + } + } } diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GitwebLink.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GitwebLink.java index cf74e7c3dd..2df67f1175 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/GitwebLink.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GitwebLink.java @@ -65,4 +65,14 @@ public class GitwebLink { p.put("branch", URL.encodeQueryString(branch.get())); return baseUrl + pattern.replace(p); } + + public String toFileHistory(final Branch.NameKey branch, final String file) { + ParameterizedString pattern = new ParameterizedString(type.getFileHistory()); + + final Map p = new HashMap(); + p.put("project", URL.encodeQueryString(branch.getParentKey().get())); + p.put("branch", URL.encodeQueryString(branch.get())); + p.put("file", URL.encodeQueryString(file)); + return baseUrl + pattern.replace(p); + } } diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/ProjectAccess.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/ProjectAccess.java index 168544dac7..2a80d52026 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/ProjectAccess.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/ProjectAccess.java @@ -20,14 +20,24 @@ import java.util.List; import java.util.Set; public class ProjectAccess { + protected Project.NameKey projectName; protected String revision; protected Project.NameKey inheritsFrom; protected List local; protected Set ownerOf; + protected boolean isConfigVisible; public ProjectAccess() { } + public Project.NameKey getProjectName() { + return projectName; + } + + public void setProjectName(Project.NameKey projectName) { + this.projectName = projectName; + } + public String getRevision() { return revision; } @@ -76,4 +86,12 @@ public class ProjectAccess { public void setOwnerOf(Set refs) { ownerOf = refs; } + + public boolean isConfigVisible() { + return isConfigVisible; + } + + public void setConfigVisible(boolean isConfigVisible) { + this.isConfigVisible = isConfigVisible; + } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.java index f3c133ba1e..e6e11b09ca 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.java @@ -15,9 +15,12 @@ package com.google.gerrit.client.admin; import com.google.gerrit.client.Dispatcher; +import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.ui.Hyperlink; import com.google.gerrit.common.data.AccessSection; +import com.google.gerrit.common.data.GitwebLink; import com.google.gerrit.common.data.ProjectAccess; +import com.google.gerrit.reviewdb.Branch; import com.google.gerrit.reviewdb.Project; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.DivElement; @@ -52,6 +55,12 @@ public class ProjectAccessEditor extends Composite implements @UiField Hyperlink parentProject; + @UiField + DivElement history; + + @UiField + Anchor gitweb; + @UiField FlowPanel localContainer; ListEditor local; @@ -101,6 +110,16 @@ public class ProjectAccessEditor extends Composite implements inheritsFrom.getStyle().setDisplay(Display.NONE); } + final GitwebLink c = Gerrit.getConfig().getGitwebLink(); + if (value.isConfigVisible() && c != null) { + history.getStyle().setDisplay(Display.BLOCK); + gitweb.setText(c.getLinkName()); + gitweb.setHref(c.toFileHistory(new Branch.NameKey(value.getProjectName(), + "refs/meta/config"), "project.config")); + } else { + history.getStyle().setDisplay(Display.NONE); + } + addSection.setVisible(value != null && editing && !value.getOwnerOf().isEmpty()); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.ui.xml index 9360daa65d..4942b832d6 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.ui.xml +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectAccessEditor.ui.xml @@ -33,6 +33,16 @@ limitations under the License. display: inline; } + .history { + margin-bottom: 0.5em; + } + .historyTitle { + font-weight: bold; + } + .gitwebLink { + display: inline; + } + .addContainer { margin-top: 5px; font-size: 80%; @@ -47,6 +57,10 @@ limitations under the License. Rights Inherit From: +
+ History: + +
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ProjectAccessFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ProjectAccessFactory.java index 440366ba12..86e884057e 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ProjectAccessFactory.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ProjectAccessFactory.java @@ -25,6 +25,7 @@ import com.google.gerrit.reviewdb.Project; import com.google.gerrit.server.account.GroupCache; import com.google.gerrit.server.account.GroupControl; import com.google.gerrit.server.config.AllProjectsName; +import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.MetaDataUpdate; import com.google.gerrit.server.git.ProjectConfig; import com.google.gerrit.server.project.NoSuchProjectException; @@ -177,6 +178,7 @@ class ProjectAccessFactory extends Handler { } final ProjectAccess detail = new ProjectAccess(); + detail.setProjectName(projectName); detail.setRevision(config.getRevision().name()); if (projectName.equals(allProjectsName)) { @@ -194,6 +196,8 @@ class ProjectAccessFactory extends Handler { detail.setLocal(local); detail.setOwnerOf(ownerOf); + detail.setConfigVisible(pc.isOwner() + || pc.controlForRef(GitRepositoryManager.REF_CONFIG).isVisible()); return detail; }