Making WordPress.org


Ignore:
Timestamp:
05/17/2023 08:38:01 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Introduce assigned reviewer functionality.

Previously the group of reviewers was so small that they knew who was handling which submission, now that we have a larger set of reviewers being onboarded we need to keep track of review assignments a bit better.

See #6993.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php

    r12520 r12591  
    6464        add_action( 'wp_ajax_plugin-author-lookup', array( __NAMESPACE__ . '\Metabox\Author', 'lookup_author' ) );
    6565        add_action( 'wp_ajax_plugin-svn-sync', array( __NAMESPACE__ . '\Metabox\Review_Tools', 'svn_sync' ) );
     66        add_action( 'wp_ajax_plugin-set-reviewer', array( __NAMESPACE__ . '\Metabox\Reviewer', 'xhr_set_reviewer' ) );
    6667
    6768        add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Release_Confirmation', 'save_post' ) );
    6869        add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Author_Notice', 'save_post' ) );
     70        add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Reviewer', 'save_post' ) );
     71
     72        // Audit logs
     73        add_action( 'updated_postmeta', array( $this, 'updated_postmeta' ), 10, 4 );
    6974    }
    7075
     
    212217        }
    213218
     219        // Filter by reviewer.
     220        if ( ! empty( $_REQUEST['reviewer'] ) ) {
     221            $meta_query = $query->get( 'meta_query' ) ?: [];
     222            $meta_query[] = [
     223                'key'   => 'assigned_reviewer',
     224                'value' => intval( $_GET['reviewer'] ),
     225            ];
     226
     227            $query->set( 'meta_query', $meta_query );
     228        }
     229
    214230    }
    215231
     
    242258
    243259        $action = array_intersect(
    244             [ 'plugin_open', 'plugin_close', 'plugin_disable', 'plugin_reject' ],
     260            [ 'plugin_open', 'plugin_close', 'plugin_disable', 'plugin_reject', 'plugin_assign' ],
    245261            [ $_REQUEST['action'], $_REQUEST['action2'] ]
    246262        );
     
    251267
    252268        check_admin_referer( 'bulk-posts' );
     269
     270        $new_status = false;
     271        $from_state = false;
     272        $meta_data  = false;
    253273
    254274        switch( $action ) {
     
    277297                $from_state = [ 'new', 'pending' ];
    278298                break;
     299            case 'plugin_assign':
     300                if ( ! isset( $_REQUEST['reviewer'] ) ) {
     301                    return;
     302                }
     303
     304                $capability = 'plugin_review';
     305                $from_state = 'any';
     306                $message    = _n_noop( '%s plugin assigned.', '%s plugins assigned.', 'wporg-plugins' );
     307                $meta_data = array(
     308                    'assigned_reviewer'      => intval( $_REQUEST['reviewer'] ),
     309                    'assigned_reviewer_time' => time(),
     310                );
     311                break;
    279312            default:
    280313                return;
     
    282315
    283316        $closed = 0;
    284         $plugins  = get_posts( array(
     317        $args = array(
    285318            'post_type'      => 'plugin',
    286319            'post__in'       => array_map( 'absint', $_REQUEST['post'] ),
    287             'post_status'    => $from_state,
    288320            'posts_per_page' => count( $_REQUEST['post'] ),
    289         ) );
     321        );
     322        if ( $from_state ) {
     323            $args['post_status'] = $from_state;
     324        }
     325        $plugins  = get_posts( $args );
    290326
    291327        foreach ( $plugins as $plugin ) {
     
    293329                continue;
    294330            }
    295 
    296             $updated = wp_update_post( array(
    297                 'ID'          => $plugin->ID,
    298                 'post_status' => $new_status,
    299             ) );
     331            $updated = false;
     332
     333            if ( $new_status ) {
     334                $updated = wp_update_post( array(
     335                    'ID'          => $plugin->ID,
     336                    'post_status' => $new_status,
     337                ) );
     338            }
     339            if ( $meta_data ) {
     340                foreach ( $meta_data as $key => $value ) {
     341                    $updated = update_post_meta( $plugin->ID, $key, $value );
     342                }
     343            }
    300344
    301345            if ( $updated && ! is_wp_error( $updated ) ) {
     
    545589            __( 'Plugin Controls', 'wporg-plugins' ),
    546590            array( __NAMESPACE__ . '\Metabox\Controls', 'display' ),
     591            'plugin', 'side', 'high'
     592        );
     593
     594        add_meta_box(
     595            'reviewerdiv',
     596            __( 'Reviewer', 'wporg-plugins' ),
     597            array( __NAMESPACE__ . '\Metabox\Reviewer', 'display' ),
    547598            'plugin', 'side', 'high'
    548599        );
     
    807858        return $keys;
    808859    }
     860
     861    /**
     862     * Watch for post_meta updates and log accordingly.
     863     */
     864    public function updated_postmeta( $meta_id, $post_id, $meta_key, $meta_value ) {
     865        if ( 'assigned_reviewer' === $meta_key && $meta_value ) {
     866            $reviewer = get_user_by( 'id', $meta_value );
     867            Tools::audit_log(
     868                sprintf(
     869                    'Assigned to <a href="%s">%s</a>.',
     870                    esc_url( 'https://profiles.wordpress.org/' . $reviewer->user_nicename . '/' ),
     871                    $reviewer->display_name ?: $reviewer->user_login
     872                ),
     873                get_post( $post_id )
     874            );
     875        } elseif ( 'assigned_reviewer' === $meta_key && ! $meta_value ) {
     876            Tools::audit_log( 'Unassigned.', get_post( $post_id ) );
     877        }
     878    }
    809879}
Note: See TracChangeset for help on using the changeset viewer.