Skip to content

Commit

Permalink
Fix slackapi#445 by adding admin.usergroups.* API
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed May 7, 2020
1 parent 2a91976 commit 9e78cfa
Show file tree
Hide file tree
Showing 27 changed files with 452 additions and 27 deletions.
5 changes: 5 additions & 0 deletions json-logs/samples/api/admin.conversations.setTeams.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"ok": false,
"channel": "C00000000",
"error": "",
"response_metadata": {
"messages": [
""
]
},
"needed": "",
"provided": ""
}
6 changes: 6 additions & 0 deletions json-logs/samples/api/admin.usergroups.addChannels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ok": false,
"error": "",
"needed": "",
"provided": ""
}
55 changes: 55 additions & 0 deletions json-logs/samples/api/admin.usergroups.listChannels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"ok": false,
"channels": [
{
"id": "C00000000",
"name": "",
"is_channel": false,
"is_group": false,
"is_im": false,
"created": 12345,
"is_archived": false,
"is_general": false,
"unlinked": 12345,
"name_normalized": "",
"is_shared": false,
"creator": "W00000000",
"is_moved": 12345,
"is_ext_shared": false,
"is_org_shared": false,
"shared_team_ids": [
"T00000000"
],
"internal_team_ids": [
"T00000000"
],
"pending_shared": [
""
],
"pending_connected_team_ids": [
""
],
"is_pending_ext_shared": false,
"is_member": false,
"is_private": false,
"is_mpim": false,
"topic": {
"value": "",
"creator": "",
"last_set": 12345
},
"purpose": {
"value": "",
"creator": "",
"last_set": 12345
},
"previous_names": [
""
],
"date_connected": 12345
}
],
"error": "",
"needed": "",
"provided": ""
}
6 changes: 6 additions & 0 deletions json-logs/samples/api/admin.usergroups.removeChannels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ok": false,
"error": "",
"needed": "",
"provided": ""
}
3 changes: 2 additions & 1 deletion json-logs/samples/api/usergroups.create.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"groups": [
""
]
}
},
"channel_count": 12345
},
"error": "",
"needed": "",
Expand Down
4 changes: 3 additions & 1 deletion json-logs/samples/api/usergroups.list.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"groups": [
""
]
}
},
"user_count": 12345,
"channel_count": 12345
}
],
"error": "",
Expand Down
2 changes: 1 addition & 1 deletion misc/slack_ruby_app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
gem 'sinatra'
gem "rack-contrib"
gem 'slack-ruby-client'
gem 'slack-ruby-client', '0.14.6'
34 changes: 18 additions & 16 deletions misc/slack_ruby_app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.3)
activesupport (6.0.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
concurrent-ruby (1.1.5)
faraday (0.15.4)
zeitwerk (~> 2.2, >= 2.2.2)
concurrent-ruby (1.1.6)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
gli (2.18.0)
hashie (3.6.0)
i18n (1.6.0)
faraday_middleware (1.0.0)
faraday (~> 1.0)
gli (2.19.0)
hashie (4.1.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
multipart-post (2.0.0)
minitest (5.14.0)
multipart-post (2.1.1)
mustermann (1.0.3)
rack (2.0.8)
rack-contrib (2.1.0)
Expand All @@ -28,7 +29,7 @@ GEM
rack (~> 2.0)
rack-protection (= 2.0.5)
tilt (~> 2.0)
slack-ruby-client (0.14.1)
slack-ruby-client (0.14.6)
activesupport
faraday (>= 0.9)
faraday_middleware
Expand All @@ -37,19 +38,20 @@ GEM
websocket-driver
thread_safe (0.3.6)
tilt (2.0.9)
tzinfo (1.2.5)
tzinfo (1.2.7)
thread_safe (~> 0.1)
websocket-driver (0.7.0)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
websocket-extensions (0.1.4)
zeitwerk (2.3.0)

PLATFORMS
ruby

DEPENDENCIES
rack-contrib
sinatra
slack-ruby-client
slack-ruby-client (= 0.14.6)

BUNDLED WITH
2.0.1
2.1.4
2 changes: 1 addition & 1 deletion misc/slack_ruby_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def send_webhook(url, message)

get "/oauth" do
client = Slack::Web::Client.new
response = client.oauth_access(
response = client.oauth_v2_access(
client_id: ENV['SLACK_TEST_CLIENT_ID'],
client_secret: ENV['SLACK_TEST_CLIENT_SECRET'],
code: params[:code]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.slack.api.methods.request.admin.teams.AdminTeamsListRequest;
import com.slack.api.methods.request.admin.teams.owners.AdminTeamsOwnersListRequest;
import com.slack.api.methods.request.admin.teams.settings.*;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsAddChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsListChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsRemoveChannelsRequest;
import com.slack.api.methods.request.admin.users.*;
import com.slack.api.methods.request.api.ApiTestRequest;
import com.slack.api.methods.request.apps.AppsUninstallRequest;
Expand Down Expand Up @@ -68,6 +71,9 @@
import com.slack.api.methods.response.admin.teams.AdminTeamsListResponse;
import com.slack.api.methods.response.admin.teams.owners.AdminTeamsOwnersListResponse;
import com.slack.api.methods.response.admin.teams.settings.*;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsAddChannelsResponse;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsListChannelsResponse;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsRemoveChannelsResponse;
import com.slack.api.methods.response.admin.users.*;
import com.slack.api.methods.response.api.ApiTestResponse;
import com.slack.api.methods.response.apps.AppsUninstallResponse;
Expand Down Expand Up @@ -269,6 +275,22 @@ public interface AsyncMethodsClient {

CompletableFuture<AdminTeamsSettingsSetNameResponse> adminTeamsSettingsSetName(RequestConfigurator<AdminTeamsSettingsSetNameRequest.AdminTeamsSettingsSetNameRequestBuilder> req);

// ------------------------------
// admin.usergroups
// ------------------------------

CompletableFuture<AdminUsergroupsAddChannelsResponse> adminUsergroupsAddChannels(AdminUsergroupsAddChannelsRequest req);

CompletableFuture<AdminUsergroupsAddChannelsResponse> adminUsergroupsAddChannels(RequestConfigurator<AdminUsergroupsAddChannelsRequest.AdminUsergroupsAddChannelsRequestBuilder> req);

CompletableFuture<AdminUsergroupsListChannelsResponse> adminUsergroupsListChannels(AdminUsergroupsListChannelsRequest req);

CompletableFuture<AdminUsergroupsListChannelsResponse> adminUsergroupsListChannels(RequestConfigurator<AdminUsergroupsListChannelsRequest.AdminUsergroupsListChannelsRequestBuilder> req);

CompletableFuture<AdminUsergroupsRemoveChannelsResponse> adminUsergroupsRemoveChannels(AdminUsergroupsRemoveChannelsRequest req);

CompletableFuture<AdminUsergroupsRemoveChannelsResponse> adminUsergroupsRemoveChannels(RequestConfigurator<AdminUsergroupsRemoveChannelsRequest.AdminUsergroupsRemoveChannelsRequestBuilder> req);

// ------------------------------
// admin.users
// ------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ private Methods() {
public static final String ADMIN_TEAMS_SETTINGS_SET_ICON = "admin.teams.settings.setIcon";
public static final String ADMIN_TEAMS_SETTINGS_SET_NAME = "admin.teams.settings.setName";

// ------------------------------
// admin.usergroups
// ------------------------------

public static final String ADMIN_USERGROUPS_ADD_CHANNELS = "admin.usergroups.addChannels";
public static final String ADMIN_USERGROUPS_LIST_CHANNELS = "admin.usergroups.listChannels";
public static final String ADMIN_USERGROUPS_REMOVE_CHANNELS = "admin.usergroups.removeChannels";

// ------------------------------
// admin.users
// ------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.slack.api.methods.request.admin.teams.AdminTeamsListRequest;
import com.slack.api.methods.request.admin.teams.owners.AdminTeamsOwnersListRequest;
import com.slack.api.methods.request.admin.teams.settings.*;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsAddChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsListChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsRemoveChannelsRequest;
import com.slack.api.methods.request.admin.users.*;
import com.slack.api.methods.request.api.ApiTestRequest;
import com.slack.api.methods.request.apps.AppsUninstallRequest;
Expand Down Expand Up @@ -81,6 +84,9 @@
import com.slack.api.methods.response.admin.teams.AdminTeamsListResponse;
import com.slack.api.methods.response.admin.teams.owners.AdminTeamsOwnersListResponse;
import com.slack.api.methods.response.admin.teams.settings.*;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsAddChannelsResponse;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsListChannelsResponse;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsRemoveChannelsResponse;
import com.slack.api.methods.response.admin.users.*;
import com.slack.api.methods.response.api.ApiTestResponse;
import com.slack.api.methods.response.apps.AppsUninstallResponse;
Expand Down Expand Up @@ -341,6 +347,22 @@ <T extends SlackApiResponse> T postFormWithAuthorizationHeaderAndParseResponse(

AdminTeamsSettingsSetNameResponse adminTeamsSettingsSetName(RequestConfigurator<AdminTeamsSettingsSetNameRequest.AdminTeamsSettingsSetNameRequestBuilder> req) throws IOException, SlackApiException;

// ------------------------------
// admin.usergroups
// ------------------------------

AdminUsergroupsAddChannelsResponse adminUsergroupsAddChannels(AdminUsergroupsAddChannelsRequest req) throws IOException, SlackApiException;

AdminUsergroupsAddChannelsResponse adminUsergroupsAddChannels(RequestConfigurator<AdminUsergroupsAddChannelsRequest.AdminUsergroupsAddChannelsRequestBuilder> req) throws IOException, SlackApiException;

AdminUsergroupsListChannelsResponse adminUsergroupsListChannels(AdminUsergroupsListChannelsRequest req) throws IOException, SlackApiException;

AdminUsergroupsListChannelsResponse adminUsergroupsListChannels(RequestConfigurator<AdminUsergroupsListChannelsRequest.AdminUsergroupsListChannelsRequestBuilder> req) throws IOException, SlackApiException;

AdminUsergroupsRemoveChannelsResponse adminUsergroupsRemoveChannels(AdminUsergroupsRemoveChannelsRequest req) throws IOException, SlackApiException;

AdminUsergroupsRemoveChannelsResponse adminUsergroupsRemoveChannels(RequestConfigurator<AdminUsergroupsRemoveChannelsRequest.AdminUsergroupsRemoveChannelsRequestBuilder> req) throws IOException, SlackApiException;

// ------------------------------
// admin.users
// ------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import com.slack.api.methods.request.admin.teams.AdminTeamsListRequest;
import com.slack.api.methods.request.admin.teams.owners.AdminTeamsOwnersListRequest;
import com.slack.api.methods.request.admin.teams.settings.*;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsAddChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsListChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsRemoveChannelsRequest;
import com.slack.api.methods.request.admin.users.*;
import com.slack.api.methods.request.api.ApiTestRequest;
import com.slack.api.methods.request.apps.AppsUninstallRequest;
Expand Down Expand Up @@ -295,6 +298,29 @@ public static FormBody.Builder toForm(AdminTeamsSettingsSetNameRequest req) {
return form;
}

public static FormBody.Builder toForm(AdminUsergroupsAddChannelsRequest req) {
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("channel_ids", req.getChannelIds().stream().collect(joining(",")), form);
setIfNotNull("team_id", req.getTeamId(), form);
setIfNotNull("usergroup_id", req.getUsergroupId(), form);
return form;
}

public static FormBody.Builder toForm(AdminUsergroupsListChannelsRequest req) {
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("team_id", req.getTeamId(), form);
setIfNotNull("usergroup_id", req.getUsergroupId(), form);
setIfNotNull("include_num_members", req.getIncludeNumMembers(), form);
return form;
}

public static FormBody.Builder toForm(AdminUsergroupsRemoveChannelsRequest req) {
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("channel_ids", req.getChannelIds().stream().collect(joining(",")), form);
setIfNotNull("usergroup_id", req.getUsergroupId(), form);
return form;
}

public static FormBody.Builder toForm(AdminUsersAssignRequest req) {
FormBody.Builder form = new FormBody.Builder();
setIfNotNull("team_id", req.getTeamId(), form);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import com.slack.api.methods.request.admin.teams.AdminTeamsListRequest;
import com.slack.api.methods.request.admin.teams.owners.AdminTeamsOwnersListRequest;
import com.slack.api.methods.request.admin.teams.settings.*;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsAddChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsListChannelsRequest;
import com.slack.api.methods.request.admin.usergroups.AdminUsergroupsRemoveChannelsRequest;
import com.slack.api.methods.request.admin.users.*;
import com.slack.api.methods.request.api.ApiTestRequest;
import com.slack.api.methods.request.apps.AppsUninstallRequest;
Expand Down Expand Up @@ -72,6 +75,9 @@
import com.slack.api.methods.response.admin.teams.AdminTeamsListResponse;
import com.slack.api.methods.response.admin.teams.owners.AdminTeamsOwnersListResponse;
import com.slack.api.methods.response.admin.teams.settings.*;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsAddChannelsResponse;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsListChannelsResponse;
import com.slack.api.methods.response.admin.usergroups.AdminUsergroupsRemoveChannelsResponse;
import com.slack.api.methods.response.admin.users.*;
import com.slack.api.methods.response.api.ApiTestResponse;
import com.slack.api.methods.response.apps.AppsUninstallResponse;
Expand Down Expand Up @@ -426,6 +432,36 @@ public CompletableFuture<AdminTeamsSettingsSetNameResponse> adminTeamsSettingsSe
return adminTeamsSettingsSetName(req.configure(AdminTeamsSettingsSetNameRequest.builder()).build());
}

@Override
public CompletableFuture<AdminUsergroupsAddChannelsResponse> adminUsergroupsAddChannels(AdminUsergroupsAddChannelsRequest req) {
return executor.execute(ADMIN_USERGROUPS_ADD_CHANNELS, toMap(req), () -> methods.adminUsergroupsAddChannels(req));
}

@Override
public CompletableFuture<AdminUsergroupsAddChannelsResponse> adminUsergroupsAddChannels(RequestConfigurator<AdminUsergroupsAddChannelsRequest.AdminUsergroupsAddChannelsRequestBuilder> req) {
return adminUsergroupsAddChannels(req.configure(AdminUsergroupsAddChannelsRequest.builder()).build());
}

@Override
public CompletableFuture<AdminUsergroupsListChannelsResponse> adminUsergroupsListChannels(AdminUsergroupsListChannelsRequest req) {
return executor.execute(ADMIN_USERGROUPS_LIST_CHANNELS, toMap(req), () -> methods.adminUsergroupsListChannels(req));
}

@Override
public CompletableFuture<AdminUsergroupsListChannelsResponse> adminUsergroupsListChannels(RequestConfigurator<AdminUsergroupsListChannelsRequest.AdminUsergroupsListChannelsRequestBuilder> req) {
return adminUsergroupsListChannels(req.configure(AdminUsergroupsListChannelsRequest.builder()).build());
}

@Override
public CompletableFuture<AdminUsergroupsRemoveChannelsResponse> adminUsergroupsRemoveChannels(AdminUsergroupsRemoveChannelsRequest req) {
return executor.execute(ADMIN_USERGROUPS_REMOVE_CHANNELS, toMap(req), () -> methods.adminUsergroupsRemoveChannels(req));
}

@Override
public CompletableFuture<AdminUsergroupsRemoveChannelsResponse> adminUsergroupsRemoveChannels(RequestConfigurator<AdminUsergroupsRemoveChannelsRequest.AdminUsergroupsRemoveChannelsRequestBuilder> req) {
return adminUsergroupsRemoveChannels(req.configure(AdminUsergroupsRemoveChannelsRequest.builder()).build());
}

@Override
public CompletableFuture<AdminUsersAssignResponse> adminUsersAssign(AdminUsersAssignRequest req) {
return executor.execute(ADMIN_USERS_ASSIGN, toMap(req), () -> methods.adminUsersAssign(req));
Expand Down
Loading

0 comments on commit 9e78cfa

Please sign in to comment.