UNPKG

joola.io.engine

Version:
84 lines (78 loc) 2.45 kB
/** * joola.io * * Copyright Joola Smart Solutions, Ltd. <info@joo.la> * * Licensed under GNU General Public License 3.0 or later. * Some rights reserved. See LICENSE, AUTHORS. * * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> */ var router = require('./index'), url = require('url'), auth = require('../lib/auth/manager'); /** * Lists all available dimensions. You can provide parameters and ask for a specific data source and datatable. * * The returned list will contain only dimensions authorized for the authenticated user. * * @method list * @param {string} [datasourceid] Datasource ID. * @param {string} [datatableid] Datatable ID. * @return {object} json structure listing all dimensions. */ exports.list = { name: 'dashboards/list', description: 'i list all dashboards available', inputs: { required: [], optional: ['datasourceid', 'datatableid'] }, outputExample: {}, permission: ['access_system'], run: function (req, res) { var response = {}; if (!req.user) return router.responseError(new router.AuthErrorTemplate('Missing user token'), req, res); response.dashboards = []; _.each(joola.config.content.dashboards, function (dashboard) { if (auth.hasRole(dashboard.roles, req.user._roles)) response.dashboards.push(dashboard); }); return router.responseSuccess(response, req, res); } }; /** * Lists all available dimensions. You can provide parameters and ask for a specific data source and datatable. * * The returned list will contain only dimensions authorized for the authenticated user. * * @method get * @param {string} [dimensionid] Dimension ID. * @return {object} json structure holding the dimension details. */ exports.get = { name: 'dashboards.get', description: 'i get a specific dashboard', inputs: { required: ['id'], optional: [] }, outputExample: {}, permission: ['access_system'], run: function (req, res) { var response = {}; if (!req.user) return router.responseError(new router.AuthErrorTemplate('Missing user token'), req, res); var _dashboard = _.find(joola.config.content.dashboards, function (dashboard) { return dashboard.id == req.params.id; }); if (_dashboard) { if (auth.hasRole(_dashboard.roles, req.user._roles)) { response.dashboard = _dashboard; } } return router.responseSuccess(response, req, res); } };