Skip to content

Commit 3825dde

Browse files
committed
[crud-context] various fixes.
- events permissions moved to "events" feature from "core" - added at least one app validation to user create process. - added desktop, mobile and web analytics sublinks under "core" feature. - and other things.
1 parent 5caad15 commit 3825dde

File tree

9 files changed

+95
-59
lines changed

9 files changed

+95
-59
lines changed

api/utils/requestProcessor.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ const processRequest = (params) => {
739739
common.returnMessage(params, 400, 'Missing parameter "app_id"');
740740
return false;
741741
}
742-
validateUpdate(params, 'core', function() {
742+
validateUpdate(params, 'events', function() {
743743
common.db.collection('events').findOne({"_id": common.db.ObjectID(params.qstring.app_id)}, function(err, event) {
744744
if (err) {
745745
common.returnMessage(params, 400, err);
@@ -1000,7 +1000,7 @@ const processRequest = (params) => {
10001000
}
10011001
case 'delete_events':
10021002
{
1003-
validateDelete(params, 'core', function() {
1003+
validateDelete(params, 'events', function() {
10041004
var idss = [];
10051005
try {
10061006
idss = JSON.parse(params.qstring.events);
@@ -1122,7 +1122,7 @@ const processRequest = (params) => {
11221122
}
11231123
case 'change_visibility':
11241124
{
1125-
validateUpdate(params, 'core', function() {
1125+
validateUpdate(params, 'events', function() {
11261126
common.db.collection('events').findOne({"_id": common.db.ObjectID(params.qstring.app_id)}, function(err, event) {
11271127
if (err) {
11281128
common.returnMessage(params, 400, err);
@@ -1954,6 +1954,7 @@ const processRequest = (params) => {
19541954
}
19551955
else {
19561956
params.truncateEventValuesList = true;
1957+
19571958
validateRead(params, 'core', countlyApi.data.fetch.prefetchEventData, params.qstring.method);
19581959
}
19591960
}

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
};
145145

146146
countlyAuth.renderFeatureTemplate = function(featureName, index) {
147-
if (featureName === 'core') return '';
148147
var odd = countlyAuth.odd;
149148
countlyAuth.odd = !countlyAuth.odd;
150149
var beautifiedFeatureName = featureBeautifier(featureName);
@@ -227,7 +226,12 @@
227226
permissionObject[permissionType].all = processFlag;
228227
for (var i = 0; i < countlyAuth.features.length; i++) {
229228
if (countlyAuth.features[i] === 'core') continue;
230-
permissionObject[permissionType].allowed[countlyAuth.features[i]] = processFlag;
229+
if (processFlag) {
230+
permissionObject[permissionType].allowed[countlyAuth.features[i]] = processFlag;
231+
}
232+
else {
233+
delete permissionObject[permissionType].allowed[countlyAuth.features[i]];
234+
}
231235
}
232236
return permissionObject;
233237
};
@@ -292,17 +296,21 @@
292296
$(parent_el + ' #mark-all-' + countlyAuth.typeNames[j] + '-' + i).countlyCheckbox().set(true);
293297

294298
for (var k = 0; k < countlyAuth.features.length; k++) {
295-
if (countlyAuth.features[k] === 'core') continue;
296299
$(parent_el + ' #' + countlyAuth.types[j] + '-' + countlyAuth.features[k] + '-' + i).countlyCheckbox().set(true);
300+
if (countlyAuth.features[k] === 'core') {
301+
$(parent_el + ' #' + countlyAuth.types[j] + '-' + countlyAuth.features[k] + '-' + i).countlyCheckbox().setDisabled();
302+
}
297303
}
298304

299305
permission_sets[i][countlyAuth.types[j]].all = true;
300306
}
301307
else {
302308
for (var feature in permission_object[countlyAuth.types[j]][user_apps[i][0]].allowed) {
303-
if (feature === 'core') continue;
304309
permission_sets[i] = countlyAuth.giveFeaturePermission(countlyAuth.types[j], feature, permission_sets[i]);
305310
$(parent_el + ' #' + countlyAuth.types[j] + '-' + feature + '-' + i).countlyCheckbox().set(true);
311+
if (feature === 'core') {
312+
$(parent_el + ' #' + countlyAuth.types[j] + '-' + feature + '-' + i).countlyCheckbox().setDisabled();
313+
}
306314
}
307315
}
308316
}

frontend/express/public/javascripts/countly/countly.template.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,12 @@ var AppRouter = Backbone.Router.extend({
13491349
self.addMenu("understand", {code: "engagement", text: "sidebar.engagement", icon: '<div class="logo ion-happy-outline"></div>', priority: 30});
13501350
self.addMenu("understand", {code: "events", text: "sidebar.events", icon: '<div class="logo events"><i class="material-icons">bubble_chart</i></div>', priority: 40});
13511351
self.addSubMenu("events", {code: "events-overview", url: "#/analytics/events/overview", text: "sidebar.events.overview", priority: 10});
1352-
self.addSubMenu("events", {code: "all-events", url: "#/analytics/events", text: "sidebar.events.all-events", priority: 20});
1353-
if (countlyAuth.validateUpdate('core') || countlyAuth.validateDelete('core')) {
1352+
if (countlyAuth.validateRead('events')) {
1353+
self.addSubMenu("events", {code: "all-events", url: "#/analytics/events", text: "sidebar.events.all-events", priority: 20});
1354+
}
1355+
if (countlyAuth.validateUpdate('events') || countlyAuth.validateDelete('events')) {
13541356
self.addSubMenu("events", {code: "manage-events", url: "#/analytics/manage-events", text: "sidebar.events.blueprint", priority: 100});
13551357
}
1356-
13571358
self.addMenu("utilities", {
13581359
code: "management",
13591360
text: "sidebar.utilities",
@@ -1368,7 +1369,7 @@ var AppRouter = Backbone.Router.extend({
13681369
if (countlyAuth.validateRead('core')) {
13691370
self.addSubMenu("management", {code: "longtasks", url: "#/manage/tasks", text: "sidebar.management.longtasks", priority: 10});
13701371
}
1371-
1372+
13721373
var jobsIconSvg = '<svg width="20px" height="16px" viewBox="0 0 12 10" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>list-24px 2</title><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="list-24px-2" fill="#9f9f9f" fill-rule="nonzero"><g id="list-24px"><path d="M0,6 L2,6 L2,4 L0,4 L0,6 Z M0,10 L2,10 L2,8 L0,8 L0,10 Z M0,2 L2,2 L2,0 L0,0 L0,2 Z M3,6 L12,6 L12,4 L3,4 L3,6 Z M3,10 L12,10 L12,8 L3,8 L3,10 Z M3,0 L3,2 L12,2 L12,0 L3,0 Z" id="Shape"></path></g></g></g></svg>';
13731374
if (countlyAuth.validateRead('global_applications')) {
13741375
self.addMenu("management", {code: "applications", url: "#/manage/apps", text: "sidebar.management.applications", icon: '<div class="logo-icon ion-ios-albums"></div>', priority: 10});

frontend/express/public/javascripts/countly/countly.views.js

+45-20
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,7 @@ window.DurationView = countlyView.extend({
20212021
});
20222022

20232023
window.ManageAppsView = countlyView.extend({
2024+
featureName: 'global_applications',
20242025
initialize: function() {
20252026
this.template = Handlebars.compile($("#template-management-applications").html());
20262027
this.templatePlugins = Handlebars.compile($("#template-management-plugins").html());
@@ -2047,9 +2048,10 @@ window.ManageAppsView = countlyView.extend({
20472048
renderCommon: function() {
20482049
var appTypes = {}, self = this;
20492050
var adminApps = countlyAuth.getAdminApps();
2051+
var userApps = countlyAuth.getUserApps();
20502052
var oAdminApps = [];
2051-
for (var i = 0; i < adminApps.length; i++) {
2052-
oAdminApps.push(countlyGlobal.apps[adminApps[i]]);
2053+
for (var j = 0; j < userApps.length; j++) {
2054+
oAdminApps.push(countlyGlobal.apps[userApps[j]]);
20532055
}
20542056
var j = 0;
20552057
for (j in app.appTypes) {
@@ -2201,22 +2203,14 @@ window.ManageAppsView = countlyView.extend({
22012203
function initAppManagement(app_id) {
22022204
var adminApps = countlyAuth.getAdminApps();
22032205
var userApps = countlyAuth.getUserApps();
2206+
22042207
if (userApps.length === 0) {
2205-
showAdd();
22062208
firstApp();
22072209
$("body").off("click", "#save-first-app-add").on("click", "#save-first-app-add", function() {
22082210
saveApp();
22092211
});
22102212
return false;
22112213
}
2212-
else if (countlyAuth.validateCreate('global_applications')) {
2213-
showAdd();
2214-
$("body").off("click", "#save-app-add").on("click", "#save-app-add", function() {
2215-
saveApp();
2216-
});
2217-
store.set('first_app', false);
2218-
return false;
2219-
}
22202214
else {
22212215
$('#content').css({"width": "", "height": "", "margin-left": "", "margin-top": ""});
22222216
store.set('first_app', false);
@@ -2231,13 +2225,6 @@ window.ManageAppsView = countlyView.extend({
22312225
});
22322226
}
22332227

2234-
if (adminApps.indexOf(app_id) !== -1) {
2235-
$("#app-delete-button").addClass("inactive");
2236-
}
2237-
else {
2238-
$("#app-delete-button").removeClass("inactive");
2239-
}
2240-
22412228
$("body").off("click", "#save-app-add").on("click", "#save-app-add", function() {
22422229
saveApp();
22432230
});
@@ -2480,6 +2467,34 @@ window.ManageAppsView = countlyView.extend({
24802467
});
24812468
});
24822469
app.localize($("#content"));
2470+
2471+
var hasDeleteRight = countlyAuth.validateDelete(self.featureName, countlyGlobal.member, app_id);
2472+
var hasUpdateRight = countlyAuth.validateUpdate(self.featureName, countlyGlobal.member, app_id);
2473+
2474+
if (hasDeleteRight) {
2475+
$("#app-delete-button").show();
2476+
$('#app-clear-button').show();
2477+
$('#app-reset-button').show();
2478+
}
2479+
else {
2480+
$("#app-delete-button").hide();
2481+
$('#app-clear-button').hide();
2482+
$('#app-reset-button').hide();
2483+
}
2484+
2485+
if (hasUpdateRight) {
2486+
$("#app-edit-button").show();
2487+
$('#app-lock-button').show();
2488+
}
2489+
else {
2490+
$("#app-edit-button").show();
2491+
$('#app-lock-button').show();
2492+
}
2493+
2494+
if (!hasDeleteRight && !hasUpdateRight) {
2495+
$('#view-app .cly-button-menu-trigger').hide();
2496+
}
2497+
24832498
}
24842499
/** initializes country select
24852500
* @param {object} parent - select parent element
@@ -2861,6 +2876,7 @@ window.ManageAppsView = countlyView.extend({
28612876
}
28622877

28632878
if (!countlyGlobal.member.global_admin && $.isEmptyObject(countlyGlobal.apps) && $.isEmptyObject(countlyGlobal.admin_apps) && !countlyGlobal.config.autonomous) {
2879+
console.log('no auth for app manage screen');
28642880
prepareUnauthorizeScreen();
28652881
}
28662882
else {
@@ -3808,6 +3824,7 @@ window.ManageUsersView = countlyView.extend({
38083824
// Events handlers
38093825
$('body').off('click', '.manage-users-options-item .show-edit-menu').on('click', '.manage-users-options-item .show-edit-menu', function() {
38103826
var that = this;
3827+
$('.edit-menu').hide();
38113828
$('.manage-users-menu-' + $(this).data('id')).show();
38123829
setTimeout(function() {
38133830
$('.manage-users-menu-' + $(that).data('id')).fadeOut();
@@ -4032,7 +4049,6 @@ window.ManageUsersView = countlyView.extend({
40324049
for (var i = 0; i < self.features.length; i++) {
40334050
if (self.features[i] === 'core') continue;
40344051
$('.create-user-drawer #' + type.substr(0, 1) + '-' + self.features[i] + '-' + index).countlyCheckbox().set(true);
4035-
//$('.create-user-drawer #' + type.substr(0, 1) + '-' + self.features[i] + '-' + index).countlyCheckbox().setDisabled();
40364052
}
40374053

40384054
self.permissionSets[index] = countlyAuth.updatePermissionByType(type.substr(0, 1), self.permissionSets[index], true);
@@ -4041,7 +4057,6 @@ window.ManageUsersView = countlyView.extend({
40414057
for (var j = 0; j < self.features.length; j++) {
40424058
if (self.features[j] === 'core') continue;
40434059
$('.create-user-drawer #' + type.substr(0, 1) + '-' + self.features[j] + '-' + index).countlyCheckbox().set(false);
4044-
//$('.create-user-drawer #' + type.substr(0, 1) + '-' + self.features[j] + '-' + index).countlyCheckbox().unsetDisabled();
40454060
}
40464061

40474062
self.permissionSets[index] = countlyAuth.updatePermissionByType(type.substr(0, 1), self.permissionSets[index], false);
@@ -4144,6 +4159,16 @@ window.ManageUsersView = countlyView.extend({
41444159
return;
41454160
}
41464161

4162+
if (self.memberModel.permission._.u[0].length === 0 && self.memberModel.permission._.a.length === 0) {
4163+
CountlyHelpers.notify({
4164+
type: 'warning',
4165+
delay: 3000,
4166+
title: 'Validation error',
4167+
message: $.i18n.map['management-users.at-least-one-app-required']
4168+
});
4169+
return;
4170+
}
4171+
41474172
if (!self.memberModel.global_admin) {
41484173
//self.memberModel.admin_of = currUserDetails.find(".admin-apps .app-list").val().split(",");
41494174
//self.memberModel.user_of = currUserDetails.find(".user-apps .app-list").val().split(",");

frontend/express/public/localization/dashboard/dashboard.properties

+1
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ management-users.full-name-required = Full name area should be filled
738738
management-users.username-required = Username area should be filled
739739
management-users.email-required = E-mail area should be filled
740740
management-users.email-invalid-format = Please check your email format
741+
management-users.at-least-one-app-required = User should have permission for at least one app
741742

742743
#user-settings
743744
user-settings.username = Username

plugins/desktop/frontend/public/javascripts/countly.views.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ app.addAppType("desktop", DesktopDashboardView);
319319
app.desktopDashboardView = new DesktopDashboardView();
320320

321321
$(document).ready(function() {
322-
if (countlyAuth.validateRead(app.desktopDashboardView.featureName)) {
322+
if (countlyAuth.validateRead('core')) {
323323
app.addSubMenuForType("desktop", "analytics", {code: "analytics-platforms", url: "#/analytics/platforms", text: "sidebar.analytics.platforms", priority: 80});
324324
app.addSubMenuForType("desktop", "analytics", {code: "analytics-versions", url: "#/analytics/versions", text: "sidebar.analytics.app-versions", priority: 60});
325325
app.addSubMenuForType("desktop", "analytics", {code: "analytics-resolutions", url: "#/analytics/resolutions", text: "sidebar.analytics.resolutions", priority: 50});

plugins/mobile/frontend/public/javascripts/countly.views.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ app.addAppManagementSwitchCallback(function(appId, type) {
334334
});
335335

336336
$(document).ready(function() {
337-
if (countlyAuth.validateRead(app.mobileDashboardView.featureName)) {
337+
if (countlyAuth.validateRead('core')) {
338338
app.addSubMenuForType("mobile", "analytics", {code: "analytics-platforms", url: "#/analytics/platforms", text: "sidebar.analytics.platforms", priority: 80});
339339
app.addSubMenuForType("mobile", "analytics", {code: "analytics-carriers", url: "#/analytics/carriers", text: "sidebar.analytics.carriers", priority: 70});
340340
app.addSubMenuForType("mobile", "analytics", {code: "analytics-versions", url: "#/analytics/versions", text: "sidebar.analytics.app-versions", priority: 60});

plugins/plugins/frontend/public/javascripts/countly.views.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1694,35 +1694,35 @@ if (countlyAuth.validateRead(app.configurationsView.featureName)) {
16941694
this.renderWhenReady(this.configurationsView);
16951695
}
16961696
});
1697-
}
1698-
1699-
app.route('/manage/user-settings', 'user-settings', function() {
1700-
this.configurationsView.namespace = null;
1701-
this.configurationsView.reset = false;
1702-
this.configurationsView.userConfig = true;
1703-
this.configurationsView.success = false;
1704-
this.renderWhenReady(this.configurationsView);
1705-
});
17061697

1707-
app.route('/manage/user-settings/:namespace', 'user-settings_namespace', function(namespace) {
1708-
if (namespace === "reset") {
1709-
this.configurationsView.reset = true;
1710-
this.configurationsView.success = false;
1698+
app.route('/manage/user-settings', 'user-settings', function() {
17111699
this.configurationsView.namespace = null;
1712-
}
1713-
else if (namespace === "success") {
1714-
this.configurationsView.reset = false;
1715-
this.configurationsView.success = true;
1716-
this.configurationsView.namespace = null;
1717-
}
1718-
else {
17191700
this.configurationsView.reset = false;
1701+
this.configurationsView.userConfig = true;
17201702
this.configurationsView.success = false;
1721-
this.configurationsView.namespace = namespace;
1722-
}
1723-
this.configurationsView.userConfig = true;
1724-
this.renderWhenReady(this.configurationsView);
1725-
});
1703+
this.renderWhenReady(this.configurationsView);
1704+
});
1705+
1706+
app.route('/manage/user-settings/:namespace', 'user-settings_namespace', function(namespace) {
1707+
if (namespace === "reset") {
1708+
this.configurationsView.reset = true;
1709+
this.configurationsView.success = false;
1710+
this.configurationsView.namespace = null;
1711+
}
1712+
else if (namespace === "success") {
1713+
this.configurationsView.reset = false;
1714+
this.configurationsView.success = true;
1715+
this.configurationsView.namespace = null;
1716+
}
1717+
else {
1718+
this.configurationsView.reset = false;
1719+
this.configurationsView.success = false;
1720+
this.configurationsView.namespace = namespace;
1721+
}
1722+
this.configurationsView.userConfig = true;
1723+
this.renderWhenReady(this.configurationsView);
1724+
});
1725+
}
17261726

17271727
$(document).ready(function() {
17281728
if (countlyGlobal.member && countlyGlobal.member.global_admin || countlyAuth.validateRead(app.pluginsView.featureName)) {

plugins/web/frontend/public/javascripts/countly.views.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ app.addAppManagementSwitchCallback(function(appId, type) {
508508
app.webDashboardView = new WebDashboardView();
509509

510510
$(document).ready(function() {
511-
if (countlyAuth.validateRead(app.webDashboardView.featureName)) {
511+
if (countlyAuth.validateRead('core')) {
512512
app.addSubMenuForType("web", "analytics", {code: "analytics-platforms", url: "#/analytics/platforms", text: "sidebar.analytics.platforms", priority: 80});
513513
app.addSubMenuForType("web", "analytics", {code: "analytics-versions", url: "#/analytics/versions", text: "sidebar.analytics.app-versions", priority: 60});
514514
app.addSubMenuForType("web", "analytics", {code: "analytics-resolutions", url: "#/analytics/resolutions", text: "sidebar.analytics.resolutions", priority: 50});

0 commit comments

Comments
 (0)