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

Prevent adding duplicate dashlet if present with same name and label #20375

Merged
merged 1 commit into from
Jun 3, 2021
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
3 changes: 1 addition & 2 deletions CRM/Core/BAO/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ public static function addDashlet(&$params) {
$dashlet->domain_id = $params['domain_id'] ?? CRM_Core_Config::domainID();

// Try and find an existing dashlet - it will be updated if found.
if (!empty($params['name']) || !empty($params['url'])) {
if (!empty($params['name'])) {
$dashlet->name = $params['name'] ?? NULL;
$dashlet->url = $params['url'] ?? NULL;
$dashlet->find(TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the overall issue, but am wondering if this is a typo: setting $dashlet->url to equal $params['label'] ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing this, was a typo on my end :/ Updated the patch now.

Copy link
Member

@colemanw colemanw Jun 2, 2021

Choose a reason for hiding this comment

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

Why would we search for existing dashlets by label? Labels are not guaranteed to be unique.

The existing code has this legacy quirk where even if you don't pass an id it will still attempt to update based on name or url. Removing the matching on url feels like a good step forward. It removes half of the legacy behavior (which IMO would be nice to get rid of completely). But then this PR adds label in, which feels like a step backwards toward more legacy behavior. Can we just do name matching only?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm agree, updated the patch. Can you please check now?

}
}
Expand Down