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

#2495 - Metrics - Personal - Gen-Map - Restrict To Records Responsible For #2504

Merged
Changes from 1 commit
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
Next Next commit
Ensure to only restrict to records user is responsible for
  • Loading branch information
kodinkat committed May 30, 2024
commit 17b9b62970509a29b65b9c0e6414591e5845d420
9 changes: 8 additions & 1 deletion dt-metrics/records/genmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public function get_query( $post_type, $p2p_type, $p2p_direction, $filters = []
}

$user = wp_get_current_user();
$user_contact_id = Disciple_Tools_Users::get_contact_for_user( $user->ID );
if ( ( $post_type !== 'contacts' ) || ! intval( $user_contact_id ) ) {
$user_contact_id = 0;
}

// Determine archived meta values.
$status_key = $filters['status_key'] ?? '';
Expand All @@ -173,7 +177,10 @@ public function get_query( $post_type, $p2p_type, $p2p_direction, $filters = []
( SELECT p_status.meta_value FROM $wpdb->postmeta as p_status WHERE ( p_status.post_id = a.ID ) AND ( p_status.meta_key = %s ) ) as status,
( SELECT EXISTS( SELECT p_shared.user_id FROM $wpdb->dt_share as p_shared WHERE p_shared.user_id = %d AND p_shared.post_id = a.ID ) ) as shared
FROM $wpdb->posts as a
LEFT JOIN $wpdb->postmeta AS pm_assigned ON ( a.ID = pm_assigned.post_id AND pm_assigned.meta_key = 'assigned_to' )
LEFT JOIN $wpdb->p2p AS p2p_subassigned ON ( a.ID = p2p_subassigned.p2p_to AND p2p_subassigned.p2p_type = 'contacts_to_subassigned' )
WHERE a.post_type = %s
AND ( pm_assigned.meta_value = %s OR p2p_subassigned.p2p_from = %d )
AND a.ID %1s IN (
SELECT DISTINCT (p2p_from)
FROM $wpdb->p2p
Expand All @@ -195,7 +202,7 @@ public function get_query( $post_type, $p2p_type, $p2p_direction, $filters = []
( SELECT EXISTS( SELECT u_shared.user_id FROM $wpdb->dt_share as u_shared WHERE u_shared.user_id = %d AND u_shared.post_id = p.%1s ) ) as shared
FROM $wpdb->p2p as p
WHERE p.p2p_type = %s;
", $status_key, $user->ID, $post_type, $not_from, $p2p_type, $not_to, $p2p_type, $select_id, $select_parent_id, $select_id, $select_id, $status_key, $user->ID, $select_id, $p2p_type ), ARRAY_A );
", $status_key, $user->ID, $post_type, ( 'user-' . $user->ID ), $user_contact_id, $not_from, $p2p_type, $not_to, $p2p_type, $select_id, $select_parent_id, $select_id, $select_id, $status_key, $user->ID, $select_id, $p2p_type ), ARRAY_A );

return $query;
}
Expand Down
Loading