Repository navigation
Limit the stored rows of an unpublished post-type chart to users who can read the post type #1430
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
base: development
Are you sure you want to change the base?
Changes from all commits
f9b0fab
176ff0c
d6ec928
f05ac70
d3b6643
88c1d05
243d590
1557394
0c99490
5fafc69
8f6eb6c
dd72a30
56fb503
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -878,16 +878,75 @@ public static function maybe_decode_content( $value ) { | |
| return is_serialized( $value ) ? self::decode_content( $value ) : $value; | ||
| } | ||
|
|
||
| /** | ||
| * Tells whether the current user can read the stored rows of a chart. | ||
| * | ||
| * A post-type chart of the Pro plugin stores post titles and meta values of posts in any status. | ||
| * A published chart shows its rows to everyone who can see it. The rows of an unpublished chart are for | ||
| * users who can read every post of the type: the post type has an admin screen, and the user can edit | ||
| * its posts of other users and read its private posts. This is the rule the Pro plugin has for the query. | ||
| * | ||
| * @param int $chart_id The chart ID, or the ID of a chart revision. | ||
| * @return bool | ||
| */ | ||
| public static function can_read_chart_rows( $chart_id ) { | ||
| if ( self::has_public_rows( $chart_id ) ) { | ||
| return true; | ||
| } | ||
|
|
||
| $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true ); | ||
| $post_type = is_array( $filter_config ) && isset( $filter_config['type'] ) && is_string( $filter_config['type'] ) ? get_post_type_object( $filter_config['type'] ) : null; | ||
| return $post_type instanceof WP_Post_Type | ||
| && $post_type->show_ui | ||
| && current_user_can( $post_type->cap->edit_others_posts ) | ||
| && current_user_can( $post_type->cap->read_private_posts ); | ||
| } | ||
|
Comment on lines
+892
to
+903
Contributor
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.
Contributor
Author
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. Fixed in d3b6643 and 88c1d05. |
||
|
|
||
| /** | ||
| * Tells whether everyone who can see a chart can read its stored rows: the chart has no post-type query, or it is published. | ||
| * | ||
| * @param int $chart_id The chart ID, or the ID of a chart revision. | ||
| * @return bool | ||
| */ | ||
| public static function has_public_rows( $chart_id ) { | ||
| $parent_id = wp_is_post_revision( $chart_id ); | ||
| return empty( get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true ) ) || 'publish' === get_post_status( $parent_id ? $parent_id : $chart_id ); | ||
| } | ||
|
|
||
| /** | ||
| * Deletes the saved image of a chart whose rows are not public. | ||
| * | ||
| * The image shows the rows, and each visitor can read a file in the uploads folder. | ||
| * | ||
| * @param int $chart_id The chart ID. A revision has no image of its own. | ||
| * @return void | ||
| */ | ||
| public static function delete_image_of_private_rows( $chart_id ) { | ||
| if ( wp_is_post_revision( $chart_id ) || self::has_public_rows( $chart_id ) ) { | ||
| return; | ||
| } | ||
| $image_id = self::get_chart_image_id( $chart_id ); | ||
| if ( $image_id ) { | ||
| wp_delete_attachment( $image_id, true ); | ||
| } | ||
| delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE ); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the chart content after common manipulations. | ||
| * | ||
| * @param WP_Post|object $chart The chart post. | ||
| * @param string $type The chart type passed to the data filter. | ||
| * @param bool $run_filter Whether to run the chart data filter. | ||
| * @param bool $sanitize Whether to prepare the cells for HTML-capable renderers; exports and editors need the stored values. | ||
| * @return mixed The chart data. | ||
| * @return mixed The chart data; an empty array when the current user cannot read the stored rows. | ||
| */ | ||
| public static function get_chart_data( $chart, $type, $run_filter = true, $sanitize = true ) { | ||
| // A chart object that is not a saved post has no ID and no saved post-type query. | ||
| if ( isset( $chart->ID ) && ! self::can_read_chart_rows( $chart->ID ) ) { | ||
| return array(); | ||
| } | ||
|
|
||
| // change HTML entities | ||
| $post_content = html_entity_decode( htmlentities( $chart->post_content ) ); | ||
| $post_content = preg_replace_callback( | ||
|
|
||
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.
correctnessThe gate empties the rows but keeps the rendered chart image. The editor renders the chart to a PNG data URI and saves it in thechart-imgsetting when it posts the settings. The block REST field, the chart editor and the chart library send all settings, so a refused Author still gets a picture of the private titles. The shortcode withuse_image="yes"and AMP also return the saved image attachment despite the row refusal. Whenevercan_read_chart_rows()refuses, removechart-imgfrom every settings output and skip the saved image. Add cases totests/test-chart-rows-permissions.phpfor the REST settings and theuse_imageshortcode as the Author.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.
Fixed in d3b6643 and 8f6eb6c.
remove_image_of_unreadable_rows()on the chart settings filter removeschart-imgfor a refused user; the block REST field case istest_reader_gives_the_chart_image_only_to_a_user_who_passes_the_rule. For the saved attachment there is one rule in place of a check in each reader: an unpublished chart with a post-type query keeps no saved image (see the reply to the image finding of the review).test_image_is_deleted_when_the_chart_is_unpublishedrenders theuse_imageshortcode as the Author.