Making WordPress.org

Changeset 12813


Ignore:
Timestamp:
08/08/2023 05:14:08 AM (15 months ago)
Author:
dd32
Message:

Plugin Directory: Allow plugins releases to be discarded instead of confirmed.

Sometimes a release should not be released, this allows discarding those releases to cease the warnings.

See #5352.

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  
    4545                ]
    4646            ],
    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' ],
    5562        ] );
    5663
     
    8794
    8895    /**
     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    /**
    89108     * Endpoint to self-close a plugin.
    90109     *
     
    154173        header( 'Location: ' . $result['location'] );
    155174
    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.
    158177            $result['confirmed'] = false;
    159178            return $result;
     
    166185        // Mark the release as confirmed if enough confirmations.
    167186        if ( count( $release['confirmations'] ) >= $release['confirmations_required'] ) {
    168             $release['confirmed'] = true;
    169             $result['fully_confirmed']     = true;
     187            $release['confirmed']      = true;
     188            $result['fully_confirmed'] = true;
    170189        }
    171190
     
    193212
    194213    /**
     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    /**
    195245     * Send a Access email
    196246     */
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r12617 r12813  
    800800     * Generates a link to confirm a release.
    801801     *
     802     * @param string            $tag  The tag to confirm.
    802803     * @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.
    803805     * @return string URL to enable confirmations.
    804806     */
    805     public static function get_release_confirmation_link( $tag, $post = null) {
     807    public static function get_release_confirmation_link( $tag, $post = null, $what = 'approve' ) {
    806808        $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 ) ) );
    807819
    808820        return add_query_arg(
    809821            array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
    810             home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/release-confirmation/' . $tag )
     822            $url
    811823        );
    812824    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-release-confirmation.php

    r12812 r12813  
    2323    static function display() {
    2424        $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        }
    2529
    2630        if ( ! $plugins ) {
     
    186190        if ( ! $data['confirmations_required'] ) {
    187191            _e( 'Release did not require confirmation.', 'wporg-plugins' );
     192        } else if ( ! empty( $data['discarded'] ) ) {
     193            _e( 'Release discarded.', 'wporg-plugins' );
    188194        } else if ( $data['confirmed'] ) {
    189195            _e( 'Release confirmed.', 'wporg-plugins' );
     
    223229            );
    224230        }
     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        }
    225244        echo '</div>';
    226245
     
    231250        $buttons = [];
    232251
    233         if ( $data['confirmations_required'] ) {
     252        if ( $data['confirmations_required'] && empty( $data['discarded'] ) ) {
    234253            $current_user_confirmed = isset( $data['confirmations'][ wp_get_current_user()->user_login ] );
    235254
     
    244263                        __( 'Confirm', 'wporg-plugins' )
    245264                    );
     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                    );
    246270                } else {
    247271                    $buttons[] = sprintf(
    248272                        '<a class="button approve-release button-secondary disabled">%s</a>',
    249273                        __( 'Confirm', 'wporg-plugins' )
     274                    );
     275                    $buttons[] = sprintf(
     276                        '<a class="button approve-release button-secondary disabled">%s</a>',
     277                        __( 'Discard', 'wporg-plugins' )
    250278                    );
    251279                }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php

    r12509 r12813  
    278278
    279279    foreach ( $releases as $release ) {
    280         if ( ! $release['confirmed'] && $release['confirmations_required'] ) {
     280        if ( ! $release['confirmed'] && $release['confirmations_required'] && empty( $release['discarded'] ) ) {
    281281            $warning = true;
     282            break;
    282283        }
    283284    }
Note: See TracChangeset for help on using the changeset viewer.