Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sidebar] permission check #2869

Merged
merged 3 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/upgrade/22.02/upgrade_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ then
#disable old plugins
countly plugin disable EChartMap
countly plugin disable restrict
countly plugin disable assistant
fi

#run upgrade scripts
Expand Down
1 change: 1 addition & 0 deletions bin/upgrade/22.02/upgrade_fs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ then
#disable old plugins
countly plugin disable EChartMap
countly plugin disable restrict
countly plugin disable assistant

#get web sdk
countly update sdk-web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(function(countlyVue, $) {

$(document).ready(function() {
var _featureMapper = {
/*var _featureMapper = {
"overview": "core",
"analytics": "core",
"events": "events",
Expand Down Expand Up @@ -63,45 +63,32 @@
"overview": ["core"],
"analytics": ["core"],
"management": ["populator", "config_transfer", "crashes", "blocks", "logger", "compliance_hub"]
};
};*/

/**
* Check feature permission before adding sidebar
* @memberof app
* @param {string} code - code text of menu item
* @param {string} permission - permission name
* @returns {boolean} - true if permission granted
**/
var checkMenuPermission = function(code) {
if (_menuDependencies[code] && _menuDependencies[code].length) {
var granted = false;
for (var i = 0; i < _menuDependencies[code].length; i++) {
if (_menuDependencies[code][i] !== "admin" && countlyAuth.validateRead(_menuDependencies[code][i])) {
granted = true;
break;
}
else if (_menuDependencies[code][i] === "admin" && countlyAuth.validateGlobalAdmin()) {
granted = true;
break;
}
}
return granted;
var checkMenuPermission = function(permission) {
if (permission) {
return countlyAuth.validateRead(permission);
}
return checkSubMenuPermission(code);
return countlyAuth.validateGlobalAdmin();
};

/**
* Check feature permission before adding sidebar
* @memberof app
* @param {string} code - code text of menu item
* @param {string} permission - permission name
* @returns {boolean} - true if permission granted
**/
var checkSubMenuPermission = function(code) {
if (_featureMapper[code] !== "admin") {
return countlyAuth.validateRead(_featureMapper[code]);
}
else {
return countlyAuth.validateGlobalAdmin();
var checkSubMenuPermission = function(permission) {
if (permission) {
return countlyAuth.validateRead(permission);
}
return countlyAuth.validateGlobalAdmin();
};

var AppsMixin = {
Expand Down Expand Up @@ -272,7 +259,7 @@
}
var self = this;
var menus = this.menus.reduce(function(acc, val) {
if (val.app_type === self.activeApp.type && checkMenuPermission(val.name)) {
if (val.app_type === self.activeApp.type && checkMenuPermission(val.permission)) {
if (!acc[val.category]) {
acc[val.category] = [];
}
Expand All @@ -289,7 +276,7 @@
}
var self = this;
var submenus = this.submenus.reduce(function(acc, val) {
if (val.app_type === self.activeApp.type && checkSubMenuPermission(val.name)) {
if (val.app_type === self.activeApp.type && checkSubMenuPermission(val.permission)) {
if (!acc[val.parent_code]) {
acc[val.parent_code] = [];
}
Expand Down