2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-16 07:47:05 +08:00
|
|
|
const sql = require('../../services/sql');
|
2017-11-03 08:48:02 +08:00
|
|
|
const options = require('../../services/options');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2017-11-05 07:57:40 +08:00
|
|
|
// options allowed to be updated directly in settings dialog
|
2018-03-26 08:52:38 +08:00
|
|
|
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
async function getAllSettings() {
|
|
|
|
return await sql.getMap("SELECT name, value FROM options");
|
|
|
|
}
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
async function getAllowedSettings() {
|
2018-01-29 08:30:14 +08:00
|
|
|
const settings = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
|
2017-11-05 07:57:40 +08:00
|
|
|
+ ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS);
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
return settings;
|
|
|
|
}
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
async function updateSetting(req) {
|
2017-10-25 10:58:59 +08:00
|
|
|
const body = req.body;
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
if (!ALLOWED_OPTIONS.includes(body['name'])) {
|
|
|
|
return [400, "not allowed option to set"];
|
2017-10-15 11:31:44 +08:00
|
|
|
}
|
|
|
|
|
2018-03-31 07:41:54 +08:00
|
|
|
await options.setOption(body['name'], body['value']);
|
2018-03-31 01:56:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getAllowedSettings,
|
|
|
|
getAllSettings,
|
|
|
|
updateSetting
|
|
|
|
};
|