mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
[WIP] Provide system restore facility
Co-Authored-By: Harvey Kandola <harvey@documize.com>
This commit is contained in:
parent
71a2860716
commit
516140dd7e
12 changed files with 597 additions and 51 deletions
|
@ -12,9 +12,10 @@
|
|||
import $ from 'jquery';
|
||||
import { inject as service } from '@ember/service';
|
||||
import Notifier from '../../mixins/notifier';
|
||||
import Modal from '../../mixins/modal';
|
||||
import Component from '@ember/component';
|
||||
|
||||
export default Component.extend(Notifier, {
|
||||
export default Component.extend(Notifier, Modal, {
|
||||
appMeta: service(),
|
||||
browserSvc: service('browser'),
|
||||
buttonLabel: 'Start Backup',
|
||||
|
@ -23,9 +24,9 @@ export default Component.extend(Notifier, {
|
|||
backupError: false,
|
||||
backupSuccess: false,
|
||||
restoreSpec: null,
|
||||
restoreButtonLabel: 'Perform Restore',
|
||||
restoreUploading: false,
|
||||
restoreButtonLabel: 'Restore',
|
||||
restoreUploadReady: false,
|
||||
confirmRestore: '',
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
|
@ -41,6 +42,7 @@ export default Component.extend(Notifier, {
|
|||
});
|
||||
|
||||
this.set('restoreFile', null);
|
||||
this.set('confirmRestore', '');
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
|
@ -79,7 +81,26 @@ export default Component.extend(Notifier, {
|
|||
});
|
||||
},
|
||||
|
||||
onRestore() {
|
||||
onShowRestoreModal() {
|
||||
this.modalOpen("#confirm-restore-modal", {"show": true}, '#confirm-restore');
|
||||
},
|
||||
|
||||
onRestore(e) {
|
||||
e.preventDefault();
|
||||
|
||||
let typed = this.get('confirmRestore');
|
||||
typed = typed.toLowerCase();
|
||||
|
||||
if (typed !== 'restore' || typed === '') {
|
||||
$("#confirm-restore").addClass("is-invalid").focus();
|
||||
return;
|
||||
}
|
||||
|
||||
this.set('confirmRestore', '');
|
||||
$("#confirm-restore").removeClass("is-invalid");
|
||||
|
||||
this.modalClose('#confirm-restore-modal');
|
||||
|
||||
// do we have upload file?
|
||||
// let files = document.getElementById("restore-file").files;
|
||||
// if (is.undefined(files) || is.null(files)) {
|
||||
|
@ -111,17 +132,16 @@ export default Component.extend(Notifier, {
|
|||
|
||||
this.get('onRestore')(spec, filedata).then(() => {
|
||||
this.showDone();
|
||||
this.set('buttonLabel', 'Perform Restore');
|
||||
this.set('buttonLabel', 'Restore');
|
||||
this.set('restoreSuccess', true);
|
||||
}, ()=> {
|
||||
this.showDone();
|
||||
this.set('restorButtonLabel', 'Perform Restore');
|
||||
this.set('restorButtonLabel', 'Restore');
|
||||
this.set('restoreFailed', true);
|
||||
});
|
||||
},
|
||||
|
||||
upload(event) {
|
||||
this.set('restoreUploading', true);
|
||||
this.set('restoreUploadReady', false);
|
||||
this.set('restoreFile', null);
|
||||
|
||||
|
@ -130,7 +150,6 @@ export default Component.extend(Notifier, {
|
|||
|
||||
this.set('restoreFile', file);
|
||||
this.set('restoreUploadReady', true);
|
||||
this.set('restoreUploading', false);
|
||||
|
||||
// let imageData;
|
||||
// reader.onload = () => {
|
||||
|
@ -146,3 +165,7 @@ export default Component.extend(Notifier, {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
// {{#ui/ui-checkbox selected=restoreSpec.recreateUsers}}
|
||||
// Recreate user accounts — users, groups, permissions
|
||||
// {{/ui/ui-checkbox}}
|
||||
|
|
|
@ -17,15 +17,11 @@ export default Controller.extend({
|
|||
|
||||
actions: {
|
||||
onBackup(spec) {
|
||||
if(this.get('session.isAdmin')) {
|
||||
return this.get('global').backup(spec);
|
||||
}
|
||||
return this.get('global').backup(spec);
|
||||
},
|
||||
|
||||
onRestore(spec, filedata) {
|
||||
if(this.get('session.isAdmin')) {
|
||||
return this.get('global').restore(spec, filedata);
|
||||
}
|
||||
return this.get('global').restore(spec, filedata);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -144,11 +144,11 @@ export default Service.extend({
|
|||
|
||||
// Run backup.
|
||||
backup(spec) {
|
||||
if (!this.get('sessionService.isGlobalAdmin') || this.get('sessionService.isAdmin')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new EmberPromise((resolve, reject) => {
|
||||
if (!this.get('sessionService.isGlobalAdmin') || !this.get('sessionService.isAdmin')) {
|
||||
reject();
|
||||
}
|
||||
|
||||
let url = this.get('appMeta.endpoint');
|
||||
let token = this.get('sessionService.session.content.authenticated.token');
|
||||
let uploadUrl = `${url}/global/backup?token=${token}`;
|
||||
|
@ -196,6 +196,10 @@ export default Service.extend({
|
|||
data.set('restore-file', file);
|
||||
|
||||
return new EmberPromise((resolve, reject) => {
|
||||
if (!this.get('sessionService.isGlobalAdmin') || !this.get('sessionService.isAdmin')) {
|
||||
reject();
|
||||
}
|
||||
|
||||
let url = this.get('appMeta.endpoint');
|
||||
let token = this.get('sessionService.session.content.authenticated.token');
|
||||
let uploadUrl = `${url}/global/restore?token=${token}&org=${spec.overwriteOrg}&users=${spec.recreateUsers}`;
|
||||
|
|
|
@ -42,10 +42,8 @@
|
|||
<div class="restore-zone">
|
||||
{{#if session.isGlobalAdmin}}
|
||||
<div class="explain">
|
||||
<p class="font-weight-bold">WARNING:</p>
|
||||
<p>
|
||||
You should only perform a restore on a <b>new Documize instance</b> and NOT on the original instance.
|
||||
Duplicate data might exist if you restore onto the same instance without first removing previous data.
|
||||
<p class="font-weight-bold">
|
||||
You should only perform a restore to an empty Documize instance.
|
||||
</p>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
@ -56,22 +54,10 @@
|
|||
<input type="file" class="custom-file-input" id="restore-file" accept="application/zip" multiple=false onchange={{action "upload"}}>
|
||||
<label class="custom-file-label" for="restore-file">Choose backup file</label>
|
||||
</div>
|
||||
<div class="restore-upload-busy">
|
||||
{{#if restoreUploadReady}}
|
||||
<div class="ready">Ready to start restore</div>
|
||||
{{/if}}
|
||||
{{#if restoreUploading}}
|
||||
<img src="/assets/img/busy-gray.gif" />
|
||||
<div class="wait">Uploading file</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="margin-top-20"></div>
|
||||
{{#ui/ui-checkbox selected=restoreSpec.overwriteOrg}}
|
||||
Overwrite settings — SMTP, authentication, integrations and other settings
|
||||
{{/ui/ui-checkbox}}
|
||||
{{#ui/ui-checkbox selected=restoreSpec.recreateUsers}}
|
||||
Recreate user accounts — users, groups, permissions
|
||||
{{/ui/ui-checkbox}}
|
||||
</div>
|
||||
|
||||
{{#if restoreFailed}}
|
||||
|
@ -80,10 +66,30 @@
|
|||
<div class="restore-success">Restore completed — restart your browser and log in</div>
|
||||
{{else}}
|
||||
{{#if restoreUploadReady}}
|
||||
<button class="btn btn-danger mb-3" {{action 'onRestore'}}>{{restoreButtonLabel}}</button>
|
||||
<button class="btn btn-danger mb-3" {{action 'onShowRestoreModal'}}>{{restoreButtonLabel}}</button>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="confirm-restore-modal" class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">Confirm Restore</div>
|
||||
<div class="modal-body">
|
||||
<form onsubmit={{action 'onRestore'}}>
|
||||
<div class="form-group">
|
||||
<label for="delete-space-name">Please type RESTORE to commence the process</label>
|
||||
{{input type='text' id="confirm-restore" class="form-control mousetrap" placeholder="Please type RESTORE" value=confirmRestore}}
|
||||
<small class="form-text text-muted">You should only restore to an empty Documize instance</small>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-danger" onclick={{action 'onRestore'}}>Start Restore</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue