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

dev/core#2426 Fix regression whereby the dashboard crashes (permission related) #19694

Merged
merged 2 commits into from
Mar 2, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Feb 28, 2021

Overview

Per https://lab.civicrm.org/dev/core/-/issues/2426 a user without the permission to see their own contact record will experience crashes on the main civicrm page as the code to load their dashlets uses setCheckPermissions(TRUE) (implicitly) which (implicitly) requires them to be able to view their own contact record.

Before

fatal error loading main civicrm screen for users with no access to view their own contact record

After

tada

Technical Details

As noted in the code comments this was not my preferred technical fix but I do lean
towards using this in the rc & reconsidering the other approaches in master (not least because I think we have a couple of other regressions to focus on and because this manefests differently in master)

Comments

With this patch I can add appropriate dashlets on 5.35 to a user with no ability to see their own contact record. However, on dmaster adding them results in a new error (@totten @colemanw @seamuslee001 ).

image

@civibot
Copy link

civibot bot commented Feb 28, 2021

(Standard links)

@eileenmcnaughton
Copy link
Contributor Author

@colemanw did you see this one? It threw up a lot of thoughts for me - but I'm inclined to consider those outside of getting the regression fixed

@sunilpawar
Copy link
Contributor

@eileenmcnaughton

Dashlet add loading on dahsboard, but when you try to delete it from dashabord.

its giving permission issue.
CRM_Contact_BAO_DashboardContact::checkEditPermission

$record = Array
(
    [dashboard_id] => 1
    [id] => 202
    [is_active] => 
    [contact_id] => 202
    [check_permissions] => 1
)

here id become contact id, instead it should be primary id of civicrm_dashboard_contact table.

in checkEditPermission function, we trying to get contact id based on `id' field value, so it refere to wrong record

Also if ($cid != CRM_Core_Session::getLoggedInContactID()) { get passed since $cid is empty.


when dashboard is loading , format of the output with your patch is like

Array
        (
            [id] => 1
            [domain_id] => 1
            [name] => blog
            [label] => CiviCRM News
            [url] => civicrm/dashlet/blog?reset=1
            [permission] => Array
                (
                    [0] => access CiviCRM
                )

            [permission_operator] => 
            [fullscreen_url] => civicrm/dashlet/blog?reset=1&context=dashletFullscreen
            [is_active] => 1
            [is_reserved] => 1
            [cache_minutes] => 1440
            [directive] => 
            [dashboard_contact.id] => 202
            [dashboard_contact.weight] => 0
            [dashboard_contact.column_no] => 1
            [dashboard_contact.is_active] => 1
        )

Somewhere dashboard_contact.id converted to id

foreach ($results as $item) {
$item['dashboard_contact.id'] = $contactDashboards[$item['id']]['contact_id'] ?? NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah - this line - @sunilpawar do you want to try changing this to

$item['dashboard_contact.contact_id'] = $contactDashboards[$item['id']]['contact_id'] ?? NULL;
$item['dashboard_contact.id'] = $contactDashboards[$item['id']]['id'] ?? NULL;

If that works I'll push it up

Copy link
Contributor

@sunilpawar sunilpawar left a comment

Choose a reason for hiding this comment

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

@eileenmcnaughton ,

Replaced :
$item['dashboard_contact.id'] = $contactDashboards[$item['id']]['contact_id'] ?? NULL;

with
$item['dashboard_contact.id'] = $contactDashboards[$item['id']]['id'] ?? NULL; $item['dashboard_contact.contact_id'] = $contactDashboards[$item['id']]['contact_id'] ?? NULL;

It working for me ...

foreach ($results as $item) {
$item['dashboard_contact.id'] = $contactDashboards[$item['id']]['contact_id'] ?? NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

This resolve issue with DB Errror and permission issue when we delete dashlet from contact dashboard

 $item['dashboard_contact.id'] = $contactDashboards[$item['id']]['id'] ?? NULL;
 $item['dashboard_contact.contact_id'] = $contactDashboards[$item['id']]['contact_id'] ?? NULL;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @sunilpawar - I've pushed it up

…ts unable to view their own contact record.

As noted in the code comments this was not my preferred technical fix but I do lean
towards using this in the rc & reconsidering the other approaches in master.

Also, in master I got a different error that I think related to new work
@sunilpawar
Copy link
Contributor

@eileenmcnaughton i have tested all changes again, its works perfectly ..

@colemanw colemanw merged commit 8d916ef into civicrm:5.35 Mar 2, 2021
@colemanw colemanw deleted the dash branch March 2, 2021 13:43
@colemanw
Copy link
Member

colemanw commented Mar 2, 2021

Thanks for reviewing @sunilpawar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants