Changeset 12813
- Timestamp:
- 08/08/2023 05:14:08 AM (15 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-release-confirmation.php
r12178 r12813 45 45 ] 46 46 ], 47 'permission_callback' => function( $request ) { 48 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] ); 49 50 return ( 51 Release_Confirmation_Shortcode::can_access() && 52 current_user_can( 'plugin_manage_releases', $plugin ) 53 ); 54 }, 47 'permission_callback' => [ $this, 'permission_can_access_plugin' ], 48 ] ); 49 50 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/release-confirmation/(?P<plugin_tag>[^/]+)/discard', [ 51 'methods' => \WP_REST_Server::READABLE, // TODO: This really should be a POST 52 'callback' => [ $this, 'discard_release' ], 53 'args' => [ 54 'plugin_slug' => [ 55 'validate_callback' => [ $this, 'validate_plugin_slug_callback' ], 56 ], 57 'plugin_tag' => [ 58 'validate_callback' => [ $this, 'validate_plugin_tag_callback' ], 59 ] 60 ], 61 'permission_callback' => [ $this, 'permission_can_access_plugin' ], 55 62 ] ); 56 63 … … 87 94 88 95 /** 96 * Validate that the user can manage releases for the given plugin. 97 */ 98 public function permission_can_access_plugin( $request ) { 99 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] ); 100 101 return ( 102 Release_Confirmation_Shortcode::can_access() && 103 current_user_can( 'plugin_manage_releases', $plugin ) 104 ); 105 } 106 107 /** 89 108 * Endpoint to self-close a plugin. 90 109 * … … 154 173 header( 'Location: ' . $result['location'] ); 155 174 156 if ( ! $release || ! empty( $release['confirmed'][ $user_login ] ) ) {157 // Already confirmed .175 if ( ! $release || ! empty( $release['confirmed'][ $user_login ] ) || ! empty( $release['discarded'] ) ) { 176 // Already confirmed, or unable to be confirmed. 158 177 $result['confirmed'] = false; 159 178 return $result; … … 166 185 // Mark the release as confirmed if enough confirmations. 167 186 if ( count( $release['confirmations'] ) >= $release['confirmations_required'] ) { 168 $release['confirmed'] = true;169 $result['fully_confirmed'] 187 $release['confirmed'] = true; 188 $result['fully_confirmed'] = true; 170 189 } 171 190 … … 193 212 194 213 /** 214 * A simple endpoint to decline/discard a release. 215 */ 216 public function discard_release( $request ) { 217 $user_login = wp_get_current_user()->user_login; 218 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] ); 219 $tag = $request['plugin_tag']; 220 $release = Plugin_Directory::get_release( $plugin, $tag ); 221 $result = [ 222 'location' => wp_get_referer() ?: home_url( '/developers/releases/' ), 223 ]; 224 header( 'Location: ' . $result['location'] ); 225 226 if ( ! $release || $release['confirmed'] || ! empty( $release['discarded'] ) ) { 227 // Already confirmed, or other error encountered. 228 $result['confirmed'] = false; 229 return $result; 230 } 231 232 // Record this user as discarding the release. 233 $release['confirmed'] = false; // Already false, just noting it here explicitely. 234 $release['discarded'] = [ 235 'user' => $user_login, 236 'time' => time(), 237 ]; 238 239 Plugin_Directory::add_release( $plugin, $release ); 240 241 return $result; 242 } 243 244 /** 195 245 * Send a Access email 196 246 */ -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r12617 r12813 800 800 * Generates a link to confirm a release. 801 801 * 802 * @param string $tag The tag to confirm. 802 803 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 804 * @param string $what Optional. What operation to perform. Default: approve. 803 805 * @return string URL to enable confirmations. 804 806 */ 805 public static function get_release_confirmation_link( $tag, $post = null ) {807 public static function get_release_confirmation_link( $tag, $post = null, $what = 'approve' ) { 806 808 $post = get_post( $post ); 809 810 if ( 'approve' === $what ) { 811 $endpoint = 'plugin/%s/release-confirmation/%s'; 812 } elseif ( 'discard' === $what ) { 813 $endpoint = 'plugin/%s/release-confirmation/%s/discard'; 814 } else { 815 return ''; 816 } 817 818 $url = home_url( 'wp-json/plugins/v1/' . sprintf( $endpoint, urlencode( $post->post_name ), urlencode( $tag ) ) ); 807 819 808 820 return add_query_arg( 809 821 array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ), 810 home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/release-confirmation/' . $tag )822 $url 811 823 ); 812 824 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-release-confirmation.php
r12812 r12813 23 23 static function display() { 24 24 $plugins = Tools::get_users_write_access_plugins( wp_get_current_user() ); 25 26 if ( isset( $_GET['show-plugin'] ) && current_user_can( 'plugin_review' ) ) { 27 $plugins = [ wp_unslash( $_GET['show-plugin'] ) ]; 28 } 25 29 26 30 if ( ! $plugins ) { … … 186 190 if ( ! $data['confirmations_required'] ) { 187 191 _e( 'Release did not require confirmation.', 'wporg-plugins' ); 192 } else if ( ! empty( $data['discarded'] ) ) { 193 _e( 'Release discarded.', 'wporg-plugins' ); 188 194 } else if ( $data['confirmed'] ) { 189 195 _e( 'Release confirmed.', 'wporg-plugins' ); … … 223 229 ); 224 230 } 231 232 if ( ! empty( $data['discarded'] ) ) { 233 $user = get_user_by( 'slug', $data['discarded']['user'] ); 234 printf( 235 '<span title="%s">%s</span><br>', 236 esc_attr( gmdate( 'Y-m-d H:i:s', $time ) ), 237 sprintf( 238 __( 'Discarded by %1$s, %2$s ago.', 'wporg-plugins' ), 239 $user->display_name ?: $user->user_nicename, 240 human_time_diff( $data['discarded']['time'] ) 241 ) 242 ); 243 } 225 244 echo '</div>'; 226 245 … … 231 250 $buttons = []; 232 251 233 if ( $data['confirmations_required'] ) {252 if ( $data['confirmations_required'] && empty( $data['discarded'] ) ) { 234 253 $current_user_confirmed = isset( $data['confirmations'][ wp_get_current_user()->user_login ] ); 235 254 … … 244 263 __( 'Confirm', 'wporg-plugins' ) 245 264 ); 265 $buttons[] = sprintf( 266 '<a href="%s" class="button approve-release button-secondary">%s</a>', 267 Template::get_release_confirmation_link( $data['tag'], $plugin, 'discard' ), 268 __( 'Discard', 'wporg-plugins' ) 269 ); 246 270 } else { 247 271 $buttons[] = sprintf( 248 272 '<a class="button approve-release button-secondary disabled">%s</a>', 249 273 __( 'Confirm', 'wporg-plugins' ) 274 ); 275 $buttons[] = sprintf( 276 '<a class="button approve-release button-secondary disabled">%s</a>', 277 __( 'Discard', 'wporg-plugins' ) 250 278 ); 251 279 } -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php
r12509 r12813 278 278 279 279 foreach ( $releases as $release ) { 280 if ( ! $release['confirmed'] && $release['confirmations_required'] ) {280 if ( ! $release['confirmed'] && $release['confirmations_required'] && empty( $release['discarded'] ) ) { 281 281 $warning = true; 282 break; 282 283 } 283 284 }
Note: See TracChangeset
for help on using the changeset viewer.