Skip to content

Commit cf228bf

Browse files
authored
Merge pull request #7128 from Countly/anna/master
[SER-2763] (Pentest)Filter out apps when updating widget based on user rights.
2 parents 6bdf279 + 4375e2b commit cf228bf

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

plugins/dashboards/api/api.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var pluginOb = {},
1212
localize = require('../../../api/utils/localization.js'),
1313
async = require('async'),
1414
mail = require("../../../api/parts/mgmt/mail"),
15-
{ validateUser } = require('../../../api/utils/rights.js');
15+
{ validateUser, getUserApps, getAdminApps} = require('../../../api/utils/rights.js');
1616

1717
var ejs = require("ejs");
1818

@@ -1205,6 +1205,24 @@ plugins.setConfigs("dashboards", {
12051205
widget.contenthtml = sanitizeNote(widget.contenthtml);
12061206
}
12071207

1208+
//Filter out app_ids that current users does not have access to
1209+
if (widget.apps && Array.isArray(widget.apps)) {
1210+
var user_apps = getUserApps(params.member) || [];
1211+
var admin_apps = getAdminApps(params.member) || [];
1212+
widget.apps = widget.apps.filter(appId => {
1213+
if (params.member.global_admin) {
1214+
return true;
1215+
}
1216+
else if (user_apps && user_apps.indexOf(appId) !== -1) {
1217+
return true;
1218+
}
1219+
else if (admin_apps && admin_apps.indexOf(appId) !== -1) {
1220+
return true;
1221+
}
1222+
return false;
1223+
});
1224+
}
1225+
12081226
common.db.collection("dashboards").findOne({_id: common.db.ObjectID(dashboardId)}, function(err, dashboard) {
12091227
if (err || !dashboard) {
12101228
common.returnMessage(params, 400, "Dashboard with the given id doesn't exist");
@@ -1287,6 +1305,24 @@ plugins.setConfigs("dashboards", {
12871305
common.returnMessage(params, 400, 'Invalid parameter: widget_id');
12881306
return true;
12891307
}
1308+
//Filter out app_ids that current users does not have access to
1309+
if (widget.apps && Array.isArray(widget.apps)) {
1310+
var user_apps = getUserApps(params.member) || [];
1311+
var admin_apps = getAdminApps(params.member) || [];
1312+
widget.apps = widget.apps.filter(appId => {
1313+
if (params.member.global_admin) {
1314+
return true;
1315+
}
1316+
else if (user_apps && user_apps.indexOf(appId) !== -1) {
1317+
return true;
1318+
}
1319+
else if (admin_apps && admin_apps.indexOf(appId) !== -1) {
1320+
return true;
1321+
}
1322+
return false;
1323+
});
1324+
}
1325+
12901326

12911327
common.db.collection("dashboards").findOne({_id: common.db.ObjectID(dashboardId), widgets: {$in: [common.db.ObjectID(widgetId)]}}, function(err, dashboard) {
12921328
if (err || !dashboard) {

0 commit comments

Comments
 (0)