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

[REF] Use Standard function cacheClause to re-use contact acl cache t… #17707

Merged

Conversation

seamuslee001
Copy link
Contributor

…able

Overview

This refactors the CRM_Contact_BAO_Query functions to utilise the cacheClause function which joins on the acl_contact_cache table rather than re-running the ACL where clause again

Before

Doesn't use acl cache contact table

After

Uses ACL cache contact table

ping @kcristiano @eileenmcnaughton @colemanw

@civibot
Copy link

civibot bot commented Jun 29, 2020

(Standard links)

@civibot civibot bot added the master label Jun 29, 2020
@@ -176,7 +176,7 @@ public function testPrevNextCache() {
'expected_query' => [
0 => 'default',
1 => 'default',
2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' ) AND ( 1 )",
2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' ) AND contact_a.is_deleted = 0",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is_deleted suggests the contact in the test does not have permission to view deleted contacts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the cacheClause function was not respecting the view deleted contacts permission

@seamuslee001
Copy link
Contributor Author

Jenkins re test this please

$wheres = [];
foreach ($contactAlias as $alias) {
if (!CRM_Core_Permission::check('access deleted contacts')) {
if (is_array($contactAlias)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of code that does if(is_array($foo)) {.. do complex stuff multiple times} else {.. do complex stuff once} if the "complex stuff" is the same in both cases, then it's better to just cast $foo to an array.

Comment on lines 311 to 318
if (is_array($contactAlias)) {
$wheres = [];
foreach ($contactAlias as $alias) {
// CRM-6181
$wheres[] = "$alias.is_deleted = 0";
}
return [NULL, '(' . implode(' AND ', $wheres) . ')'];
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (is_array($contactAlias)) {
$wheres = [];
foreach ($contactAlias as $alias) {
// CRM-6181
$wheres[] = "$alias.is_deleted = 0";
}
return [NULL, '(' . implode(' AND ', $wheres) . ')'];
}
$wheres = [];
foreach ((array) $contactAlias as $alias) {
// CRM-6181
$wheres[] = "$alias.is_deleted = 0";
}
return [NULL, '(' . implode(' AND ', $wheres) . ')'];

@eileenmcnaughton
Copy link
Contributor

I added has-test as the previous fails make it clear this is tested!

@seamuslee001 it's stale

@seamuslee001 seamuslee001 force-pushed the ref_permission_clause_search branch from 87423cf to d3181ef Compare July 1, 2020 06:11
@eileenmcnaughton eileenmcnaughton changed the title [REF] Use Standard function cacheClasue to re-use contact acl cache t… [REF] Use Standard function cacheClause to re-use contact acl cache t… Jul 1, 2020
@seamuslee001 seamuslee001 force-pushed the ref_permission_clause_search branch from d3181ef to e9ad71c Compare July 1, 2020 06:14
@seamuslee001
Copy link
Contributor Author

Rebased now @eileenmcnaughton

@kcristiano
Copy link
Member

@seamuslee001 This makes sense to me. I'll add the PR to a couple of sites and see if I notice any oddities.

@colemanw colemanw added the merge ready PR will be merged after a few days if there are no objections label Jul 14, 2020
Tidy up where clause generation as per Coleman
…o prove that when someone doesn't have view all contacts but does have access deleted contacts and we are searching in the trash an appropriate where clause is generated
@seamuslee001 seamuslee001 force-pushed the ref_permission_clause_search branch from e9ad71c to 21b8bcb Compare July 16, 2020 07:06
@seamuslee001
Copy link
Contributor Author

Jenkins re test this please

@eileenmcnaughton
Copy link
Contributor

@kcristiano @colemanw this has been merge-ready for a while. I would normally merge something after merge-ready but this seems to be pending more testing rather than giving others a chance to input

@kcristiano
Copy link
Member

@eileenmcnaughton I agree I have it applied on our 5.28 RC sites my concern is we won't hot any issues until I can get it on production.

I do think it's good to go in master as that will get it further testing before release

@eileenmcnaughton
Copy link
Contributor

Thanks @kcristiano

@eileenmcnaughton eileenmcnaughton merged commit 93317f7 into civicrm:master Jul 29, 2020
@seamuslee001 seamuslee001 deleted the ref_permission_clause_search branch January 12, 2021 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants