Skip to content

Commit

Permalink
Merge pull request advplyr#3122 from nichwall/backup_field_prevent_ed…
Browse files Browse the repository at this point in the history
…its_with_env

Prevent backup path edits when ENV is set
  • Loading branch information
advplyr authored Jul 5, 2024
2 parents 0461b57 + 7c0b4e3 commit 3a2f786
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/components/tables/BackupsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default {
this.$axios
.$get('/api/backups')
.then((data) => {
this.$emit('loaded', data.backupLocation)
this.$emit('loaded', data)
this.setBackups(data.backups || [])
})
.catch((error) => {
Expand Down
18 changes: 12 additions & 6 deletions client/pages/config/backups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
</div>
<div v-else>
<form class="flex items-center w-full space-x-1" @submit.prevent="saveBackupPath">
<ui-text-input v-model="newBackupLocation" :disabled="savingBackupPath" class="w-full max-w-[calc(100%-50px)] text-sm h-8" />
<ui-btn small :loading="savingBackupPath" color="success" type="submit" class="h-8">{{ $strings.ButtonSave }}</ui-btn>
<ui-text-input v-model="newBackupLocation" :disabled="savingBackupPath || !canEditBackup" class="w-full max-w-[calc(100%-50px)] text-sm h-8" />
<ui-btn v-if="canEditBackup" small :loading="savingBackupPath" color="success" type="submit" class="h-8">{{ $strings.ButtonSave }}</ui-btn>
<ui-btn small :disabled="savingBackupPath" type="button" class="h-8" @click="cancelEditBackupPath">{{ $strings.ButtonCancel }}</ui-btn>
</form>
<p class="text-sm text-warning/80 pt-1">{{ $strings.MessageBackupsLocationEditNote }}</p>
<p class="text-sm text-warning/80 pt-1">{{ canEditBackup ? $strings.MessageBackupsLocationEditNote : $strings.MessageBackupsLocationNoEditNote }}</p>
</div>
</div>

Expand Down Expand Up @@ -92,6 +92,7 @@ export default {
newServerSettings: {},
showCronBuilder: false,
showEditBackupPath: false,
backupPathEnvSet: false,
backupLocation: '',
newBackupLocation: '',
savingBackupPath: false
Expand All @@ -115,6 +116,10 @@ export default {
timeFormat() {
return this.serverSettings.timeFormat
},
canEditBackup() {
// Prevent editing of backup path if an environment variable is set
return !this.backupPathEnvSet
},
scheduleDescription() {
if (!this.cronExpression) return ''
const parsed = this.$parseCronExpression(this.cronExpression)
Expand All @@ -127,9 +132,10 @@ export default {
}
},
methods: {
backupsLoaded(backupLocation) {
this.backupLocation = backupLocation
this.newBackupLocation = backupLocation
backupsLoaded(data) {
this.backupLocation = data.backupLocation
this.newBackupLocation = data.backupLocation
this.backupPathEnvSet = data.backupPathEnvSet
},
cancelEditBackupPath() {
this.newBackupLocation = this.backupLocation
Expand Down
1 change: 1 addition & 0 deletions client/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@
"MessageAppriseDescription": "To use this feature you will need to have an instance of <a href=\"https://github.com/caronc/apprise-api\" target=\"_blank\">Apprise API</a> running or an api that will handle those same requests. <br />The Apprise API Url should be the full URL path to send the notification, e.g., if your API instance is served at <code>http://192.168.1.1:8337</code> then you would put <code>http://192.168.1.1:8337/notify</code>.",
"MessageBackupsDescription": "Backups include users, user progress, library item details, server settings, and images stored in <code>/metadata/items</code> & <code>/metadata/authors</code>. Backups <strong>do not</strong> include any files stored in your library folders.",
"MessageBackupsLocationEditNote": "Note: Updating the backup location will not move or modify existing backups",
"MessageBackupsLocationNoEditNote": "Note: The backup location is set through an environment variable and cannot be changed here.",
"MessageBackupsLocationPathEmpty": "Backup location path cannot be empty",
"MessageBatchQuickMatchDescription": "Quick Match will attempt to add missing covers and metadata for the selected items. Enable the options below to allow Quick Match to overwrite existing covers and/or metadata.",
"MessageBookshelfNoCollections": "You haven't made any collections yet",
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/BackupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class BackupController {
getAll(req, res) {
res.json({
backups: this.backupManager.backups.map((b) => b.toJSON()),
backupLocation: this.backupManager.backupPath
backupLocation: this.backupManager.backupPath,
backupPathEnvSet: this.backupManager.backupPathEnvSet
})
}

Expand Down
4 changes: 4 additions & 0 deletions server/managers/BackupManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class BackupManager {
return global.ServerSettings.backupPath
}

get backupPathEnvSet() {
return !!process.env.BACKUP_PATH
}

get backupSchedule() {
return global.ServerSettings.backupSchedule
}
Expand Down

0 comments on commit 3a2f786

Please sign in to comment.