Skip to content

Commit 38336e8

Browse files
committed
[UI][app-select] Optional auth
1 parent 53619c5 commit 38336e8

File tree

1 file changed

+34
-1
lines changed
  • frontend/express/public/javascripts/countly/vue/components

1 file changed

+34
-1
lines changed

frontend/express/public/javascripts/countly/vue/components/helpers.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global Vue, CV, app, countlyEvent, countlyGlobal*/
1+
/* global Vue, CV, app, countlyEvent, countlyGlobal, countlyAuth*/
22

33
(function(countlyVue) {
44

@@ -447,6 +447,13 @@
447447
type: Number,
448448
default: 0,
449449
required: false
450+
},
451+
auth: {
452+
type: Object,
453+
default: function() {
454+
return {};
455+
},
456+
required: false
450457
}
451458
},
452459
computed: {
@@ -461,6 +468,32 @@
461468
},
462469
apps: function() {
463470
var apps = countlyGlobal.apps || {};
471+
472+
if (this.auth && this.auth.feature && this.auth.permission) {
473+
var expectedPermission = this.auth.permission,
474+
targetFeature = this.auth.feature;
475+
476+
return Object.keys(apps).reduce(function(acc, key) {
477+
var hasPermission,
478+
currentApp = apps[key];
479+
480+
if (expectedPermission === "r") {
481+
hasPermission = countlyAuth.validateRead(targetFeature, null, currentApp._id);
482+
}
483+
else {
484+
hasPermission = countlyAuth.validateWrite(expectedPermission, targetFeature, null, currentApp._id);
485+
}
486+
487+
if (hasPermission) {
488+
acc.push({
489+
label: currentApp.name,
490+
value: currentApp._id
491+
});
492+
}
493+
return acc;
494+
}, []);
495+
}
496+
464497
return Object.keys(apps).map(function(key) {
465498
return {
466499
label: apps[key].name,

0 commit comments

Comments
 (0)