diff --git a/assets/js/components/settings/interface.js b/assets/js/components/settings/interface.js index c58186f8..2aacd220 100644 --- a/assets/js/components/settings/interface.js +++ b/assets/js/components/settings/interface.js @@ -194,6 +194,25 @@ const SettingsInterface = { */ getDataConservationPolicy: async function() { return await api("settings/get_data_conservation_policy", null, true); + }, + + /** + * Update data conservation password + * + * @param {DataConservationPolicy} policy New policy + * @param {String} password User password + */ + setDataConservationPolicy: async function(policy, password) { + let data = { + password: password + } + + for (let key in policy) { + if (policy.hasOwnProperty(key)) + data[key] = policy[key] + } + + await api("settings/set_data_conservation_policy", data, true) } } diff --git a/assets/js/pages/settings/sections/privacy.js b/assets/js/pages/settings/sections/privacy.js index 857e55ef..adba61bb 100644 --- a/assets/js/pages/settings/sections/privacy.js +++ b/assets/js/pages/settings/sections/privacy.js @@ -96,7 +96,7 @@ const SettingsPrivacySection = { // Load server policy await ServerConfig.ensureLoaded(); - const serverPolicy = ServerConfig.conf; + const serverPolicy = ServerConfig.conf.data_conservation_policy; // Use Vue const oneDay = 60 * 60 * 24; @@ -115,7 +115,7 @@ const SettingsPrivacySection = { let findOptionIndex = (value) => { if (!value) return lifetimeOptions[0].value; - return [...lifetimeOptions].reverse().find(v => v.value <= value).value + return lifetimeOptions.find(v => v.value >= value).value } const DataConservationPolicyVueApp = { @@ -127,41 +127,72 @@ const SettingsPrivacySection = { title: tr("Automatically delete unread notification after"), key: "notification_lifetime", value: findOptionIndex(settings.notification_lifetime), + minVal: serverPolicy.min_notification_lifetime, }, { title: tr("Automatically delete your comments after"), key: "comments_lifetime", - value: findOptionIndex(settings.comments_lifetime) + value: findOptionIndex(settings.comments_lifetime), + minVal: serverPolicy.min_comments_lifetime, }, { title: tr("Automatically delete your posts after"), key: "posts_lifetime", - value: findOptionIndex(settings.posts_lifetime) + value: findOptionIndex(settings.posts_lifetime), + minVal: serverPolicy.min_posts_lifetime, }, { title: tr("Automatically delete your conversation messages after"), key: "conversation_messages_lifetime", - value: findOptionIndex(settings.conversation_messages_lifetime) + value: findOptionIndex(settings.conversation_messages_lifetime), + minVal: serverPolicy.min_conversation_messages_lifetime, }, { title: tr("Automatically delete your likes after"), key: "likes_lifetime", - value: findOptionIndex(settings.likes_lifetime) + value: findOptionIndex(settings.likes_lifetime), + minVal: serverPolicy.min_likes_lifetime, }, { title: tr("Automatically delete your account if you have been inactive for"), key: "inactive_account_lifetime", - value: findOptionIndex(settings.inactive_account_lifetime) + value: findOptionIndex(settings.inactive_account_lifetime), + minVal: serverPolicy.min_inactive_account_lifetime, } - ] + ], + password: "", + updating: false, + } + }, + + methods: { + async submitUpdate() { + try { + if (this.password.length < 3) + return notify(tr("Please specify your password !"), "danger") + + let newSettings = {} + for (let el of this.settings) + newSettings[el.key] = el.value; + + this.updating = true; + await SettingsInterface.setDataConservationPolicy(newSettings, this.password) + } + + catch (e) { + console.error(e) + notify(tr("Failed to update data conservation policy!"), "danger"); + } + + this.updating = false } } - } + }; Vue.createApp(DataConservationPolicyVueApp).mount(el); }, diff --git a/assets/templates/pages/settings/privacy/ConservationPolicy.html b/assets/templates/pages/settings/privacy/ConservationPolicy.html index ec18a409..414bfc5f 100644 --- a/assets/templates/pages/settings/privacy/ConservationPolicy.html +++ b/assets/templates/pages/settings/privacy/ConservationPolicy.html @@ -1,4 +1,4 @@ -
+

tr("Data conservation policy")

@@ -10,18 +10,20 @@
- +
- +
-
tr("Update settings")
+
+ +
\ No newline at end of file