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