Merge pull request #2569 from Computroniks/bug/2565-negative-retention-value

Fixed negative retention time values
pull/2575/head
Louis Lam 2 years ago committed by GitHub
commit 439f963749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,6 +25,10 @@ const DEFAULT_KEEP_PERIOD = 180;
parsedPeriod = DEFAULT_KEEP_PERIOD;
}
if (parsedPeriod < 1) {
log(`Data deletion has been disabled as period is less than 1. Period is ${parsedPeriod} days.`);
} else {
log(`Clearing Data older than ${parsedPeriod} days...`);
try {
@ -35,6 +39,7 @@ const DEFAULT_KEEP_PERIOD = 180;
} catch (e) {
log(`Failed to clear old data: ${e.message}`);
}
}
exit();
})();

@ -7,6 +7,7 @@
settings.keepDataPeriodDays,
])
}}
{{ $t("infiniteRetention") }}
</label>
<input
id="keepDataPeriodDays"
@ -14,9 +15,12 @@
type="number"
class="form-control"
required
min="1"
min="0"
step="1"
/>
<div v-if="settings.keepDataPeriodDays < 0" class="form-text">
{{ $t("dataRetentionTimeError") }}
</div>
</div>
<div class="my-4">
<button class="btn btn-primary" type="button" @click="saveSettings()">

@ -675,4 +675,6 @@ export default {
"General Monitor Type": "General Monitor Type",
"Passive Monitor Type": "Passive Monitor Type",
"Specific Monitor Type": "Specific Monitor Type",
dataRetentionTimeError: "Retention period must be 0 or greater",
infiniteRetention: "Set to 0 for infinite retention.",
};

@ -189,6 +189,8 @@ export default {
* @param {string} [currentPassword] Only need for disableAuth to true
*/
saveSettings(callback, currentPassword) {
let valid = this.validateSettings();
if (valid.success) {
this.$root.getSocket().emit("setSettings", this.settings, currentPassword, (res) => {
this.$root.toastRes(res);
this.loadSettings();
@ -197,6 +199,26 @@ export default {
callback();
}
});
} else {
this.$root.toastError(valid.msg);
}
},
/**
* Ensure settings are valid
* @returns {Object} Contains success state and error msg
*/
validateSettings() {
if (this.settings.keepDataPeriodDays < 0) {
return {
success: false,
msg: this.$t("dataRetentionTimeError"),
};
}
return {
success: true,
msg: "",
};
},
}
};

Loading…
Cancel
Save