Skip to content

Commit 6576a55

Browse files
committed
feat: add setting to disable public dashboards
1 parent 272db17 commit 6576a55

File tree

4 files changed

+88
-30
lines changed

4 files changed

+88
-30
lines changed

plugins/dashboards/api/api.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var pluginOb = {},
1717
var ejs = require("ejs");
1818

1919
plugins.setConfigs("dashboards", {
20-
sharing_status: true
20+
sharing_status: true,
21+
allow_public_dashboards: true
2122
});
2223

2324
(function() {
@@ -455,17 +456,25 @@ plugins.setConfigs("dashboards", {
455456
groups = [groups];
456457
}
457458
groups = groups.map(group_id => group_id + "");
459+
460+
var orConditions = [
461+
{owner_id: memberId},
462+
{shared_with_edit: memberId},
463+
{shared_with_view: memberId},
464+
{shared_email_view: memberEmail},
465+
{shared_email_edit: memberEmail},
466+
{shared_user_groups_edit: {$in: groups}},
467+
{shared_user_groups_view: {$in: groups}}
468+
];
469+
470+
// Only include all-users dashboards if public dashboards are allowed
471+
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
472+
if (allowPublicDashboards !== false) {
473+
orConditions.push({share_with: "all-users"});
474+
}
475+
458476
filterCond = {
459-
$or: [
460-
{owner_id: memberId},
461-
{share_with: "all-users"},
462-
{shared_with_edit: memberId},
463-
{shared_with_view: memberId},
464-
{shared_email_view: memberEmail},
465-
{shared_email_edit: memberEmail},
466-
{shared_user_groups_edit: {$in: groups}},
467-
{shared_user_groups_view: {$in: groups}}
468-
]
477+
$or: orConditions
469478
};
470479
}
471480
let projection = {};
@@ -686,6 +695,13 @@ plugins.setConfigs("dashboards", {
686695
sharedUserGroupView = [];
687696
}
688697

698+
// Check if public dashboards are disabled
699+
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
700+
if (shareWith === "all-users" && allowPublicDashboards === false) {
701+
common.returnMessage(params, 400, 'Public dashboards are disabled');
702+
return true;
703+
}
704+
689705
var sharing = checkSharingStatus(params.member, shareWith, sharedEmailEdit, sharedEmailView, sharedUserGroupEdit, sharedUserGroupView);
690706

691707
if (!sharing) {
@@ -978,6 +994,13 @@ plugins.setConfigs("dashboards", {
978994
sharedUserGroupView = [];
979995
}
980996

997+
// Check if public dashboards are disabled
998+
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
999+
if (shareWith === "all-users" && allowPublicDashboards === false) {
1000+
common.returnMessage(params, 400, 'Public dashboards are disabled');
1001+
return true;
1002+
}
1003+
9811004
common.db.collection("dashboards").findOne({_id: common.db.ObjectID(dashboardId)}, function(err, dashboard) {
9821005
if (err || !dashboard) {
9831006
common.returnMessage(params, 400, "Dashboard with the given id doesn't exist");
@@ -1747,6 +1770,19 @@ plugins.setConfigs("dashboards", {
17471770
}
17481771

17491772
if (dashboard.share_with === "all-users") {
1773+
// Check if public dashboards are allowed
1774+
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
1775+
if (allowPublicDashboards === false) {
1776+
// If public dashboards are disabled, only owner can access
1777+
if (member._id + "" === dashboard.owner_id) {
1778+
return cb(null, true);
1779+
}
1780+
// Global admins can still access
1781+
if (member.global_admin) {
1782+
return cb(null, true);
1783+
}
1784+
return cb(null, false);
1785+
}
17501786
return cb(null, true);
17511787
}
17521788

@@ -1817,6 +1853,15 @@ plugins.setConfigs("dashboards", {
18171853
return cb(null, false);
18181854
}
18191855

1856+
// Check if public dashboards are disabled
1857+
if (dashboard.share_with === "all-users") {
1858+
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
1859+
if (allowPublicDashboards === false) {
1860+
// If public dashboards are disabled, no edit access for non-owners
1861+
return cb(null, false);
1862+
}
1863+
}
1864+
18201865
if ((Array.isArray(dashboard.shared_with_edit) && dashboard.shared_with_edit.indexOf(member._id + "") !== -1) ||
18211866
(Array.isArray(dashboard.shared_email_edit) && dashboard.shared_email_edit.indexOf(member.email) !== -1)) {
18221867
return cb(null, true);

plugins/dashboards/frontend/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var countlyFs = require('../../../api/utils/countlyFs.js');
1010

1111
plugin.renderDashboard = function(ob) {
1212
ob.data.countlyGlobal.sharing_status = plugins.getConfig("dashboards").sharing_status;
13+
ob.data.countlyGlobal.allow_public_dashboards = plugins.getConfig("dashboards").allow_public_dashboards;
1314
};
1415

1516
plugin.staticPaths = function(app/*, countlyDb*/) {

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -484,25 +484,6 @@
484484
saveButtonLabel: "",
485485
sharingAllowed: countlyGlobal.sharing_status || AUTHENTIC_GLOBAL_ADMIN,
486486
groupSharingAllowed: countlyGlobal.plugins.indexOf("groups") > -1 && AUTHENTIC_GLOBAL_ADMIN,
487-
constants: {
488-
sharingOptions: [
489-
{
490-
value: "all-users",
491-
name: this.i18nM("dashboards.share.all-users"),
492-
description: this.i18nM("dashboards.share.all-users.description"),
493-
},
494-
{
495-
value: "selected-users",
496-
name: this.i18nM("dashboards.share.selected-users"),
497-
description: this.i18nM("dashboards.share.selected-users.description"),
498-
},
499-
{
500-
value: "none",
501-
name: this.i18nM("dashboards.share.none"),
502-
description: this.i18nM("dashboards.share.none.description"),
503-
}
504-
]
505-
},
506487
sharedEmailEdit: [],
507488
sharedEmailView: [],
508489
sharedGroupEdit: [],
@@ -511,6 +492,35 @@
511492
};
512493
},
513494
computed: {
495+
constants: function() {
496+
var allSharingOptions = [
497+
{
498+
value: "all-users",
499+
name: this.i18nM("dashboards.share.all-users"),
500+
description: this.i18nM("dashboards.share.all-users.description"),
501+
},
502+
{
503+
value: "selected-users",
504+
name: this.i18nM("dashboards.share.selected-users"),
505+
description: this.i18nM("dashboards.share.selected-users.description"),
506+
},
507+
{
508+
value: "none",
509+
name: this.i18nM("dashboards.share.none"),
510+
description: this.i18nM("dashboards.share.none.description"),
511+
}
512+
];
513+
514+
// Filter out "all-users" option if public dashboards are disabled
515+
var allowPublicDashboards = countlyGlobal.allow_public_dashboards !== false;
516+
var sharingOptions = allowPublicDashboards ? allSharingOptions : allSharingOptions.filter(function(option) {
517+
return option.value !== "all-users";
518+
});
519+
520+
return {
521+
sharingOptions: sharingOptions
522+
};
523+
},
514524
canShare: function() {
515525
var canShare = this.sharingAllowed && (this.controls.initialEditedObject.is_owner || AUTHENTIC_GLOBAL_ADMIN);
516526
return canShare;

plugins/dashboards/frontend/public/localization/dashboards.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ dashboards.compared-to-prev-period = compared to prev.period
4545

4646
dashboards.sharing_status = Allow Dashboard Sharing
4747
configs.help.dashboards-sharing_status = Enable dashboard sharing for users to share a dashboard with other users. If set to off, dashboards cannot be shared with others.
48+
dashboards.allow_public_dashboards = Allow public dashboards
49+
configs.help.dashboards-allow_public_dashboards = Allow sharing dashboards with all Countly dashboard users
4850
dashboards.access-denied = This dashboard is no longer shared with you or an error has occurred. Please ask your global administrator if you think this is due to an issue.
4951
dashbaords.access-denied-title = Access Denied
5052
dashboards.edit-access-denied = You don't have the edit permission for this dashboard. Please ask your global administrator if you think this is due to an issue.

0 commit comments

Comments
 (0)