-
Notifications
You must be signed in to change notification settings - Fork 65
#2498 - Metrics - Personal Layers Map #2542
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
Merged
corsacca
merged 12 commits into
DiscipleTools:develop
from
kodinkat:2498-metrics-personal-layers-map
Aug 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fb97a60
Support record maps within personal metrics
kodinkat 805aee9
Merge branch 'develop' of https://github.com/DiscipleTools/disciple-t…
kodinkat 1debcc0
Embedded filter by post id sql + Split local storage cookie across me…
kodinkat 0a95051
Updated sql to ensure only shared records are returned
kodinkat 7488015
Resolved auto formatting issue
kodinkat 85d1b03
Additional tidy-ups
kodinkat 1fdfafd
Simplified sql
kodinkat 64c397d
Ensure metrics is only shown for specific user roles
kodinkat 51ffd8a
Personal for all. Dynamics by permissions
kodinkat be8905f
Prevent non-slug related requests
kodinkat 9fd2f94
Moved permissions check to endpoint
kodinkat 1cacd6f
Revised permission checks + Updated genmap to follow new checks
kodinkat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ class DT_Metrics_Dynamic_Records_Map extends DT_Metrics_Chart_Base | |
{ | ||
|
||
//slug and title of the top menu folder | ||
public $base_slug = 'records'; // lowercase | ||
public $base_slug; // lowercase | ||
public $base_title; | ||
public $post_type = 'contacts'; | ||
public $post_types = []; | ||
|
@@ -18,17 +18,21 @@ class DT_Metrics_Dynamic_Records_Map extends DT_Metrics_Chart_Base | |
public $slug = 'dynamic_records_map'; // lowercase | ||
public $js_object_name = 'wp_js_object'; // This object will be loaded into the metrics.js file by the wp_localize_script. | ||
public $js_file_name = '/dt-metrics/records/dynamic-records-map.js'; // should be full file name plus extension | ||
public $permissions = [ 'dt_all_access_contacts', 'view_project_metrics' ]; | ||
public $permissions = [ 'dt_all_access_contacts', 'view_project_metrics', 'multiplier' ]; | ||
public $namespace = 'dt-metrics/records'; | ||
public $base_filter = []; | ||
|
||
public function __construct() { | ||
parent::__construct(); | ||
public function __construct( $base_slug, $base_title ) { | ||
if ( !$this->has_permission() ){ | ||
return; | ||
} | ||
|
||
$this->base_slug = $base_slug; | ||
$this->base_title = $base_title; | ||
|
||
parent::__construct(); | ||
|
||
$this->title = __( 'Records Map', 'disciple_tools' ); | ||
$this->base_title = __( 'Contacts', 'disciple_tools' ); | ||
|
||
// Build post types array, ignoring some for now. | ||
// TODO: Only select post types with valid location field types! | ||
|
@@ -69,6 +73,8 @@ public function __construct() { | |
if ( "metrics/$this->base_slug/$this->slug" === $url_path ) { | ||
add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ], 99 ); | ||
} | ||
|
||
$this->namespace = "dt-metrics/$this->base_slug/$this->slug"; | ||
add_action( 'rest_api_init', [ $this, 'add_api_routes' ] ); | ||
} | ||
|
||
|
@@ -101,6 +107,7 @@ public function scripts() { | |
'map_key' => DT_Mapbox_API::get_key(), | ||
'no_map_key_msg' => _x( 'To view this map, a mapbox key is needed; click here to add.', 'install mapbox key to view map', 'disciple_tools' ), | ||
'map_mirror' => dt_get_location_grid_mirror( true ), | ||
'can_list_all' => in_array( $this->base_slug, [ 'records' ] ), | ||
'menu_slug' => $this->base_slug, | ||
'post_type' => $this->post_type, | ||
'post_types' => $this->post_type_options, | ||
|
@@ -183,8 +190,14 @@ public function post_type_geojson( WP_REST_Request $request ){ | |
break; | ||
} | ||
|
||
// Determine if record restriction (listing-all) should take effect. | ||
$params = self::capture_list_all_setting( $params ); | ||
|
||
// Execute request query. | ||
$response = Disciple_Tools_Mapping_Queries::post_type_geojson( $params['post_type'], $params, $offset, $limit ); | ||
|
||
// Ensure to unset assigned_post_ids for security reasons. | ||
unset( $params['assigned_post_ids'] ); | ||
} | ||
|
||
return [ | ||
|
@@ -202,7 +215,7 @@ public function cluster_geojson( WP_REST_Request $request ) { | |
$query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; | ||
$query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); | ||
|
||
return Disciple_Tools_Mapping_Queries::cluster_geojson( $post_type, $query ); | ||
return Disciple_Tools_Mapping_Queries::cluster_geojson( $post_type, self::capture_list_all_setting( $query ) ); | ||
} | ||
|
||
|
||
|
@@ -215,7 +228,7 @@ public function get_grid_totals( WP_REST_Request $request ) { | |
$post_type = $params['post_type']; | ||
$query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; | ||
$query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); | ||
$results = Disciple_Tools_Mapping_Queries::query_location_grid_meta_totals( $post_type, $query ); | ||
$results = Disciple_Tools_Mapping_Queries::query_location_grid_meta_totals( $post_type, self::capture_list_all_setting( $query ) ); | ||
|
||
$list = []; | ||
foreach ( $results as $result ) { | ||
|
@@ -236,7 +249,7 @@ public function get_list_by_grid_id( WP_REST_Request $request ) { | |
$query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; | ||
$query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); | ||
|
||
return Disciple_Tools_Mapping_Queries::query_under_location_grid_meta_id( $post_type, $grid_id, $query ); | ||
return Disciple_Tools_Mapping_Queries::query_under_location_grid_meta_id( $post_type, $grid_id, self::capture_list_all_setting( $query ) ); | ||
} | ||
|
||
|
||
|
@@ -252,9 +265,33 @@ public function points_geojson( WP_REST_Request $request ) { | |
$query = ( isset( $params['query'] ) && !empty( $params['query'] ) ) ? $params['query'] : []; | ||
$query = dt_array_merge_recursive_distinct( $query, $this->base_filter ); | ||
|
||
return Disciple_Tools_Mapping_Queries::points_geojson( $post_type, $query ); | ||
return Disciple_Tools_Mapping_Queries::points_geojson( $post_type, self::capture_list_all_setting( $query ) ); | ||
} | ||
|
||
private function capture_list_all_setting( $params ) { | ||
if ( !isset( $params['list_all'] ) || !$params['list_all'] ) { | ||
$params['list_all'] = false; | ||
$params['assigned_post_ids'] = self::list_assigned_post_ids( ( ( $params['post_type'] === 'system-users' ) ? 'contacts' : $params['post_type'] ), get_current_user_id() ); | ||
} else { | ||
$params['list_all'] = true; | ||
$params['assigned_post_ids'] = []; | ||
} | ||
|
||
return $params; | ||
} | ||
|
||
private function list_assigned_post_ids( $post_type, $user_id, $fields = [ 'ID' ], $limit = 500000 ): array { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kodinkat, lets add an extra param post_type_geojson with the restrict param and add the sql directly if it is present. |
||
$assigned_posts = DT_Posts::search_viewable_post( $post_type, [ | ||
'limit' => $limit, | ||
'fields' => $fields, | ||
'assigned_to' => [ $user_id ], | ||
'subassigned' => [ $user_id ], | ||
'shared_with' => [ $user_id ] | ||
] ); | ||
|
||
return array_map( function ( $post ) { | ||
return $post->ID; | ||
}, $assigned_posts['posts'] ?? [] ); | ||
} | ||
|
||
} | ||
new DT_Metrics_Dynamic_Records_Map(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kodinkat
multiplier
is not a permission. Please explain