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

[vue][app-select] Auth #2961

Merged
merged 2 commits into from
Mar 14, 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
17 changes: 17 additions & 0 deletions frontend/express/public/javascripts/countly/countly.auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@
return validateWrite('d', feature, member, app_id);
};

/**
* validate all types of requests for specific feature on specific app
* @param {string} accessType - write process type [c, r, u, d]
* @param {string} feature - feature name that required access right
* @param {object} member - countly member object
* @param {string} app_id - countly application id
* @return {boolean} result of permission check
*/
countlyAuth.validate = function(accessType, feature, member, app_id) {
if (accessType === "r") {
return countlyAuth.validateRead(feature, member, app_id);
}
else {
return validateWrite(accessType, feature, member, app_id);
}
};

/**
* Validate is this user global admin or not
* @returns {boolean} is this user global admin or not?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, CV, app, countlyEvent, countlyGlobal*/
/* global Vue, CV, app, countlyEvent, countlyGlobal, countlyAuth*/

(function(countlyVue) {

Expand Down Expand Up @@ -447,6 +447,13 @@
type: Number,
default: 0,
required: false
},
auth: {
type: Object,
default: function() {
return {};
},
required: false
}
},
computed: {
Expand All @@ -461,6 +468,24 @@
},
apps: function() {
var apps = countlyGlobal.apps || {};

if (this.auth && this.auth.feature && this.auth.permission) {
var expectedPermission = this.auth.permission,
targetFeature = this.auth.feature;

return Object.keys(apps).reduce(function(acc, key) {
var currentApp = apps[key];

if (countlyAuth.validate(expectedPermission, targetFeature, null, currentApp._id)) {
acc.push({
label: currentApp.name,
value: currentApp._id
});
}
return acc;
}, []);
}

return Object.keys(apps).map(function(key) {
return {
label: apps[key].name,
Expand Down
2 changes: 1 addition & 1 deletion plugins/vue-example/frontend/public/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ <h3>Checkbox group - plain</h3>
</cly-section>
<cly-section title="Helpers (cly-app-select, single)">
<div class="example-cell">
<cly-app-select v-model="selectedApp"></cly-app-select>
<cly-app-select v-model="selectedApp" :auth='{"feature": "drill", "permission": "c"}'></cly-app-select>
<cly-app-select v-model="selectedApp" allow-all></cly-app-select>
</div>
<div class="example-cell">
Expand Down