Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1283 - Add conversations (slack connect) and admin.auth.policy API methods #1284

Merged
merged 5 commits into from Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 60 additions & 2 deletions packages/web-api/src/methods.ts
Expand Up @@ -3,6 +3,9 @@ import { Dialog, View, KnownBlock, Block, MessageAttachment, LinkUnfurls, CallUs
import { WebAPICallOptions, WebAPICallResult, WebClient, WebClientEvent } from './WebClient';
import { EventEmitter } from 'eventemitter3';

import { AdminAuthPolicyAssignEntitiesResponse } from './response/AdminAuthPolicyAssignEntitiesResponse';
import { AdminAuthPolicyGetEntitiesResponse } from './response/AdminAuthPolicyGetEntitiesResponse';
import { AdminAuthPolicyRemoveEntitiesResponse } from './response/AdminAuthPolicyRemoveEntitiesResponse';
import { AdminAppsApproveResponse } from './response/AdminAppsApproveResponse';
import { AdminAppsApprovedListResponse } from './response/AdminAppsApprovedListResponse';
import { AdminAppsRequestsListResponse } from './response/AdminAppsRequestsListResponse';
Expand Down Expand Up @@ -240,6 +243,13 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
},
uninstall: bindApiCall<AdminAppsUninstallArguments, AdminAppsUninstallResponse>(this, 'admin.apps.uninstall'),
},
auth: {
policy: {
assignEntities: bindApiCall<AdminAuthPolicyAssignEntitiesArguments, AdminAuthPolicyAssignEntitiesResponse>(this, 'admin.auth.policy.assignEntities'),
getEntities: bindApiCall<AdminAuthPolicyGetEntitiesArguments, AdminAuthPolicyGetEntitiesResponse>(this, 'admin.auth.policy.getEntities'),
removeEntities: bindApiCall<AdminAuthPolicyRemoveEntitiesArguments, AdminAuthPolicyRemoveEntitiesResponse>(this, 'admin.auth.policy.removeEntities'),
},
},
barriers: {
create: bindApiCall<AdminBarriersCreateArguments, AdminBarriersCreateResponse>(this, 'admin.barriers.create'),
delete: bindApiCall<AdminBarriersDeleteArguments, AdminBarriersDeleteResponse>(this, 'admin.barriers.delete'),
Expand Down Expand Up @@ -437,16 +447,21 @@ export abstract class Methods extends EventEmitter<WebClientEvent> {
};

public readonly conversations = {
acceptSharedInvite: bindApiCall<ConversationsAcceptSharedInviteArguments, WebAPICallResult>(this, 'conversations.acceptSharedInvite'),
approveSharedInvite: bindApiCall<ConversationsApproveSharedInviteArguments, WebAPICallResult>(this, 'conversations.approveSharedInvite'),
archive: bindApiCall<ConversationsArchiveArguments, ConversationsArchiveResponse>(this, 'conversations.archive'),
close: bindApiCall<ConversationsCloseArguments, ConversationsCloseResponse>(this, 'conversations.close'),
create: bindApiCall<ConversationsCreateArguments, ConversationsCreateResponse>(this, 'conversations.create'),
declineSharedInvite: bindApiCall<ConversationsDeclineSharedInviteArguments, WebAPICallResult>(this, 'conversations.declineSharedInvite'),
history: bindApiCall<ConversationsHistoryArguments, ConversationsHistoryResponse>(this, 'conversations.history'),
info: bindApiCall<ConversationsInfoArguments, ConversationsInfoResponse>(this, 'conversations.info'),
invite: bindApiCall<ConversationsInviteArguments, ConversationsInviteResponse>(this, 'conversations.invite'),
inviteShared: bindApiCall<ConversationsInviteSharedArguments, WebAPICallResult>(this, 'conversations.inviteShared'),
join: bindApiCall<ConversationsJoinArguments, ConversationsJoinResponse>(this, 'conversations.join'),
kick: bindApiCall<ConversationsKickArguments, ConversationsKickResponse>(this, 'conversations.kick'),
leave: bindApiCall<ConversationsLeaveArguments, ConversationsLeaveResponse>(this, 'conversations.leave'),
list: bindApiCall<ConversationsListArguments, ConversationsListResponse>(this, 'conversations.list'),
listConnectInvites: bindApiCall<ConversationsListConnectInvitesArguments, WebAPICallResult>(this, 'conversations.listConnectInvites'),
mark: bindApiCall<ConversationsMarkArguments, ConversationsMarkResponse>(this, 'conversations.mark'),
members: bindApiCall<ConversationsMembersArguments, ConversationsMembersResponse>(this, 'conversations.members'),
open: bindApiCall<ConversationsOpenArguments, ConversationsOpenResponse>(this, 'conversations.open'),
Expand Down Expand Up @@ -717,8 +732,8 @@ export interface TraditionalPagingEnabled {
*/

/*
* `admin.*`
*/
* `admin.*`
*/
export interface AdminAppsApproveArguments extends WebAPICallOptions, TokenOverridable {
app_id?: string;
request_id?: string;
Expand Down Expand Up @@ -754,6 +769,22 @@ export interface AdminAppsUninstallArguments extends WebAPICallOptions {
enterprise_id?: string;
team_ids?: string[];
}
export interface AdminAuthPolicyAssignEntitiesArguments extends WebAPICallOptions, TokenOverridable {
srajiang marked this conversation as resolved.
Show resolved Hide resolved
entity_ids: string[];
entity_type: string;
policy_name: string;
}
export interface AdminAuthPolicyGetEntitiesArguments extends WebAPICallOptions, TokenOverridable,
CursorPaginationEnabled {
policy_name: string;
entity_type?: string;
}
cursorPaginationEnabledMethods.add('admin.auth.policy.getEntities');
export interface AdminAuthPolicyRemoveEntitiesArguments extends WebAPICallOptions, TokenOverridable {
entity_ids: string[];
entity_type: string;
policy_name: string;
}
export interface AdminBarriersCreateArguments extends WebAPICallOptions, TokenOverridable {
barriered_from_usergroup_ids: string[];
primary_usergroup_id: string;
Expand Down Expand Up @@ -1268,6 +1299,18 @@ export interface ChatUpdateArguments extends WebAPICallOptions, TokenOverridable
/*
* `conversations.*`
*/
export interface ConversationsAcceptSharedInviteArguments extends WebAPICallOptions, TokenOverridable {
channel_name: string;
channel_id?: string;
free_trial_accepted?: boolean;
invite_id?: string;
is_private?: boolean;
team_id?: string;
}
export interface ConversationsApproveSharedInviteArguments extends WebAPICallOptions, TokenOverridable {
invite_id: string;
target_team?: string;
}
export interface ConversationsArchiveArguments extends WebAPICallOptions, TokenOverridable {
channel: string;
}
Expand All @@ -1279,6 +1322,10 @@ export interface ConversationsCreateArguments extends WebAPICallOptions, TokenOv
is_private?: boolean;
team_id?: string;
}
export interface ConversationsDeclineSharedInviteArguments extends WebAPICallOptions, TokenOverridable {
invite_id: string;
target_team?: string;
}
export interface ConversationsHistoryArguments extends WebAPICallOptions, TokenOverridable, CursorPaginationEnabled,
TimelinePaginationEnabled {
channel: string;
Expand All @@ -1292,6 +1339,11 @@ export interface ConversationsInviteArguments extends WebAPICallOptions, TokenOv
channel: string;
users: string; // comma-separated list of users
}
export interface ConversationsInviteSharedArguments extends WebAPICallOptions, TokenOverridable {
channel: string;
emails?: string[];
user_ids?: string[];
}
export interface ConversationsJoinArguments extends WebAPICallOptions, TokenOverridable {
channel: string;
}
Expand All @@ -1308,6 +1360,12 @@ export interface ConversationsListArguments extends WebAPICallOptions, TokenOver
team_id?: string;
}
cursorPaginationEnabledMethods.add('conversations.list');
export interface ConversationsListConnectInvitesArguments extends WebAPICallOptions, TokenOverridable {
count?: number;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method accepts a count and a cursor option, and so it doesn't to conform to CursorPaginationEnabled or TraditionalPagingEnabled interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... the 3rd pattern came here.

cursor?: string;
team_id?: string;
}
cursorPaginationEnabledMethods.add('conversations.listConnectInvites');
export interface ConversationsMarkArguments extends WebAPICallOptions, TokenOverridable {
channel: string;
ts: string;
Expand Down
@@ -0,0 +1,9 @@
/* tslint:disable */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by generate-web-api-types.sh

import { WebAPICallResult } from '../WebClient';
export type AdminAuthPolicyAssignEntitiesResponse = WebAPICallResult & {
ok?: boolean;
entity_total_count?: number;
error?: string;
needed?: string;
provided?: string;
};
@@ -0,0 +1,16 @@
/* tslint:disable */
import { WebAPICallResult } from '../WebClient';
export type AdminAuthPolicyGetEntitiesResponse = WebAPICallResult & {
ok?: boolean;
error?: string;
entities?: Entity[];
entity_total_count?: number;
needed?: string;
provided?: string;
};

export interface Entity {
entity_id?: string;
entity_type?: string;
date_added?: number;
}
@@ -0,0 +1,9 @@
/* tslint:disable */
import { WebAPICallResult } from '../WebClient';
export type AdminAuthPolicyRemoveEntitiesResponse = WebAPICallResult & {
ok?: boolean;
entity_total_count?: number;
error?: string;
needed?: string;
provided?: string;
};
34 changes: 34 additions & 0 deletions packages/web-api/src/response/SearchAllResponse.ts
Expand Up @@ -140,6 +140,7 @@ export interface MessagesMatch {
attachments?: MatchAttachment[];
is_mpim?: boolean;
score?: number;
files?: File[];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here aren't relevant to PR, but auto-generated by generate-web-api-types.sh
See also, SearchMessagesResponse.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is fine. We've detected this pattern and updated the type def very recently.

}

export interface MatchAttachment {
Expand Down Expand Up @@ -343,6 +344,39 @@ export interface Channel {
name_normalized?: string;
}

export interface File {
id?: string;
created?: number;
timestamp?: number;
name?: string;
title?: string;
mimetype?: string;
filetype?: string;
pretty_type?: string;
user?: string;
editable?: boolean;
size?: number;
mode?: string;
is_external?: boolean;
external_type?: string;
is_public?: boolean;
public_url_shared?: boolean;
display_as_bot?: boolean;
username?: string;
url_private?: string;
url_private_download?: string;
permalink?: string;
permalink_public?: string;
edit_link?: string;
preview?: string;
preview_highlight?: string;
lines?: number;
lines_more?: number;
preview_is_truncated?: boolean;
is_starred?: boolean;
has_rich_preview?: boolean;
}

export interface Previous {
type?: string;
user?: string;
Expand Down
34 changes: 34 additions & 0 deletions packages/web-api/src/response/SearchMessagesResponse.ts
Expand Up @@ -33,6 +33,7 @@ export interface Match {
attachments?: MatchAttachment[];
is_mpim?: boolean;
score?: number;
files?: File[];
}

export interface MatchAttachment {
Expand Down Expand Up @@ -236,6 +237,39 @@ export interface Channel {
name_normalized?: string;
}

export interface File {
id?: string;
created?: number;
timestamp?: number;
name?: string;
title?: string;
mimetype?: string;
filetype?: string;
pretty_type?: string;
user?: string;
editable?: boolean;
size?: number;
mode?: string;
is_external?: boolean;
external_type?: string;
is_public?: boolean;
public_url_shared?: boolean;
display_as_bot?: boolean;
username?: string;
url_private?: string;
url_private_download?: string;
permalink?: string;
permalink_public?: string;
edit_link?: string;
preview?: string;
preview_highlight?: string;
lines?: number;
lines_more?: number;
preview_is_truncated?: boolean;
is_starred?: boolean;
has_rich_preview?: boolean;
}

export interface Previous {
type?: string;
user?: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/web-api/src/response/index.ts
Expand Up @@ -6,6 +6,9 @@ export { AdminAppsRequestsListResponse } from './AdminAppsRequestsListResponse';
export { AdminAppsRestrictResponse } from './AdminAppsRestrictResponse';
export { AdminAppsRestrictedListResponse } from './AdminAppsRestrictedListResponse';
export { AdminAppsUninstallResponse } from './AdminAppsUninstallResponse';
export { AdminAuthPolicyAssignEntitiesResponse } from './AdminAuthPolicyAssignEntitiesResponse';
export { AdminAuthPolicyGetEntitiesResponse } from './AdminAuthPolicyGetEntitiesResponse';
export { AdminAuthPolicyRemoveEntitiesResponse } from './AdminAuthPolicyRemoveEntitiesResponse';
export { AdminBarriersCreateResponse } from './AdminBarriersCreateResponse';
export { AdminBarriersDeleteResponse } from './AdminBarriersDeleteResponse';
export { AdminBarriersListResponse } from './AdminBarriersListResponse';
Expand Down
39 changes: 38 additions & 1 deletion prod-server-integration-tests/test/admin-web-api.js
Expand Up @@ -69,4 +69,41 @@ describe('admin.* Web APIs', function () {
assert.equal(get3.no_settings_applied.length, userIds.length);
});
});
});

describe('admin.auth.policy.{assign|get|remove}Entities', function () {
/*
To run this test suite manually, you need an email_password auth policy
enabled on the Enterprise Org. For this, you need to have an Enterprise Org
with SSO enabled. You will additionally need to export a User ID for
a user managed by the IDP for testing.

export SLACK_SDK_TEST_GRID_USER_ID=
*/
it('should assign an entity', async function () {
const res = await orgAdminClient.admin.auth.policy.assignEntities({
entity_ids: [process.env.SLACK_SDK_TEST_GRID_USER_ID],
entity_type: "USER",
policy_name: "email_password",
});
assert.equal(res.ok, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the following assertion is a bit easier to check the result than just knowing false

assert.isUndefined(res.error);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added these assertions!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srajiang Thanks. Perhaps, you can remove assert.equal(res.ok, true); in L88 because the old assertion fails before the newly added one 😸

assert.isUndefined(res.error);
})
it('should get entities', async function () {
const res2 = await orgAdminClient.admin.auth.policy.getEntities({
policy_name: "email_password",
});
logger.info(res2);
assert.equal(res2.ok, true);
assert.isUndefined(res2.error);
})
it('should remove entities', async function () {
const res3 = await orgAdminClient.admin.auth.policy.removeEntities({
entity_ids: [process.env.SLACK_SDK_TEST_GRID_USER_ID],
entity_type: "USER",
policy_name: "email_password",
})
assert.equal(res3.ok, true);
assert.isUndefined(res3.error);
})
})
});