2020-03-07 00:41:41 +08:00
|
|
|
import Controller, { inject as controller } from "@ember/controller";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { alias, equal } from "@ember/object/computed";
|
2019-01-24 00:40:24 +08:00
|
|
|
import { i18n, setting } from "discourse/lib/computed";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2020-01-17 01:56:53 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2016-10-21 01:26:41 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2020-03-07 00:41:41 +08:00
|
|
|
adminBackups: controller(),
|
2019-10-31 04:28:29 +08:00
|
|
|
status: alias("adminBackups.model"),
|
2019-01-24 00:40:24 +08:00
|
|
|
uploadLabel: i18n("admin.backups.upload.label"),
|
|
|
|
backupLocation: setting("backup_location"),
|
2019-10-31 04:28:29 +08:00
|
|
|
localBackupStorage: equal("backupLocation", "local"),
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("status.allowRestore", "status.isOperationRunning")
|
2019-01-24 00:40:24 +08:00
|
|
|
restoreTitle(allowRestore, isOperationRunning) {
|
|
|
|
if (!allowRestore) {
|
2015-03-27 01:05:27 +08:00
|
|
|
return "admin.backups.operations.restore.is_disabled";
|
2019-01-24 00:40:24 +08:00
|
|
|
} else if (isOperationRunning) {
|
2015-03-27 01:05:27 +08:00
|
|
|
return "admin.backups.operations.is_running";
|
2014-02-13 12:35:46 +08:00
|
|
|
} else {
|
2015-03-27 01:05:27 +08:00
|
|
|
return "admin.backups.operations.restore.title";
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
2019-01-24 00:40:24 +08:00
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
|
|
|
|
actions: {
|
2015-03-27 01:05:27 +08:00
|
|
|
toggleReadOnlyMode() {
|
2014-09-12 03:25:30 +08:00
|
|
|
if (!this.site.get("isReadOnly")) {
|
2014-02-13 12:35:46 +08:00
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.backups.read_only.enable.confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
2019-01-24 00:40:24 +08:00
|
|
|
(confirmed) => {
|
2014-02-13 23:56:23 +08:00
|
|
|
if (confirmed) {
|
2019-07-26 17:20:11 +08:00
|
|
|
this.set("currentUser.hideReadOnlyAlert", true);
|
2019-01-24 00:40:24 +08:00
|
|
|
this._toggleReadOnlyMode(true);
|
2014-02-13 23:56:23 +08:00
|
|
|
}
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this._toggleReadOnlyMode(false);
|
|
|
|
}
|
2016-11-12 05:31:08 +08:00
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2016-11-12 05:31:08 +08:00
|
|
|
download(backup) {
|
2019-01-24 00:40:24 +08:00
|
|
|
const link = backup.get("filename");
|
|
|
|
ajax(`/admin/backups/${link}`, { type: "PUT" }).then(() =>
|
|
|
|
bootbox.alert(I18n.t("admin.backups.operations.download.alert"))
|
|
|
|
);
|
2016-11-12 05:31:08 +08:00
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
},
|
|
|
|
|
2015-03-27 01:05:27 +08:00
|
|
|
_toggleReadOnlyMode(enable) {
|
2016-07-01 01:55:44 +08:00
|
|
|
ajax("/admin/backups/readonly", {
|
2014-02-13 12:35:46 +08:00
|
|
|
type: "PUT",
|
2019-01-24 00:40:24 +08:00
|
|
|
data: { enable },
|
|
|
|
}).then(() => this.site.set("isReadOnly", enable));
|
2014-03-19 09:21:10 +08:00
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
});
|