Making WordPress.org

Changeset 12574


Ignore:
Timestamp:
05/08/2023 02:46:30 AM (3 years ago)
Author:
dd32
Message:

Support Forums: Also Viewing: Change it to be privacy-by-default. This allows for only mods to see other mods, and for plugin support reps to see other support reps for the same plugins/themes.

See #6431.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

    r12531 r12574  
    10561056                return $support_reps;
    10571057        }
     1058
     1059        /**
     1060         * Get the plugin or theme object slugs for a given user.
     1061         *
     1062         * @param int $user_id The user id.
     1063         * @return array
     1064         */
     1065        public function get_user_object_slugs( $user_id ) {
     1066                global $wpdb;
     1067
     1068                // Check the cache.
     1069                $cache_key   = $user_id;
     1070                $cache_group = $this->compat() . '-user-object-slugs';
     1071                $slugs       = wp_cache_get( $cache_key, $cache_group );
     1072                if ( $slugs !== false ) {
     1073                        return $slugs;
     1074                }
     1075                $slugs = [];
     1076
     1077                // Themes.
     1078                if ( 'theme' == $this->compat() ) {
     1079                        $slugs = $wpdb->get_col( $wpdb->prepare(
     1080                                "SELECT post_name
     1081                                        FROM %i
     1082                                        WHERE post_type = 'repopackage' AND post_author = %d",
     1083                                $wpdb->base_prefix . WPORG_THEME_DIRECTORY_BLOGID . '_posts',
     1084                                $user_id
     1085                        ) );
     1086                }
     1087
     1088                // Plugins
     1089                if ( 'plugin' == $this->compat() ) {
     1090                        $slugs = $wpdb->get_col( $wpdb->prepare(
     1091                                "SELECT DISTINCT p.post_name
     1092                                        FROM %i AS t
     1093                                                LEFT JOIN %i AS tt ON tt.term_id = t.term_id
     1094                                                LEFT JOIN %i AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
     1095                                                LEFT JOIN %i AS p ON tr.object_id = p.ID
     1096                                        WHERE tt.taxonomy IN( 'plugin_contributors', 'plugin_support_reps', 'plugin_committers' ) AND t.name = %s",
     1097                                        $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_terms',
     1098                                        $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_term_taxonomy',
     1099                                        $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_term_relationships',
     1100                                        $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_posts',
     1101                                        get_user_by( 'id', $user_id )->user_nicename
     1102                        ) );
     1103                }
     1104
     1105                wp_cache_set( $cache_key, $slugs, $cache_group, HOUR_IN_SECONDS );
     1106
     1107                return $slugs;
     1108        }
    10581109}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js

    r11664 r12574  
    5757                        banner.hide();
    5858                } else {
    59                         userList = currentlyViewing.map( function( item ) {
     59                        anonymousUsers      = currentlyViewing.filter( function( item ) { return ! item.user_id; } );
     60                        anonymousUserCount  = anonymousUsers.length;
     61                        anonymousUserTyping = anonymousUsers.filter( function( item ) { return !! item.isTyping; } ).length;
     62                        userList            = currentlyViewing.filter( function( item ) { return !! item.user_id; } );
     63
     64                        // Markup those who are typing, and flatten it to just the name.
     65                        userList = userList.map( function( item ) {
    6066                                return item.who + ( item.isTyping ? ' ' + __( '(is typing)', 'wporg-forums' ) : '' );
    6167                        } );
    6268
    63                         if ( userCount > 1 ) {
     69                        // Add the anonymous users to the list.
     70                        if ( anonymousUserCount ) {
     71                                var anonymousText = _n( '%s other person', '%s other people', anonymousUserCount, 'wporg-forums' );
     72
     73                                anonymousText = anonymousText.replace( '%s', anonymousUserCount );
     74                                if ( anonymousUserTyping ) {
     75                                        anonymousText += ' ' + _n( '(%s is typing)', '(%s are typing)', anonymousUserTyping, 'wporg-forums' );
     76                                }
     77
     78                                userList.push( anonymousText );
     79                        }
     80
     81                        displayCount = userList.length;
     82
     83                        if ( displayCount > 1 ) {
    6484                                userlistPretty = __( '%1$s and %2$s', 'wporg-forums' )
    65                                 .replace( '%1$s', userList.slice( 0, -1 ).join( ', ' ) + ( userCount > 2 ? ',' : '' ) )
    66                                 .replace( '%2$s', userList.slice( -1 ) );
     85                                        .replace( '%1$s', userList.slice( 0, -1 ).join( ', ' ) + ( displayCount > 2 ? ',' : '' ) )
     86                                        .replace( '%2$s', userList.slice( -1 ) );
    6787                        } else {
    6888                                userlistPretty = userList.join( ', ' ); // only one element.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.php

    r12412 r12574  
    22namespace WordPressdotorg\BBP_Also_Viewing;
    33use function WordPressdotorg\SEO\Canonical\get_canonical_url;
     4use const MINUTE_IN_SECONDS;
    45
    56/**
     
    2829
    2930const USER_OPTION  = 'also-viewing';
    30 const TIMEOUT      = 5 * \MINUTE_IN_SECONDS;
     31const TIMEOUT      = 5 * MINUTE_IN_SECONDS;
    3132const REFRESH_INT  = 45; // How often the client should check for new viewers in seconds.
    3233const CACHE_GROUP  = 'also-viewing';
    33 const CACHE_TIME   = 5 * \MINUTE_IN_SECONDS;
     34const CACHE_TIME   = 5 * MINUTE_IN_SECONDS;
    3435const REPLY_THRESH = 20; // The number of replies a user must have before the feature can be opt'd into.
    3536
     
    275276 * Get the list of OTHER users who are currently viewing a page.
    276277 *
     278 * This anonymizes users so that only mods can see other mods, and plugin support reps can see other reps and committers.
     279 *
    277280 * @param string $page The page to get the userse for.
    278281 *
     
    287290        }
    288291
     292        // Anonymize the list of users if appropriate.
     293        // Mods + Admins can see all.
     294        if ( current_user_can( 'moderate' ) || current_user_can( 'list_users' ) ) {
     295                return array_values( $users );
     296        }
     297
     298        // Anonymize mods for other users.
     299        foreach ( $users as &$u ) {
     300                if ( user_can( $u['user_id'], 'moderate' ) ) {
     301                        $u['who']     = '';
     302                        $u['user_id'] = 0;
     303                }
     304        }
     305
     306        // Anonymize users unless they've got similar caps.
     307        // Plugin support reps can see other reps and committers -for their own plugins-.
     308        $current_user_objects = get_user_object_slugs( get_current_user_id() );
     309        foreach ( $users as &$u ) {
     310                $user_objects = get_user_object_slugs( $u['user_id'] );
     311                if ( ! array_intersect( $user_objects, $current_user_objects ) ) {
     312                        $u['who']     = '';
     313                        $u['user_id'] = 0;
     314                }
     315        }
     316
    289317        return array_values( $users );
     318}
     319
     320/**
     321 * Fetch the list of plugins/themes a user has access to.
     322 *
     323 * @param int $user_id The user ID to check for.
     324 * @return array Array of plugin slugs.
     325 */
     326function get_user_object_slugs( $user_id ) {
     327        if ( ! class_exists( '\WordPressdotorg\Forums\Plugin' ) ) {
     328                return [];
     329        }
     330
     331        $plugin_slugs = \WordPressdotorg\Forums\Plugin::get_instance()->plugins->get_user_object_slugs( $user_id );
     332        $theme_slugs  = \WordPressdotorg\Forums\Plugin::get_instance()->themes->get_user_object_slugs( $user_id );
     333
     334        $matrix = [];
     335        foreach ( $plugin_slugs as $slug ) {
     336                $matrix[] = "plugin:{$slug}";
     337        }
     338        foreach ( $theme_slugs as $slug ) {
     339                $matrix[] = "theme:{$slug}";
     340        }
     341
     342        return $matrix;
    290343}
    291344
Note: See TracChangeset for help on using the changeset viewer.