Changeset 12678
- Timestamp:
- 06/28/2023 02:11:16 AM (15 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin-post.php
r12671 r12678 21 21 $team_ids = array_map( 'intval', $team_ids ); 22 22 23 $updated = 'success'; 24 $message = null; 25 $invite = false; 23 $updated = 'success'; 24 $message = null; 25 $invite = false; 26 $github_username = false; 26 27 27 28 if ( ! $team_ids ) { 28 29 $updated = 'error'; 29 30 $message = 'No teams selected'; 30 } elseif ( 31 preg_match( '!^https://profiles.wordpress.org/(?<slug>[^/]+)!i', $input, $m ) || 32 ! is_email( $input ) 33 ) { 31 } elseif ( is_email( $input ) ) { 32 $invite = $input; 33 } elseif ( preg_match( '!^https://github.com/(?<slug>[^/]+)!i', $input, $m ) ) { 34 $gh_user = api( '/users/' . $m['slug'] ); 35 $github_username = $gh_user->login ?? false; 36 $invite = $gh_user->id ?? 0; 37 } else { 38 preg_match( '!^https://profiles.wordpress.org/(?<slug>[^/]+)!i', $input, $m ); 39 34 40 $user = get_user_by( 'slug', $m['slug'] ?? $input ); 35 $github_details = json_decode( $wpdb->get_var( $wpdb->prepare(36 'SELECT user_details FROM wporg_github_users WHERE user_id = %d',41 $github_details = $wpdb->get_row( $wpdb->prepare( 42 'SELECT github_user, user_details FROM wporg_github_users WHERE user_id = %d', 37 43 $user->ID 38 ) ) ); 44 ) ); 45 if ( $github_details ) { 46 $github_details->user_details = json_decode( $github_details->user_details ); 47 } 39 48 40 if ( ! $user || ! $github_details ) {49 if ( ! $user || ! $github_details || ! $github_details->user_details ) { 41 50 $updated = 'no-github'; 42 51 } else { 43 $invite = $github_details->id; 52 $invite = $github_details->user_details->id; 53 $github_username = $github_details->github_user; 44 54 } 45 } elseif ( is_email( $input ) ) {46 $invite = $input;47 } else {48 $updated = 'error';49 55 } 50 56 … … 52 58 $result = invite_member( $invite, $team_ids ); 53 59 54 if ( $result->id ) { 55 // Note that it was invited via this site.. 56 $invited_gh_users = get_option( 'invited_gh_users', [] ); 57 $invited_gh_users[] = $result->id; 58 update_option( 'invited_gh_users', $invited_gh_users ); 60 if ( 61 is_wp_error( $result ) && 62 $github_username && 63 'Invitee is already a part of this org' === $result->get_error_data( 'api_error' )->errors[0]->message ?? '' 64 ) { 65 // Already a GitHub member, just add them to the team. 66 $result = add_to_team( $github_username, $team_ids ); 67 $message = 'User already a GitHub member, Added to team(s).'; 68 } 59 69 60 delete_site_transient( 'gh_invites' ); 70 if ( ! is_wp_error( $result ) ) { 71 if ( ! empty( $result->id ) ) { 72 // Note that it was invited via this site.. 73 $invited_gh_users = get_option( 'invited_gh_users', [] ); 74 $invited_gh_users[] = $result->id; 75 update_option( 'invited_gh_users', $invited_gh_users ); 76 77 delete_site_transient( 'gh_invites' ); 78 } 61 79 62 80 // Log it to Slack. -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/admin.php
r12671 r12678 80 80 <table class="form-table"> 81 81 <tr> 82 <th scope="row"><label for="invite">GitHub Email, WordPress.org user slug, or WordPress.org Profile URL</label></th>82 <th scope="row"><label for="invite">GitHub Email, GitHub URL, WordPress.org user slug, or WordPress.org Profile URL</label></th> 83 83 <td><input type="text" name="invite" id="invite" class="regular-text" placeholder="https://profiles.wordpress.org/<?php echo wp_get_current_user()->user_nicename; ?>/"></td> 84 84 </tr> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-github-invite/api.php
r12671 r12678 83 83 84 84 /** 85 * Add an organisation member to a team. 86 * 87 * @param int|string $who The GitHub user login. 88 * @param array $team_ids The team IDs to add the user to. 89 */ 90 function add_to_team( $who, array $team_ids ) { 91 $error = new WP_Error; 92 93 foreach ( $team_ids as $team_id ) { 94 $response = api( 95 "/orgs/{ORG}/team/{$team_id}/memberships/{$who}", 96 false, 97 'PUT' 98 ); 99 100 if ( is_wp_error( $response ) ) { 101 $error->merge_from( $response ); 102 } 103 } 104 105 if ( $error->get_error_code() ) { 106 return $error; 107 } 108 109 return $response; 110 } 111 112 /** 85 113 * Cancel an invitation by ID 86 114 */ … … 92 120 ); 93 121 } 94 95 122 96 123 /**
Note: See TracChangeset
for help on using the changeset viewer.