Can update privacy settings

This commit is contained in:
Pierre HUBERT 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);
},

View File

@ -1,4 +1,4 @@
<div class="box box-primary box-export-account-data-settings">
<div class="box box-primary box-data-conservation-policy">
<div class="box-header">
<h3 class="box-title">tr("Data conservation policy")</h3>
</div>
@ -10,18 +10,20 @@
<div class="form-group" v-for="setting in settings">
<label>{{setting.title}}</label>
<select style="width: 100%;" class="form-control select2" v-model="setting.value">
<option v-for="opt in options" v-bind:value="opt.value">{{ opt.label }}</option>
<option v-for="opt in options.filter(v => !v.value || v.value >= setting.minVal)" v-bind:value="opt.value">{{ opt.label }}</option>
</select>
</div>
<!-- Password confirmation -->
<div class="form-group">
<label>Please type your password to update your policy</label>
<label>tr("Please type your password to update your policy")</label>
<div class="input-group" style="width: 100%;">
<input class="form-control" type="password" placeholder="Your password">
<input class="form-control" type="password" placeholder="tr("Your password")" v-model="password">
</div>
</div>
<div class="btn btn-primary">tr("Update settings")</div>
<div style="text-align: center;" v-if="!updating">
<input type="button" class="btn btn-primary" @click="submitUpdate()" value="tr("Update settings")">
</div>
</div>
</div>