Skip to content
Open
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
59 changes: 48 additions & 11 deletions plugins/dashboards/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var pluginOb = {},
var ejs = require("ejs");

plugins.setConfigs("dashboards", {
sharing_status: true
sharing_status: true,
allow_public_dashboards: true
});

(function() {
Expand Down Expand Up @@ -455,17 +456,24 @@ plugins.setConfigs("dashboards", {
groups = [groups];
}
groups = groups.map(group_id => group_id + "");

var orConditions = [
{owner_id: memberId},
{shared_with_edit: memberId},
{shared_with_view: memberId},
{shared_email_view: memberEmail},
{shared_email_edit: memberEmail},
{shared_user_groups_edit: {$in: groups}},
{shared_user_groups_view: {$in: groups}}
];

var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
if (allowPublicDashboards !== false) {
orConditions.push({share_with: "all-users"});
}

filterCond = {
$or: [
{owner_id: memberId},
{share_with: "all-users"},
{shared_with_edit: memberId},
{shared_with_view: memberId},
{shared_email_view: memberEmail},
{shared_email_edit: memberEmail},
{shared_user_groups_edit: {$in: groups}},
{shared_user_groups_view: {$in: groups}}
]
$or: orConditions
};
}
let projection = {};
Expand Down Expand Up @@ -686,6 +694,12 @@ plugins.setConfigs("dashboards", {
sharedUserGroupView = [];
}

var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
if (shareWith === "all-users" && allowPublicDashboards === false) {
common.returnMessage(params, 400, 'Public dashboards are disabled');
return true;
}

var sharing = checkSharingStatus(params.member, shareWith, sharedEmailEdit, sharedEmailView, sharedUserGroupEdit, sharedUserGroupView);

if (!sharing) {
Expand Down Expand Up @@ -978,6 +992,12 @@ plugins.setConfigs("dashboards", {
sharedUserGroupView = [];
}

var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
if (shareWith === "all-users" && allowPublicDashboards === false) {
common.returnMessage(params, 400, 'Public dashboards are disabled');
return true;
}

common.db.collection("dashboards").findOne({_id: common.db.ObjectID(dashboardId)}, function(err, dashboard) {
if (err || !dashboard) {
common.returnMessage(params, 400, "Dashboard with the given id doesn't exist");
Expand Down Expand Up @@ -1747,6 +1767,16 @@ plugins.setConfigs("dashboards", {
}

if (dashboard.share_with === "all-users") {
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
if (allowPublicDashboards === false) {
if (member._id + "" === dashboard.owner_id) {
return cb(null, true);
}
if (member.global_admin) {
return cb(null, true);
}
return cb(null, false);
}
return cb(null, true);
}

Expand Down Expand Up @@ -1817,6 +1847,13 @@ plugins.setConfigs("dashboards", {
return cb(null, false);
}

if (dashboard.share_with === "all-users") {
var allowPublicDashboards = plugins.getConfig("dashboards").allow_public_dashboards;
if (allowPublicDashboards === false) {
return cb(null, false);
}
}

if ((Array.isArray(dashboard.shared_with_edit) && dashboard.shared_with_edit.indexOf(member._id + "") !== -1) ||
(Array.isArray(dashboard.shared_email_edit) && dashboard.shared_email_edit.indexOf(member.email) !== -1)) {
return cb(null, true);
Expand Down
1 change: 1 addition & 0 deletions plugins/dashboards/frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var countlyFs = require('../../../api/utils/countlyFs.js');

plugin.renderDashboard = function(ob) {
ob.data.countlyGlobal.sharing_status = plugins.getConfig("dashboards").sharing_status;
ob.data.countlyGlobal.allow_public_dashboards = plugins.getConfig("dashboards").allow_public_dashboards;
};

plugin.staticPaths = function(app/*, countlyDb*/) {
Expand Down
47 changes: 28 additions & 19 deletions plugins/dashboards/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,25 +484,6 @@
saveButtonLabel: "",
sharingAllowed: countlyGlobal.sharing_status || AUTHENTIC_GLOBAL_ADMIN,
groupSharingAllowed: countlyGlobal.plugins.indexOf("groups") > -1 && AUTHENTIC_GLOBAL_ADMIN,
constants: {
sharingOptions: [
{
value: "all-users",
name: this.i18nM("dashboards.share.all-users"),
description: this.i18nM("dashboards.share.all-users.description"),
},
{
value: "selected-users",
name: this.i18nM("dashboards.share.selected-users"),
description: this.i18nM("dashboards.share.selected-users.description"),
},
{
value: "none",
name: this.i18nM("dashboards.share.none"),
description: this.i18nM("dashboards.share.none.description"),
}
]
},
sharedEmailEdit: [],
sharedEmailView: [],
sharedGroupEdit: [],
Expand All @@ -511,6 +492,34 @@
};
},
computed: {
constants: function() {
var allSharingOptions = [
{
value: "all-users",
name: this.i18nM("dashboards.share.all-users"),
description: this.i18nM("dashboards.share.all-users.description"),
},
{
value: "selected-users",
name: this.i18nM("dashboards.share.selected-users"),
description: this.i18nM("dashboards.share.selected-users.description"),
},
{
value: "none",
name: this.i18nM("dashboards.share.none"),
description: this.i18nM("dashboards.share.none.description"),
}
];

var allowPublicDashboards = countlyGlobal.allow_public_dashboards !== false;
var sharingOptions = allowPublicDashboards ? allSharingOptions : allSharingOptions.filter(function(option) {
return option.value !== "all-users";
});

return {
sharingOptions: sharingOptions
};
},
canShare: function() {
var canShare = this.sharingAllowed && (this.controls.initialEditedObject.is_owner || AUTHENTIC_GLOBAL_ADMIN);
return canShare;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dashboards.compared-to-prev-period = compared to prev.period

dashboards.sharing_status = Allow Dashboard Sharing
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.
dashboards.allow_public_dashboards = Allow public dashboards
configs.help.dashboards-allow_public_dashboards = Allow sharing dashboards with all Countly dashboard users
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.
dashbaords.access-denied-title = Access Denied
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.
Expand Down
Loading