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

update permission control #2960

Merged
merged 3 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
5 changes: 5 additions & 0 deletions plugins/alerts/frontend/public/javascripts/countly.models.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
context.dispatch("countlyAlerts/table/fetchAll", null, {root: true});
},
saveAlert: function(context, alertConfig) {
delete alertConfig._canUpdate;
delete alertConfig._canDelete;
return CV.$.ajax({
type: "GET",
url: countlyCommon.API_PARTS.data.w + "/alert/save",
Expand Down Expand Up @@ -205,6 +207,9 @@
});
},
saveOnlineUsersAlert: function(context, alertConfig) {
delete alertConfig._canUpdate;
delete alertConfig._canDelete;

return CV.$.ajax({
type: "GET",
url: countlyCommon.API_PARTS.data.w + "/concurrent_alert/save",
Expand Down
13 changes: 11 additions & 2 deletions plugins/hooks/frontend/public/javascripts/countly.models.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
CV,
countlyVue,
countlyGlobal,
countlyAuth,
_,
moment,
*/

(function(hooksPlugin, jQuery) {
var FEATURE_NAME = "hooks";
var countlyCommon = window.countlyCommon;


Expand Down Expand Up @@ -197,8 +199,11 @@
dataType: "json",
success: function(data) {
if (data.hooksList && data.hooksList.length === 1) {
data.hooksList[0].triggerEffectDom = hooksPlugin.generateTriggerActionsTreeDom(data.hooksList[0]);
context.commit("setDetail", data.hooksList[0]);
var record = data.hooksList[0];
record.triggerEffectDom = hooksPlugin.generateTriggerActionsTreeDom(record);
record._canUpdate = countlyAuth.validateUpdate(FEATURE_NAME, countlyGlobal.member, record.apps[0]),
record._canDelete = countlyAuth.validateDelete(FEATURE_NAME, countlyGlobal.member, record.apps[0]),
context.commit("setDetail", record);
context.commit("setDetailLogsInitialized", true);
}
},
Expand All @@ -208,6 +213,8 @@
context.dispatch("countlyHooks/table/fetchAll", null, {root: true});
},
saveHook: function(context, record) {
delete record._canUpdate;
delete record._canDelete;
return CV.$.ajax({
type: "POST",
url: countlyCommon.API_PARTS.data.w + "/hook/save?" + "app_id=" + record.apps[0],
Expand Down Expand Up @@ -335,6 +342,8 @@
created_at: hookList[i].created_at || 0,
created_at_string: moment(hookList[i].created_at).fromNow(),
triggerEffectColumn: triggerEffectDom || "",
_canUpdate: countlyAuth.validateUpdate(FEATURE_NAME, countlyGlobal.member, hookList[i].apps[0]),
_canDelete: countlyAuth.validateDelete(FEATURE_NAME, countlyGlobal.member, hookList[i].apps[0]),
});
}
context.commit("setInitialized", true);
Expand Down
4 changes: 3 additions & 1 deletion plugins/hooks/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
value: "lastTriggerTimestampString",
label: CV.i18n('hooks.trigger-last-time'),
default: true
}]
}],
tablePersistKey: "hooks_table_" + countlyCommon.ACTIVE_APP_ID,

};
},
methods: {
Expand Down
6 changes: 3 additions & 3 deletions plugins/hooks/frontend/public/templates/vue-hooks-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ <h3>{{hookDetail.name}}</h3>
</template>
<template v-slot:header-right>
<div>
<div class="is-option-button" v-if="canUserUpdate || canUserDelete">
<div class="is-option-button" v-if="hookDetail._canUpdate || hookDetail._canDelete">
<cly-more-options size="small" @command="handleHookEditCommand($event, hookDetail)">
<el-dropdown-item icon="el-icon-document-copy" v-if="canUserUpdate" command="edit-comment">
<el-dropdown-item icon="el-icon-document-copy" v-if="hookDetail._canUpdate" command="edit-comment">
Edit
</el-dropdown-item>
<el-dropdown-item icon="el-icon-delete" v-if="canUserDelete" command="delete-comment">
<el-dropdown-item icon="el-icon-delete" v-if="hookDetail._canDelete" command="delete-comment">
Delete
</el-dropdown-item>
</cly-more-options>
Expand Down
11 changes: 6 additions & 5 deletions plugins/hooks/frontend/public/templates/vue-table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<cly-section>
<cly-datatable-n
:force-loading="!initialized"
:persist-key="tablePersistKey"
class="cly-vue-hook-table is-clickable"
:tracked-fields="localTableTrackedFields"
:rows="tableRows" :resizable="false"
Expand Down Expand Up @@ -28,7 +29,7 @@
<template v-slot="rowScope">
<el-switch :value="rowScope.row.enabled"
class="bu-ml-4 bu-mr-2"
:disabled="!canUserUpdate"
:disabled="!rowScope.row._canUpdate"
@input="scope.patch(rowScope.row, {enabled: !rowScope.row.enabled})">
</el-switch>
</template>
Expand Down Expand Up @@ -79,13 +80,13 @@
</div>
</template>
</el-table-column>
<el-table-column type="options" v-if="canUserUpdate || canUserDelete" >
<el-table-column type="options">
<template v-slot="rowScope">
<cly-more-options v-if="rowScope.row.hover" size="small" @command="handleHookEditCommand($event,rowScope)">
<el-dropdown-item v-if="canUserUpdate" icon="el-icon-document-copy" command="edit-comment">
<cly-more-options v-if="rowScope.row.hover &&(rowScope.row._canUpdate || rowScope.row._canDelete)" size="small" @command="handleHookEditCommand($event,rowScope)">
<el-dropdown-item v-if="rowScope.row._canUpdate" icon="el-icon-document-copy" command="edit-comment">
{{i18n('hooks.edit')}}
</el-dropdown-item>
<el-dropdown-item v-if="canUserDelete" icon="el-icon-delete" command="delete-comment">
<el-dropdown-item v-if="rowScope.row._canDelete" icon="el-icon-delete" command="delete-comment">
{{i18n('hooks.delete')}}
</el-dropdown-item>
</cly-more-options>
Expand Down
17 changes: 17 additions & 0 deletions plugins/reports/frontend/public/javascripts/countly.models.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*global
countlyCommon,
countlyGlobal,
countlyAuth,
jQuery,
CV,
CountlyHelpers,
countlyVue,
app,
*/
(function(countlyReporting, $) {
var FEATURE_NAME = "reports";
//Private Properties
var _data = {};
var _metrics = [
Expand Down Expand Up @@ -179,6 +181,8 @@
});
},
saveReport: function(context, args) {
delete args._canUpdate;
delete args._canDelete;
return CV.$.ajax({
type: "GET",
url: countlyCommon.API_PARTS.data.w + "/reports/" + (args._id ? "update" : "create"),
Expand Down Expand Up @@ -290,6 +294,17 @@
ret = ret.substring(0, ret.length - 2);

ret += " for " + data[i].appNames.join(", ");

data[i]._canUpdate = true;
data[i]._canDelete = true;
for (var aIdx = 0; aIdx < data[i].apps.length; aIdx++) {
if (!countlyAuth.validateUpdate(FEATURE_NAME, countlyGlobal.member, data[i].apps[aIdx])) {
data[i]._canUpdate = false;
}
if (!countlyAuth.validateDelete(FEATURE_NAME, countlyGlobal.member, data[i].apps[aIdx])) {
data[i]._canDelete = false;
}
}
}
else if (!data[i].pluginEnabled) {
ret = jQuery.i18n.prop("reports.enable-plugin", data[i].report_type);
Expand All @@ -308,6 +323,8 @@
}
}
ret = "Dashboard " + (dashboard.name || "");
data[i]._canUpdate = countlyAuth.validateUpdate(FEATURE_NAME, countlyGlobal.member, countlyCommon.ACTIVE_APP_ID);
data[i]._canDelete = countlyAuth.validateDelete(FEATURE_NAME, countlyGlobal.member, countlyCommon.ACTIVE_APP_ID);
}
data[i].dataColumn = ret;

Expand Down
6 changes: 3 additions & 3 deletions plugins/reports/frontend/public/templates/vue-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2> {{i18n('reports.title')}}
<template v-slot="scope">
<el-table-column type="switch" fixed="left" width="88" prop="enabled">
<template v-slot="rowScope">
<el-switch :value="rowScope.row.enabled" class="bu-ml-4 bu-mr-2" :disabled="!canUserUpdate"
<el-switch :value="rowScope.row.enabled" class="bu-ml-4 bu-mr-2" :disabled="!rowScope.row._canUpdate"
@input="scope.patch(rowScope.row, {enabled: !rowScope.row.enabled})">
</el-switch>
</template>
Expand Down Expand Up @@ -84,7 +84,7 @@ <h2> {{i18n('reports.title')}}
<el-table-column type="options">
<template v-slot="rowScope">
<cly-more-options v-if="rowScope.row.hover" size="small" @command="handleReportEditCommand($event,rowScope)">
<el-dropdown-item v-if="canUserUpdate" icon="el-icon-document-copy" command="edit-comment">
<el-dropdown-item v-if="rowScope.row._canUpdate" icon="el-icon-document-copy" command="edit-comment">
Edit
</el-dropdown-item>
<el-dropdown-item icon="el-icon-position" command="send-comment">
Expand All @@ -93,7 +93,7 @@ <h2> {{i18n('reports.title')}}
<el-dropdown-item icon="el-icon-chat-dot-square" command="preview-comment">
Preview
</el-dropdown-item>
<el-dropdown-item v-if="canUserDelete" icon="el-icon-delete" command="delete-comment">
<el-dropdown-item v-if="rowScope.row._canDelete" icon="el-icon-delete" command="delete-comment">
Delete
</el-dropdown-item>
</cly-more-options>
Expand Down