UNPKG

2.54 kBJavaScriptView Raw
1/**
2 * joola.io
3 *
4 * Copyright Joola Smart Solutions, Ltd. <info@joo.la>
5 *
6 * Licensed under GNU General Public License 3.0 or later.
7 * Some rights reserved. See LICENSE, AUTHORS.
8 *
9 * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
10 */
11
12var
13 router = require('./index'),
14
15 url = require('url'),
16 auth = require('../lib/auth/manager');
17
18/**
19 * Lists all available dimensions. You can provide parameters and ask for a specific data source and datatable.
20 *
21 * The returned list will contain only dimensions authorized for the authenticated user.
22 *
23 * @method list
24 * @param {string} [datasourceid] Datasource ID.
25 * @param {string} [datatableid] Datatable ID.
26 * @return {object} json structure listing all dimensions.
27 */
28exports.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 * Lists all available dimensions. You can provide parameters and ask for a specific data source and datatable.
53 *
54 * The returned list will contain only dimensions authorized for the authenticated user.
55 *
56 * @method get
57 * @param {string} [dimensionid] Dimension ID.
58 * @return {object} json structure holding the dimension details.
59 */
60exports.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