Changeset 10824
- Timestamp:
- 03/17/2021 01:34:10 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/slack/subgroup.php
r10823 r10824 2 2 3 3 namespace Dotorg\Slack\Subgroup; 4 use const Dotorg\Slack\WORDPRESSORG_USER_ID as WORDPRESSORG_SLACK_USER_ID; 4 5 5 6 require dirname( dirname( __DIR__ ) ) . '/includes/slack-config.php'; … … 22 23 // Confirm it came from Slack. 23 24 if ( $_POST['token'] !== WEBHOOK_TOKEN ) { 24 die ;25 die( "Invalid Token" ); 25 26 } 26 27 27 28 $current_group_id = $_POST['channel_id']; 28 29 29 // If it didn't come from a group, die. 30 if ( $current_group_id[0] !== 'G' ) { 31 die; 32 } 30 // Note: We no longer check to see if the calling channel is a group, as the below list command will limit it to private channels. 31 // Groups can begin with `G` (old created groups) or `C` (private channel), public channels also begin with `C` so the below check is safer. 33 32 34 33 // Get a list of all groups @wordpressdotorg is in. … … 41 40 'limit' => 999, 42 41 ] 43 ) ;42 )['channels']; 44 43 45 44 // Find the group that we are in right now. 46 foreach ( $groups ['channels']as $group ) {45 foreach ( $groups as $group ) { 47 46 if ( $group['id'] === $current_group_id ) { 48 47 $found = true; … … 61 60 } 62 61 62 // Get the current groups members. 63 $members = api_call( 64 // https://api.slack.com/methods/conversations.members 65 'conversations.members', 66 [ 67 'channel' => $group['id'], 68 'limit' => 999, 69 ] 70 )['members']; 71 63 72 // Ensure the calling user is in the main group. 64 if ( ! in_array( $_POST['user_id'], $ group['members'], true ) ) {73 if ( ! in_array( $_POST['user_id'], $members, true ) ) { 65 74 die; 66 75 } … … 79 88 'conversations.create', 80 89 [ 81 'name' => $subcommand,90 'name' => $subcommand, 82 91 'is_private' => true, 83 92 ] … … 95 104 'text' => sprintf( 96 105 'Group %s created by <@%s>.', 97 $new_group[' group']['name'],106 $new_group['channel']['name'], 98 107 $_POST['user_id'] 99 108 ), … … 103 112 104 113 // Invite all current parent channel members to the new channel. 105 $members = api_call( 106 // https://api.slack.com/methods/conversations.members 107 'conversations.members', 108 [ 109 'channel' => 'CMYKV0D7B', 110 'limit' => 999, 111 ] 112 ); 113 if ( empty( $members['members'] ) ) { 114 die( sprintf( "Group %s created, but could not invite members.", $new_group['group']['name'] ) ); 115 } 116 114 // Note: Cannot invite self. 117 115 api_call( 118 116 // https://api.slack.com/methods/conversations.invite 119 117 'conversations.invite', 120 118 [ 121 'channel' => $new_group[' group']['id'],122 'users' => implode( ',', $members['members']),119 'channel' => $new_group['channel']['id'], 120 'users' => implode( ',', array_diff( $members, [ WORDPRESSORG_SLACK_USER_ID ] ) ), 123 121 ] 124 122 ); … … 152 150 foreach ( $groups as $group ) { 153 151 if ( strpos( $group['name'], $parent_group['name'] . '-' ) === 0 ) { 154 if ( ! in_array( $_POST['user_id'], $group['members'], true ) ) { 152 153 $group_members = api_call( 154 // https://api.slack.com/methods/conversations.members 155 'conversations.members', 156 [ 157 'channel' => $group['id'], 158 'limit' => 999, 159 ] 160 ); 161 162 if ( ! in_array( $_POST['user_id'], $group_members['members'], true ) ) { 155 163 $groups_to_add[] = $group['name']; 156 164 }
Note: See TracChangeset
for help on using the changeset viewer.