diff options
author | peto268 <peto268@gmail.com> | 2014-04-26 14:08:31 +0200 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-05-08 13:40:41 -0400 |
commit | 99b43dffe86b635e97f625157083cee37ee921bf (patch) | |
tree | ea4ba8fd29ca248b0f298e5ff1c00d9160c52561 /src | |
parent | 1d2d5efe6d5dafbd2236776bc4667521921e5c8c (diff) | |
download | gitblit-99b43dffe86b635e97f625157083cee37ee921bf.tar.gz gitblit-99b43dffe86b635e97f625157083cee37ee921bf.zip |
Added option to disable deleting of non empty repositories through the user interface
Diffstat (limited to 'src')
3 files changed, 50 insertions, 13 deletions
diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties index 3215094e..30e97896 100644 --- a/src/main/distrib/data/gitblit.properties +++ b/src/main/distrib/data/gitblit.properties @@ -766,6 +766,11 @@ web.authenticateAdminPages = true # SINCE 0.5.0
web.allowCookieAuthentication = true
+# Allow deleting of non empty repositories through the user interface.
+#
+# SINCE 1.6.0
+web.allowDeletingNonEmptyRepositories = true
+
# Config file for storing project metadata
#
# SINCE 1.2.0
diff --git a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java index a0f8ac48..2c84ac06 100644 --- a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java @@ -145,20 +145,36 @@ public class ProjectRepositoryPanel extends BasePanel { @Override
public void onClick() {
- if (app().repositories().deleteRepositoryModel(entry)) {
+ // refresh the model
+ RepositoryModel model = app().repositories().getRepositoryModel(entry.name);
+ if (isDeleteAllowed(model) &&
+ app().repositories().deleteRepositoryModel(model)) {
// redirect to the owning page
- if (entry.isPersonalRepository()) {
- setResponsePage(getPage().getClass(), WicketUtils.newUsernameParameter(entry.projectPath.substring(1)));
+ if (model.isPersonalRepository()) {
+ setResponsePage(getPage().getClass(), WicketUtils.newUsernameParameter(model.projectPath.substring(1)));
} else {
- setResponsePage(getPage().getClass(), WicketUtils.newProjectParameter(entry.projectPath));
+ setResponsePage(getPage().getClass(), WicketUtils.newProjectParameter(model.projectPath));
}
} else {
- error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), entry));
+ error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), model));
}
}
+
+ @Override
+ public boolean isEnabled() {
+ return isDeleteAllowed(entry);
+ }
+
+ private boolean isDeleteAllowed(
+ final RepositoryModel model) {
+ return app().settings().getBoolean(Keys.web.allowDeletingNonEmptyRepositories, true)
+ || !model.hasCommits;
+ }
};
- deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
- localizer.getString("gb.deleteRepository", parent), entry)));
+ if (deleteLink.isEnabled()) {
+ deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
+ localizer.getString("gb.deleteRepository", parent), entry)));
+ }
repositoryLinks.add(deleteLink);
}
} else {
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java index be5d960b..40cd77e6 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -334,20 +334,36 @@ public class RepositoriesPanel extends BasePanel { @Override
public void onClick() {
- if (app().repositories().deleteRepositoryModel(entry)) {
+ // refresh the model
+ RepositoryModel model = app().repositories().getRepositoryModel(entry.name);
+ if (isDeleteAllowed(model) &&
+ app().repositories().deleteRepositoryModel(model)) {
if (dp instanceof SortableRepositoriesProvider) {
- info(MessageFormat.format(getString("gb.repositoryDeleted"), entry));
- ((SortableRepositoriesProvider) dp).remove(entry);
+ info(MessageFormat.format(getString("gb.repositoryDeleted"), model));
+ ((SortableRepositoriesProvider) dp).remove(model);
} else {
setResponsePage(getPage().getClass(), getPage().getPageParameters());
}
} else {
- error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), entry));
+ error(MessageFormat.format(getString("gb.repositoryDeleteFailed"), model));
}
}
+
+ @Override
+ public boolean isEnabled() {
+ return isDeleteAllowed(entry);
+ }
+
+ private boolean isDeleteAllowed(
+ final RepositoryModel model) {
+ return app().settings().getBoolean(Keys.web.allowDeletingNonEmptyRepositories, true)
+ || !model.hasCommits;
+ }
};
- deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
- getString("gb.deleteRepository"), entry)));
+ if (deleteLink.isEnabled()) {
+ deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
+ getString("gb.deleteRepository"), entry)));
+ }
repositoryLinks.add(deleteLink);
row.add(repositoryLinks);
} else if (showOwner) {
|