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

Ensure Dashboard respects multiple Domains #15099

Merged
merged 1 commit into from
Aug 30, 2019
Merged
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
15 changes: 10 additions & 5 deletions CRM/Core/BAO/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static function getContactDashlets($contactID = NULL) {
'contact_id' => $contactID,
'is_active' => 1,
'dashboard_id.is_active' => 1,
'dashboard_id.domain_id' => CRM_Core_Config::domainID(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christianwach do we need to cope with dashboards that don't have a domain_id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 There should always be a domain_id assigned to each dashlet when they are created. Personally I'd consider dashlets without a domain_id to be orphaned.

'options' => ['sort' => 'weight', 'limit' => 0],
'return' => [
'id',
Expand Down Expand Up @@ -143,7 +144,7 @@ public static function getContactDashlets($contactID = NULL) {
// If empty, then initialize default dashlets for this user.
if (!$results['count']) {
// They may just have disabled all their dashlets. Check if any records exist for this contact.
if (!civicrm_api3('DashboardContact', 'getcount', ['contact_id' => $contactID])) {
if (!civicrm_api3('DashboardContact', 'getcount', ['contact_id' => $contactID, 'dashboard_id.domain_id' => CRM_Core_Config::domainID()])) {
$dashlets = self::initializeDashlets();
}
}
Expand Down Expand Up @@ -388,7 +389,13 @@ public static function addDashlet(&$params) {
$dashlet = new CRM_Core_DAO_Dashboard();

if (!$dashboardID) {
// check url is same as exiting entries, if yes just update existing

// Assign domain before search to allow identical dashlets in different domains.
if (empty($params['domain_id'])) {
$dashlet->domain_id = CRM_Core_Config::domainID();
}

// Try and find an existing dashlet - it will be updated if found.
if (!empty($params['name'])) {
$dashlet->name = CRM_Utils_Array::value('name', $params);
$dashlet->find(TRUE);
Expand All @@ -397,9 +404,7 @@ public static function addDashlet(&$params) {
$dashlet->url = CRM_Utils_Array::value('url', $params);
$dashlet->find(TRUE);
}
if (empty($params['domain_id'])) {
$dashlet->domain_id = CRM_Core_Config::domainID();
}

}
else {
$dashlet->id = $dashboardID;
Expand Down