Skip to content

Commit f9163a6

Browse files
authoredMar 14, 2022
Merge pull request #2961 from Countly/can/feature/new-ui
[vue][app-select] Auth
2 parents 4ed232e + 4e87db5 commit f9163a6

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed
 

‎frontend/express/public/javascripts/countly/countly.auth.js

+17
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@
168168
return validateWrite('d', feature, member, app_id);
169169
};
170170

171+
/**
172+
* validate all types of requests for specific feature on specific app
173+
* @param {string} accessType - write process type [c, r, u, d]
174+
* @param {string} feature - feature name that required access right
175+
* @param {object} member - countly member object
176+
* @param {string} app_id - countly application id
177+
* @return {boolean} result of permission check
178+
*/
179+
countlyAuth.validate = function(accessType, feature, member, app_id) {
180+
if (accessType === "r") {
181+
return countlyAuth.validateRead(feature, member, app_id);
182+
}
183+
else {
184+
return validateWrite(accessType, feature, member, app_id);
185+
}
186+
};
187+
171188
/**
172189
* Validate is this user global admin or not
173190
* @returns {boolean} is this user global admin or not?

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

+26-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,24 @@
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 currentApp = apps[key];
478+
479+
if (countlyAuth.validate(expectedPermission, targetFeature, null, currentApp._id)) {
480+
acc.push({
481+
label: currentApp.name,
482+
value: currentApp._id
483+
});
484+
}
485+
return acc;
486+
}, []);
487+
}
488+
464489
return Object.keys(apps).map(function(key) {
465490
return {
466491
label: apps[key].name,

‎plugins/vue-example/frontend/public/templates/form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ <h3>Checkbox group - plain</h3>
317317
</cly-section>
318318
<cly-section title="Helpers (cly-app-select, single)">
319319
<div class="example-cell">
320-
<cly-app-select v-model="selectedApp"></cly-app-select>
320+
<cly-app-select v-model="selectedApp" :auth='{"feature": "drill", "permission": "c"}'></cly-app-select>
321321
<cly-app-select v-model="selectedApp" allow-all></cly-app-select>
322322
</div>
323323
<div class="example-cell">

0 commit comments

Comments
 (0)
Please sign in to comment.