Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Allow Forums to disable the Backups feature

Robin Ward69a90f31fba1
diff --git a/app/assets/javascripts/admin/routes/admin-backups.js.es6 b/app/assets/javascripts/admin/routes/admin-backups.js.es6
index 6d1a425190f..92ac4652fa6 100644
--- a/app/assets/javascripts/admin/routes/admin-backups.js.es6
+++ b/app/assets/javascripts/admin/routes/admin-backups.js.es6
@@ -68,7 +68,7 @@ export default Discourse.Route.extend({
function(confirmed) {
if (confirmed) {
backup.destroy().then(function() {
- self.controllerFor("adminBackupsIndex").removeObject(backup);
+ self.controllerFor("adminBackupsIndex").get('model').removeObject(backup);
});
}
}
diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs
index 01f9ffb6738..af4aafde947 100644
--- a/app/assets/javascripts/admin/templates/admin.hbs
+++ b/app/assets/javascripts/admin/templates/admin.hbs
@@ -20,7 +20,9 @@
{{#if currentUser.admin}}
{{nav-item route='adminCustomize' label='admin.customize.title'}}
{{nav-item route='adminApi' label='admin.api.title'}}
- {{nav-item route='admin.backups' label='admin.backups.title'}}
+ {{#if siteSettings.enable_backups}}
+ {{nav-item route='admin.backups' label='admin.backups.title'}}
+ {{/if}}
{{/if}}
{{nav-item route='adminPlugins' label='admin.plugins.title'}}
{{plugin-outlet name="admin-menu" connectorTagName="li"}}
diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb
index 7a3fcfa78d8..52b8403cddf 100644
--- a/app/controllers/admin/backups_controller.rb
+++ b/app/controllers/admin/backups_controller.rb
@@ -2,6 +2,7 @@ require "backup_restore/backup_restore"
class Admin::BackupsController < Admin::AdminController
+ before_action :ensure_backups_enabled
skip_before_action :check_xhr, only: [:index, :show, :logs, :check_backup_chunk, :upload_backup_chunk]
def index
@@ -178,4 +179,8 @@ class Admin::BackupsController < Admin::AdminController
`df -Pk #{Rails.root}/public/backups | awk 'NR==2 {print $4 * 1024;}'`.to_i > size
end
+ def ensure_backups_enabled
+ raise Discourse::InvalidAccess.new unless SiteSetting.enable_backups?
+ end
+
end
diff --git a/app/jobs/scheduled/schedule_backup.rb b/app/jobs/scheduled/schedule_backup.rb
index 047c8a11416..48ebe73fc24 100644
--- a/app/jobs/scheduled/schedule_backup.rb
+++ b/app/jobs/scheduled/schedule_backup.rb
@@ -5,7 +5,7 @@ module Jobs
sidekiq_options retry: false
def execute(args)
- return unless SiteSetting.automatic_backups_enabled?
+ return unless SiteSetting.enable_backups? && SiteSetting.automatic_backups_enabled?
if latest_backup = Backup.all[0]
date = File.ctime(latest_backup.path).getutc.to_date
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 40791ae9f86..b6e5af9b2ea 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1159,6 +1159,7 @@ en:
github_client_secret: "Client secret for Github authentication, registered at https://github.com/settings/applications"
readonly_mode_during_backup: "Enable read only mode while taking a backup"
+ enable_backups: "Allow administrators to create backups of the forum"
allow_restore: "Allow restore, which can replace ALL site data! Leave false unless you plan to restore a backup"
maximum_backups: "The maximum amount of backups to keep on disk. Older backups are automatically deleted"
automatic_backups_enabled: "Run automatic backups as defined in backup frequency"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index af3d8beacd8..44ad6c6014f 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1168,6 +1168,10 @@ legal:
default: ''
backups:
+ enable_backups:
+ default: true
+ shadowed_by_global: true
+ client: true
readonly_mode_during_backup:
default: false
allow_restore:
diff --git a/spec/requests/admin/backups_controller_spec.rb b/spec/requests/admin/backups_controller_spec.rb
index 1fc67d76015..719056f64b4 100644
--- a/spec/requests/admin/backups_controller_spec.rb
+++ b/spec/requests/admin/backups_controller_spec.rb
@@ -7,6 +7,14 @@ RSpec.describe Admin::BackupsController do
sign_in(admin)
end
+ describe "#index" do
+ it "raises an error when backups are disabled" do
+ SiteSetting.enable_backups = false
+ get "/admin/backups.json"
+ expect(response).not_to be_success
+ end
+ end
+
describe '#rollback' do
it 'should rollback the restore' do
BackupRestore.expects(:rollback!)