Can update privacy settings

This commit is contained in:
2021-02-16 18:23:59 +01:00
parent bb81512f2c
commit 73fb50f8ca
3 changed files with 66 additions and 14 deletions

View File

@ -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)
}
}

View File

@ -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);
},