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