Making WordPress.org


Ignore:
Timestamp:
09/03/2017 09:43:53 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Introduce UI for managing plugin support reps.

Support representatives can mark forum topics as resolved or sticky (same as plugin authors and contributors), but don't have commit access to the plugin.

See #3029, #2699.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-support-reps.php

    r5864 r5867  
    1111
    1212/**
    13  * An API Endpoint to manage plugin committers.
     13 * An API Endpoint to manage plugin support reps.
    1414 *
    1515 * @package WordPressdotorg_Plugin_Directory
    1616 */
    17 class Plugin_Committers extends Base {
     17class Plugin_Support_Reps extends Base {
    1818
    1919    function __construct() {
    20         register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/committers/?', array(
     20        register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/support-reps/?', array(
    2121            array(
    2222                'methods'  => WP_REST_Server::READABLE,
    23                 'callback' => array( $this, 'list_committers' ),
     23                'callback' => array( $this, 'list_support_reps' ),
    2424                'permission_callback' => function( $request ) {
    2525                    return current_user_can(
     
    3737            array(
    3838                'methods'  => WP_REST_Server::CREATABLE,
    39                 'callback' => array( $this, 'add_committer' ),
     39                'callback' => array( $this, 'add_support_rep' ),
    4040                'permission_callback' => function( $request ) {
    4141                    return current_user_can(
    42                         'plugin_add_committer',
     42                        'plugin_add_support_rep',
    4343                        Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    4444                    );
     
    5353        ) );
    5454
    55         register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/committers/(?P<committer>[^/]+)/?', array(
     55        register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/support-reps/(?P<support_rep>[^/]+)/?', array(
    5656            'methods'  => WP_REST_Server::DELETABLE,
    57             'callback' => array( $this, 'revoke_committer' ),
     57            'callback' => array( $this, 'remove_support_rep' ),
    5858            'permission_callback' => function( $request ) {
    5959                return current_user_can(
    60                     'plugin_remove_committer',
     60                    'plugin_remove_support_rep',
    6161                    Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    6262                );
     
    6767                    'required' => true,
    6868                ),
    69                 'committer' => array(
     69                'support_rep' => array(
    7070                    'validate_callback' => array( $this, 'validate_user_slug_callback' ),
    7171                    'required' => true,
     
    7878     *
    7979     */
    80     function list_committers( $request ) {
     80    function list_support_reps( $request ) {
    8181        $plugin_slug = $request['plugin_slug'];
    8282
    83         $committers = array();
    84         foreach ( (array) Tools::get_plugin_committers( $plugin_slug ) as $user_login ) {
    85             $user = get_user_by( 'login', $user_login );
    86             $committers[] = $this->user_committer_details( $user );
     83        $support_reps = array();
     84        foreach ( (array) Tools::get_plugin_support_reps( $plugin_slug ) as $user_nicename ) {
     85            $user = get_user_by( 'slug', $user_nicename );
     86            $support_reps[] = $this->user_support_rep_details( $user );
    8787        }
    8888
    89         return $committers;
     89        return $support_reps;
    9090    }
    9191
    92     function add_committer( $request ) {
    93         $user = new WP_User( $request['committer'] );
     92    function add_support_rep( $request ) {
     93        $user = new WP_User( $request['support_rep'] );
    9494        if ( ! $user->exists() ) {
    9595            return new WP_Error( 'plugin_user_not_found', __( 'The provided user could not be found.', 'wporg-plugins' ) );
     
    9898        $plugin_slug = $request['plugin_slug'];
    9999
    100         if ( ! Tools::grant_plugin_committer( $plugin_slug, $user ) ) {
     100        if ( ! Tools::add_plugin_support_rep( $plugin_slug, $user ) ) {
    101101            return new WP_Error( 'failed', __( 'The operation failed. Please try again.', 'wporg-plugins' ) );
    102102        }
    103103
    104         return $this->user_committer_details( $user );
     104        return $this->user_support_rep_details( $user );
    105105    }
    106106
    107     function revoke_committer( $request ) {
    108         $user = new WP_User( $request['committer'] );
     107    function remove_support_rep( $request ) {
     108        $user = new WP_User( $request['support_rep'] );
    109109        if ( ! $user->exists() ) {
    110110            return new WP_Error( 'plugin_user_not_found', __( 'The provided user could not be found.', 'wporg-plugins' ) );
     
    113113        $plugin_slug = $request['plugin_slug'];
    114114
    115         $result = Tools::revoke_plugin_committer( $plugin_slug, $user );
     115        $result = Tools::remove_plugin_support_rep( $plugin_slug, $user );
    116116        if ( ! $result ) {
    117117            return new WP_Error( 'failed', __( 'The operation failed. Please try again.', 'wporg-plugins' ) );
     
    129129
    130130    /**
    131      * Helper function to return a committer object
     131     * Helper function to return a support rep object
    132132     */
    133     function user_committer_details( $user ) {
     133    function user_support_rep_details( $user ) {
    134134        $data = array(
    135135            'nicename' => $user->user_nicename,
Note: See TracChangeset for help on using the changeset viewer.