\r
private final Map<String, PageRegistration> registeredPages;\r
private boolean showAdmin;\r
-\r
+ private boolean isOwner;\r
+ \r
public RepositoryPage(PageParameters params) {\r
super(params);\r
repositoryName = WicketUtils.getRepositoryName(params);\r
}\r
\r
// Conditionally add edit link\r
- this.showAdmin = false;\r
+ showAdmin = false;\r
if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {\r
boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
} else {\r
showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
}\r
- if (showAdmin\r
- || GitBlitWebSession.get().isLoggedIn()\r
+ isOwner = GitBlitWebSession.get().isLoggedIn()\r
&& (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()\r
- .getUsername()))) {\r
+ .getUsername()));\r
+ if (showAdmin || isOwner) {\r
pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));\r
}\r
return pages;\r
return WicketUtils.newObjectParameter(repositoryName, commitId);\r
}\r
\r
- public boolean isShowAdmin()\r
- {\r
- return this.showAdmin;\r
+ public boolean isShowAdmin() {\r
+ return showAdmin;\r
+ }\r
+ \r
+ public boolean isOwner() {\r
+ return isOwner;\r
}\r
\r
private class SearchForm extends SessionlessForm<Void> implements Serializable {\r
\r
add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0));\r
add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());\r
- add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, isShowAdmin()).hideIfEmpty());\r
+ add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());\r
\r
if (getRepositoryModel().showReadme) {\r
String htmlText = null;\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.Constants;\r
+import com.gitblit.GitBlit;\r
import com.gitblit.SyndicationServlet;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
\r
private final boolean hasBranches;\r
\r
- public BranchesPanel(String wicketId, final RepositoryModel model, final Repository r,\r
+ public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,\r
final int maxCount, final boolean showAdmin) {\r
super(wicketId);\r
\r
// branches page\r
add(new Label("branches", new StringResourceModel("gb.branches", this, null)));\r
}\r
-\r
+ \r
+ // only allow delete if we have multiple branches\r
+ final boolean showDelete = showAdmin && branches.size() > 1;\r
+ \r
ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);\r
DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {\r
private static final long serialVersionUID = 1L;\r
item.add(shortlog);\r
\r
if (maxCount <= 0) {\r
- Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);\r
+ Fragment fragment = new Fragment("branchLinks", showDelete? "branchPageAdminLinks" : "branchPageLinks", this);\r
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
.newObjectParameter(model.name, entry.getName())));\r
fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils\r
fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink(\r
getRequest().getRelativePathPrefixToContextRoot(), model.name,\r
entry.getName(), 0)));\r
- \r
- fragment.add(createDeleteBranchLink(r, entry, showAdmin));\r
- \r
+ if (showDelete) {\r
+ fragment.add(createDeleteBranchLink(model, entry));\r
+ }\r
item.add(fragment);\r
} else {\r
Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);\r
return this;\r
}\r
\r
- private Link<Void> createDeleteBranchLink(final Repository r, final RefModel entry, final boolean showAdmin)\r
+ private Link<Void> createDeleteBranchLink(final RepositoryModel repositoryModel, final RefModel entry)\r
{\r
Link<Void> deleteLink = new Link<Void>("deleteBranch") {\r
private static final long serialVersionUID = 1L;\r
\r
@Override\r
public void onClick() {\r
- if( showAdmin && JGitUtils.deleteBranchRef(r, entry.getName()) ) {\r
+ Repository r = GitBlit.self().getRepository(repositoryModel.name);\r
+ boolean success = JGitUtils.deleteBranchRef(r, entry.getName());\r
+ r.close();\r
+ if (success) {\r
info(MessageFormat.format("Branch \"{0}\" deleted", entry.displayName));\r
+ // redirect to the owning page\r
+ setResponsePage(getPage().getClass(), WicketUtils.newRepositoryParameter(repositoryModel.name));\r
}\r
else {\r
error(MessageFormat.format("Failed to delete branch \"{0}\"", entry.displayName));\r
\r
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(\r
"Delete branch \"{0}\"?", entry.displayName )));\r
- \r
- deleteLink.setVisible(showAdmin);\r
- \r
return deleteLink;\r
}\r
}\r