| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:57:40 -04:00
										 |  |  | // options allowed to be updated directly in settings 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-03-30 13:56:46 -04:00
										 |  |  | async function getAllSettings() { | 
					
						
							|  |  |  |     return await sql.getMap("SELECT name, value FROM options"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 13:56:46 -04:00
										 |  |  | async function getAllowedSettings() { | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |     const settings = 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-03-30 13:56:46 -04:00
										 |  |  |     return settings; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-14 23:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 13:56:46 -04:00
										 |  |  | async function updateSetting(req) { | 
					
						
							| 
									
										
										
										
											2017-10-24 22:58:59 -04:00
										 |  |  |     const body = req.body; | 
					
						
							| 
									
										
										
										
											2018-01-28 21:57:46 -05:00
										 |  |  |     const sourceId = req.headers.source_id; | 
					
						
							| 
									
										
										
										
											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 13:56:46 -04:00
										 |  |  |     await options.setOption(body['name'], body['value'], sourceId); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     getAllowedSettings, | 
					
						
							|  |  |  |     getAllSettings, | 
					
						
							|  |  |  |     updateSetting | 
					
						
							|  |  |  | }; |