UNPKG

2.48 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 url = require('url'),
15 auth = require('../lib/auth/manager');
16
17/**
18 * Lists all available dimensions. You can provide parameters and ask for a specific data source and datatable.
19 *
20 * The returned list will contain only dimensions authorized for the authenticated user.
21 *
22 * @method list
23 * @param {string} [datasourceid] Datasource ID.
24 * @param {string} [datatableid] Datatable ID.
25 * @return {object} json structure listing all dimensions.
26 */
27exports.list = {
28 name: 'reports/list',
29 description: 'i list all reports available',
30 inputs: {
31 required: [],
32 optional: ['datasourceid', 'datatableid']
33 },
34 outputExample: {},
35 permission: ['access_system'],
36 run: function (req, res) {
37 var response = {};
38 if (!req.user)
39 return router.responseError(new router.AuthErrorTemplate('Missing user token'), req, res);
40
41 response.reports = [];
42 _.each(joola.config.content.reports, function (report) {
43 if (auth.hasRole(report.roles, req.user._roles))
44 response.reports.push(report);
45 });
46 return router.responseSuccess(response, req, res);
47 }
48};
49
50/**
51 * Lists all available dimensions. You can provide parameters and ask for a specific data source and datatable.
52 *
53 * The returned list will contain only dimensions authorized for the authenticated user.
54 *
55 * @method get
56 * @param {string} [dimensionid] Dimension ID.
57 * @return {object} json structure holding the dimension details.
58 */
59exports.get = {
60 name: 'reports.get',
61 description: 'i get a specific report',
62 inputs: {
63 required: ['id'],
64 optional: []
65 },
66 outputExample: {},
67 permission: ['access_system'],
68 run: function (req, res) {
69 var response = {};
70 if (!req.user)
71 return router.responseError(new router.AuthErrorTemplate('Missing user token'), req, res);
72
73 var _report = _.find(joola.config.content.reports, function (report) {
74 return report.id == req.params.id;
75 });
76 if (_report) {
77 if (auth.hasRole(_report.roles, req.user._roles)) {
78 response.report = _report;
79 }
80 }
81 return router.responseSuccess(response, req, res);
82 }
83};
\No newline at end of file