1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var
|
13 | router = require('./index'),
|
14 |
|
15 | url = require('url'),
|
16 | auth = require('../lib/auth/manager');
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | exports.list = {
|
29 | name: 'dashboards/list',
|
30 | description: 'i list all dashboards available',
|
31 | inputs: {
|
32 | required: [],
|
33 | optional: ['datasourceid', 'datatableid']
|
34 | },
|
35 | outputExample: {},
|
36 | permission: ['access_system'],
|
37 | run: function (req, res) {
|
38 | var response = {};
|
39 | if (!req.user)
|
40 | return router.responseError(new router.AuthErrorTemplate('Missing user token'), req, res);
|
41 |
|
42 | response.dashboards = [];
|
43 | _.each(joola.config.content.dashboards, function (dashboard) {
|
44 | if (auth.hasRole(dashboard.roles, req.user._roles))
|
45 | response.dashboards.push(dashboard);
|
46 | });
|
47 | return router.responseSuccess(response, req, res);
|
48 | }
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | exports.get = {
|
61 | name: 'dashboards.get',
|
62 | description: 'i get a specific dashboard',
|
63 | inputs: {
|
64 | required: ['id'],
|
65 | optional: []
|
66 | },
|
67 | outputExample: {},
|
68 | permission: ['access_system'],
|
69 | run: function (req, res) {
|
70 | var response = {};
|
71 | if (!req.user)
|
72 | return router.responseError(new router.AuthErrorTemplate('Missing user token'), req, res);
|
73 |
|
74 | var _dashboard = _.find(joola.config.content.dashboards, function (dashboard) {
|
75 | return dashboard.id == req.params.id;
|
76 | });
|
77 | if (_dashboard) {
|
78 | if (auth.hasRole(_dashboard.roles, req.user._roles)) {
|
79 | response.dashboard = _dashboard;
|
80 | }
|
81 | }
|
82 | return router.responseSuccess(response, req, res);
|
83 | }
|
84 | }; |
\ | No newline at end of file |