File size: 1,449 Bytes
56b6519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module.exports = function (app) {
  var Response = require('../lib/httpResponse.js');
  var acl = require('../lib/auth').acl;
  var Settings = require('mongoose').model('Settings');

  app.get(
    '/api/settings',
    acl.hasPermission('settings:read'),
    function (req, res) {
      Settings.getAll()
        .then(settings => Response.Ok(res, settings))
        .catch(err => Response.Internal(res, err));
    },
  );

  app.get(
    '/api/settings/public',
    acl.hasPermission('settings:read-public'),
    function (req, res) {
      Settings.getPublic()
        .then(settings => Response.Ok(res, settings))
        .catch(err => Response.Internal(res, err));
    },
  );

  app.put(
    '/api/settings',
    acl.hasPermission('settings:update'),
    function (req, res) {
      Settings.update(req.body)
        .then(msg => Response.Ok(res, msg))
        .catch(err => Response.Internal(res, err));
    },
  );

  app.put(
    '/api/settings/revert',
    acl.hasPermission('settings:update'),
    function (req, res) {
      Settings.restoreDefaults()
        .then(msg => Response.Ok(res, msg))
        .catch(err => Response.Internal(res, err));
    },
  );

  app.get(
    '/api/settings/export',
    acl.hasPermission('settings:read'),
    function (req, res) {
      Settings.getAll()
        .then(settings => Response.SendFile(res, 'app-settings.json', settings))
        .catch(err => Response.Internal(res, err));
    },
  );
};