diff options
author | James Moger <james.moger@gitblit.com> | 2014-05-09 07:56:22 -0600 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-05-09 07:56:22 -0600 |
commit | c4a443e8bdd6f85265f4c460686bc44ddc8183e1 (patch) | |
tree | c5cdcff2bc2de17af7d2cf5a1fea87396a1fb72b /src/main/java/com/gitblit | |
parent | ad1a0235bfce09dbcbcc17a0b49a55862422b728 (diff) | |
parent | b4ed66fda03d83fd281ca9cbeae0a1c7785489e4 (diff) | |
download | gitblit-c4a443e8bdd6f85265f4c460686bc44ddc8183e1.tar.gz gitblit-c4a443e8bdd6f85265f4c460686bc44ddc8183e1.zip |
Merged #67 "Allow disabling repository deletion"
Diffstat (limited to 'src/main/java/com/gitblit')
9 files changed, 69 insertions, 78 deletions
diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java index 2782e724..16c71ba6 100644 --- a/src/main/java/com/gitblit/manager/GitblitManager.java +++ b/src/main/java/com/gitblit/manager/GitblitManager.java @@ -1015,6 +1015,11 @@ public class GitblitManager implements IGitblit { } @Override + public boolean canDelete(RepositoryModel model) { + return repositoryManager.canDelete(model); + } + + @Override public boolean deleteRepositoryModel(RepositoryModel model) { return repositoryManager.deleteRepositoryModel(model); } diff --git a/src/main/java/com/gitblit/manager/IRepositoryManager.java b/src/main/java/com/gitblit/manager/IRepositoryManager.java index 69177f1e..f5cf03fa 100644 --- a/src/main/java/com/gitblit/manager/IRepositoryManager.java +++ b/src/main/java/com/gitblit/manager/IRepositoryManager.java @@ -339,6 +339,15 @@ public interface IRepositoryManager extends IManager { void updateConfiguration(Repository r, RepositoryModel repository); /** + * Returns true if the repository can be deleted. + * + * @param model + * @return true if the repository can be deleted + * @since 1.6.0 + */ + boolean canDelete(RepositoryModel model); + + /** * Deletes the repository from the file system and removes the repository * permission from all repository users. * diff --git a/src/main/java/com/gitblit/manager/RepositoryManager.java b/src/main/java/com/gitblit/manager/RepositoryManager.java index 7351eb97..c141f088 100644 --- a/src/main/java/com/gitblit/manager/RepositoryManager.java +++ b/src/main/java/com/gitblit/manager/RepositoryManager.java @@ -1533,6 +1533,17 @@ public class RepositoryManager implements IRepositoryManager { } /** + * Returns true if the repository can be deleted. + * + * @return true if the repository can be deleted + */ + @Override + public boolean canDelete(RepositoryModel repository) { + return settings.getBoolean(Keys.web.allowDeletingNonEmptyRepositories, true) + || !repository.hasCommits; + } + + /** * Deletes the repository from the file system and removes the repository * permission from all repository users. * @@ -1553,6 +1564,12 @@ public class RepositoryManager implements IRepositoryManager { */ @Override public boolean deleteRepository(String repositoryName) { + RepositoryModel repository = getRepositoryModel(repositoryName); + if (!canDelete(repository)) { + logger.warn("Attempt to delete {} rejected!", repositoryName); + return false; + } + try { close(repositoryName); // clear the repository cache diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html index f82ac3d5..b7a1976f 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -112,7 +112,7 @@ <div class="row">
<div class="span12">
- <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /></div>
+ <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /> <input class="btn btn-danger" type="submit" value="Delete" wicket:message="value:gb.delete" wicket:id="delete" /></div>
</div>
</div>
diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index cd0da5f4..412c0ecc 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -42,6 +42,7 @@ import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
@@ -68,6 +69,7 @@ import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.StringChoiceRenderer;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation;
import com.gitblit.wicket.panels.BulletListPanel;
import com.gitblit.wicket.panels.RegistrantPermissionsPanel;
@@ -614,6 +616,38 @@ public class EditRepositoryPage extends RootSubPage { cancel.setDefaultFormProcessing(false);
form.add(cancel);
+ // the user can delete if deletions are allowed AND the user is an admin or the personal owner
+ // assigned ownership is not sufficient to allow deletion
+ boolean canDelete = !isCreate && app().repositories().canDelete(repositoryModel)
+ && (user.canAdmin() || user.isMyPersonalRepository(repositoryModel.name));
+
+ Link<Void> delete = new Link<Void>("delete") {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick() {
+ RepositoryModel latestModel = app().repositories().getRepositoryModel(repositoryModel.name);
+ boolean canDelete = app().repositories().canDelete(latestModel);
+ if (canDelete) {
+ if (app().repositories().deleteRepositoryModel(latestModel)) {
+ info(MessageFormat.format(getString("gb.repositoryDeleted"), latestModel));
+ setResponsePage(RepositoriesPage.class);
+ } else {
+ error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), latestModel));
+ }
+ } else {
+ error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), latestModel));
+ }
+ }
+ };
+
+ if (canDelete) {
+ delete.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
+ getString("gb.deleteRepository"), repositoryModel)));
+ }
+ form.add(delete.setVisible(canDelete));
+
add(form);
}
diff --git a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.html b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.html index d5a87d3f..33345a0a 100644 --- a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.html @@ -5,15 +5,6 @@ lang="en">
<wicket:panel>
- <wicket:fragment wicket:id="repositoryAdminLinks">
- <span class="link">
- <a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a>
- | <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a>
- | <a wicket:id="editRepository"><wicket:message key="gb.edit">[edit]</wicket:message></a>
- | <a wicket:id="deleteRepository"><wicket:message key="gb.delete">[delete]</wicket:message></a>
- </span>
- </wicket:fragment>
-
<wicket:fragment wicket:id="repositoryOwnerLinks">
<span class="link">
<a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a>
diff --git a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java index a0f8ac48..8630d201 100644 --- a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java @@ -15,7 +15,6 @@ */
package com.gitblit.wicket.panels;
-import java.text.MessageFormat;
import java.util.Map;
import org.apache.wicket.Component;
@@ -24,7 +23,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ExternalLink;
-import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Fragment;
import com.gitblit.Constants.AccessRestrictionType;
@@ -129,38 +127,10 @@ public class ProjectRepositoryPanel extends BasePanel { user = UserModel.ANONYMOUS;
}
Fragment repositoryLinks;
- boolean showOwner = entry.isOwner(user.username);
- // owner of personal repository gets admin powers
- boolean showAdmin = isAdmin || entry.isUsersPersonalRepository(user.username);
-
- if (showAdmin || showOwner) {
- repositoryLinks = new Fragment("repositoryLinks", showAdmin ? "repositoryAdminLinks"
- : "repositoryOwnerLinks", this);
+ if (user.canAdmin(entry)) {
+ repositoryLinks = new Fragment("repositoryLinks", "repositoryOwnerLinks", this);
repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository", EditRepositoryPage.class,
WicketUtils.newRepositoryParameter(entry.name)));
- if (showAdmin) {
- Link<Void> deleteLink = new Link<Void>("deleteRepository") {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick() {
- if (app().repositories().deleteRepositoryModel(entry)) {
- // redirect to the owning page
- if (entry.isPersonalRepository()) {
- setResponsePage(getPage().getClass(), WicketUtils.newUsernameParameter(entry.projectPath.substring(1)));
- } else {
- setResponsePage(getPage().getClass(), WicketUtils.newProjectParameter(entry.projectPath));
- }
- } else {
- error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), entry));
- }
- }
- };
- deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
- localizer.getString("gb.deleteRepository", parent), entry)));
- repositoryLinks.add(deleteLink);
- }
} else {
repositoryLinks = new Fragment("repositoryLinks", "repositoryUserLinks", this);
}
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html index 0cf3ef29..c3ec2e27 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.html @@ -42,10 +42,6 @@ </div>
</wicket:fragment>
- <wicket:fragment wicket:id="repositoryAdminLinks">
- <span class="link"><a wicket:id="editRepository"><wicket:message key="gb.edit">[edit]</wicket:message></a> | <a wicket:id="deleteRepository"><wicket:message key="gb.delete">[delete]</wicket:message></a></span>
- </wicket:fragment>
-
<wicket:fragment wicket:id="repositoryOwnerLinks">
<span class="link"><a wicket:id="editRepository"><wicket:message key="gb.edit">[edit]</wicket:message></a></span>
</wicket:fragment>
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java index be5d960b..54e2aab9 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -15,7 +15,6 @@ */
package com.gitblit.wicket.panels;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -320,37 +319,7 @@ public class RepositoriesPanel extends BasePanel { WicketUtils.setHtmlTooltip(lastChangeLabel, getString("gb.author") + ": " + entry.lastChangeAuthor);
}
- boolean showOwner = user != null && entry.isOwner(user.username);
- boolean myPersonalRepository = showOwner && entry.isUsersPersonalRepository(user.username);
- if (showAdmin || myPersonalRepository) {
- Fragment repositoryLinks = new Fragment("repositoryLinks",
- "repositoryAdminLinks", this);
- repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository",
- EditRepositoryPage.class, WicketUtils
- .newRepositoryParameter(entry.name)));
- Link<Void> deleteLink = new Link<Void>("deleteRepository") {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick() {
- if (app().repositories().deleteRepositoryModel(entry)) {
- if (dp instanceof SortableRepositoriesProvider) {
- info(MessageFormat.format(getString("gb.repositoryDeleted"), entry));
- ((SortableRepositoriesProvider) dp).remove(entry);
- } else {
- setResponsePage(getPage().getClass(), getPage().getPageParameters());
- }
- } else {
- error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), entry));
- }
- }
- };
- deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
- getString("gb.deleteRepository"), entry)));
- repositoryLinks.add(deleteLink);
- row.add(repositoryLinks);
- } else if (showOwner) {
+ if (user != null && user.canAdmin(entry)) {
Fragment repositoryLinks = new Fragment("repositoryLinks",
"repositoryOwnerLinks", this);
repositoryLinks.add(new BookmarkablePageLink<Void>("editRepository",
|