Making WordPress.org

Changeset 10957


Ignore:
Timestamp:
05/06/2021 06:43:29 AM (6 years ago)
Author:
dd32
Message:

Helpscout: Display Slack user details in the profile information.

Location:
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/common.php

    r10909 r10957  
    11<?php
    22
     3$wp_init_host = 'https://wordpress.org/';
    34$base_dir = dirname( dirname( __DIR__ ) );
    45require( $base_dir . '/wp-init.php' );
    … …  
    2526
    2627// get the info from HS
    27 return json_decode( $data );
     28$data = json_decode( $data );
     29
     30// If this is related to a slack user, fetch their details instead.
     31if (
     32        isset ( $data->customer->email, $data->ticket->subject ) &&
     33        false !== stripos( $data->customer->email, 'slack' ) &&
     34        preg_match( '/(\S+)@chat.wordpress.org/i', $data->ticket->subject, $m )
     35) {
     36        $user = get_user_by( 'slug', $m[1] );
     37        if ( $user ) {
     38                $data->customer->email = $user->user_email;
     39        }
     40}
     41
     42return $data;
  • sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/dpo.php

    r10910 r10957  
    22// Add current DPO Export/Erasure status for the customer.
    33
    4 $wp_init_host = 'https://wordpress.org/';
    54// $request is the validated HelpScout request.
    65$request = include __DIR__ . '/common.php';
    … …  
    1413
    1514// default empty output
    16 $html = '';
    17 
     15$html  = '';
    1816$email = $request->customer->email;
    1917
  • sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/profile.php

    r10944 r10957  
    77// default empty output
    88$html = '';
     9$user = false;
    910
    1011// Look up a user based on email address
    … …  
    6263}
    6364
     65// If this is related to a slack user, include the details of the slack account.
     66if ( $user || preg_match( '/(\S+@chat.wordpress.org)/i', $request->ticket->subject, $m ) ) {
     67
     68        if ( $user ) {
     69                $slack_user = $wpdb->get_row( $sql = $wpdb->prepare(
     70                        'SELECT * FROM slack_users WHERE user_id = %d',
     71                        $user->ID
     72                ) );
     73        } else {
     74                $slack_user = $wpdb->get_row( $sql = $wpdb->prepare(
     75                        'SELECT * FROM slack_users WHERE profiledata LIKE %s',
     76                        '%' . $wpdb->esc_like( '"email":"' . $m[1] . '"' ) . '%',
     77                ) );
     78        }
     79
     80        if ( $slack_user ) {
     81                $slack_data = json_decode( $slack_user->profiledata );
     82                $html .= '<hr/>';
     83                $html .= '<ul>';
     84                $html .= '<li>Slack: <a href="https://wordpress.slack.com/archives/' . $slack_user->dm_id .  '">' . esc_html( $slack_data->profile->display_name_normalized ?? $slack_data->profile->display_name ) . '</a></li>';
     85                $html .= '<li>Account ' . ( !empty( $slack_data->deleted ) ? 'Deactivated' : 'Enabled' ) . '</li>';
     86                $html .= '<li>Last Updated: ' . gmdate( 'Y-m-d H:i:s', $slack_data->updated ) . '</li>';
     87                $html .= '</ul>';
     88        }
     89}
     90
    6491// response to HS is just HTML to display in the sidebar
    6592$response = array( 'html' => $html );
Note: See TracChangeset for help on using the changeset viewer.