Skip to content

Commit f08f905

Browse files
authored
Merge pull request #1079 from frknbasaran/server-1561
[server-1561] added user access control for collections from app_rest…
2 parents f745a1a + 5cb9d73 commit f08f905

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

plugins/dbviewer/api/api.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,24 @@ var common = require('../../../api/utils/common.js'),
250250
var apps = [];
251251
if (params.qstring.app_id) {
252252
//if app_id was provided, we need to check if user has access for this app_id
253-
if (params.member.global_admin || (params.member.user_of && params.member.user_of.indexOf(params.qstring.app_id) !== -1)) {
253+
// is user_of array contain current app_id?
254+
var isUserOf = params.member.user_of && params.member.user_of.indexOf(params.qstring.app_id) !== -1;
255+
var isRestricted = params.member.app_restrict && params.member.app_restrict[params.qstring.app_id] && params.member.app_restrict[params.qstring.app_id].indexOf("#/manage/db");
256+
if (params.member.global_admin || isUserOf && !isRestricted) {
254257
apps = [params.qstring.app_id];
255258
}
256259
}
257260
else {
258261
//use whatever user has permission for
259262
apps = params.member.user_of || [];
263+
// also check for app based restrictions
264+
if (params.member.app_restrict) {
265+
for (var app_id in params.member.app_restrict) {
266+
if (params.member.app_restrict[app_id].indexOf("#/manage/db") !== -1 && apps.indexOf(app_id) !== -1) {
267+
apps.splice(apps.indexOf(app_id), 1);
268+
}
269+
}
270+
}
260271
}
261272
var appList = [];
262273
if (collection.indexOf("events") === 0 || collection.indexOf("drill_events") === 0) {

plugins/dbviewer/frontend/public/javascripts/countly.views.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ window.DBViewerView = countlyView.extend({
8383
$('#app-list').prepend('<div data-value="all" class="app-option item" data-localize=""><span class="app-title-in-dropdown">' + $.i18n.map["common.all"] + '</span></div>');
8484
// append list items
8585
for (var key in countlyGlobal.apps) {
86-
$('#app-list').append('<div data-value="' + countlyGlobal.apps[key]._id + '" class="app-option item" data-localize=""><span class="app-title-in-dropdown">' + countlyGlobal.apps[key].name + '</span></div>');
86+
if (!countlyGlobal.member.app_restrict || (countlyGlobal.member.app_restrict && !countlyGlobal.member.app_restrict[key])) {
87+
$('#app-list').append('<div data-value="' + countlyGlobal.apps[key]._id + '" class="app-option item" data-localize=""><span class="app-title-in-dropdown">' + countlyGlobal.apps[key].name + '</span></div>');
88+
}
8789
}
8890
// set height
8991
if ($('#dbviewer').height() < (window.innerHeight - 150)) {

0 commit comments

Comments
 (0)