Skip to content

Commit e2e90b5

Browse files
authored
Merge branch 'main' into hotfix-sqlalchemy-oauth-model
2 parents b805a3d + 0a3166c commit e2e90b5

8 files changed

Lines changed: 289 additions & 5 deletions

File tree

integration_tests/env_variable_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID_2 = "SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID_2"
2828
SLACK_SDK_TEST_GRID_TEAM_ID = "SLACK_SDK_TEST_GRID_TEAM_ID"
2929
SLACK_SDK_TEST_GRID_USER_ID = "SLACK_SDK_TEST_GRID_USER_ID"
30+
# The following user must be a full member, who is not a primary owner
31+
SLACK_SDK_TEST_GRID_USER_ID_ADMIN_AUTH = "SLACK_SDK_TEST_GRID_USER_ID_ADMIN_AUTH"
3032

3133
# Webhook
3234
SLACK_SDK_TEST_INCOMING_WEBHOOK_URL = "SLACK_SDK_TEST_INCOMING_WEBHOOK_URL"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import logging
2+
import os
3+
import unittest
4+
5+
from integration_tests.env_variable_names import (
6+
SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN,
7+
SLACK_SDK_TEST_GRID_USER_ID_ADMIN_AUTH,
8+
)
9+
from integration_tests.helpers import async_test
10+
from slack_sdk.web import WebClient
11+
from slack_sdk.web.async_client import AsyncWebClient
12+
13+
14+
class TestWebClient(unittest.TestCase):
15+
"""Runs integration tests with real Slack API"""
16+
17+
def setUp(self):
18+
self.logger = logging.getLogger(__name__)
19+
self.org_admin_token = os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN]
20+
self.sync_client: WebClient = WebClient(token=self.org_admin_token)
21+
self.async_client: AsyncWebClient = AsyncWebClient(token=self.org_admin_token)
22+
self.user_ids = [os.environ[SLACK_SDK_TEST_GRID_USER_ID_ADMIN_AUTH]]
23+
24+
def tearDown(self):
25+
pass
26+
27+
def test_sync(self):
28+
client = self.sync_client
29+
30+
list = client.admin_auth_policy_getEntities(
31+
policy_name="email_password", limit=3
32+
)
33+
self.assertIsNotNone(list)
34+
35+
assignment = client.admin_auth_policy_assignEntities(
36+
entity_ids=self.user_ids,
37+
policy_name="email_password",
38+
entity_type="USER",
39+
)
40+
self.assertIsNotNone(assignment)
41+
self.assertEqual(
42+
list["entity_total_count"] + 1, assignment["entity_total_count"]
43+
)
44+
45+
removal = client.admin_auth_policy_removeEntities(
46+
entity_ids=self.user_ids,
47+
policy_name="email_password",
48+
entity_type="USER",
49+
)
50+
self.assertIsNotNone(removal)
51+
self.assertEqual(list["entity_total_count"], removal["entity_total_count"])
52+
53+
@async_test
54+
async def test_async(self):
55+
client = self.async_client
56+
57+
list = await client.admin_auth_policy_getEntities(
58+
policy_name="email_password", limit=3
59+
)
60+
self.assertIsNotNone(list)
61+
62+
assignment = await client.admin_auth_policy_assignEntities(
63+
entity_ids=self.user_ids,
64+
policy_name="email_password",
65+
entity_type="USER",
66+
)
67+
self.assertIsNotNone(assignment)
68+
self.assertEqual(
69+
list["entity_total_count"] + 1, assignment["entity_total_count"]
70+
)
71+
72+
removal = await client.admin_auth_policy_removeEntities(
73+
entity_ids=self.user_ids,
74+
policy_name="email_password",
75+
entity_type="USER",
76+
)
77+
self.assertIsNotNone(removal)
78+
self.assertEqual(list["entity_total_count"], removal["entity_total_count"])

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"pytest-cov>=2,<3",
2424
"codecov>=2,<3",
2525
"flake8>=3,<4",
26-
"black==21.5b1",
26+
"black==21.6b0",
2727
"psutil>=5,<6",
2828
"databases>=0.3",
2929
]
3030
codegen_dependencies = [
31-
"black==21.5b1",
31+
"black==21.6b0",
3232
]
3333

3434
needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)

slack_sdk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Check the latest version at https://pypi.org/project/slack-sdk/"""
2-
__version__ = "3.6.0"
2+
__version__ = "3.7.0"

slack_sdk/web/async_client.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,65 @@ async def admin_apps_uninstall(
182182
"admin.apps.uninstall", http_verb="POST", params=kwargs
183183
)
184184

185+
async def admin_auth_policy_getEntities(
186+
self,
187+
*,
188+
policy_name: str,
189+
cursor: Optional[str] = None,
190+
entity_type: Optional[str] = None,
191+
limit: Optional[int] = None,
192+
**kwargs
193+
) -> AsyncSlackResponse:
194+
"""Fetch all the entities assigned to a particular authentication policy by name."""
195+
kwargs.update({"policy_name": policy_name})
196+
if cursor is not None:
197+
kwargs.update({"cursor": cursor})
198+
if entity_type is not None:
199+
kwargs.update({"entity_type": entity_type})
200+
if limit is not None:
201+
kwargs.update({"limit": limit})
202+
return await self.api_call(
203+
"admin.auth.policy.getEntities", http_verb="POST", params=kwargs
204+
)
205+
206+
async def admin_auth_policy_assignEntities(
207+
self,
208+
*,
209+
entity_ids: Union[str, Sequence[str]],
210+
policy_name: str,
211+
entity_type: str,
212+
**kwargs
213+
) -> AsyncSlackResponse:
214+
"""Assign entities to a particular authentication policy."""
215+
if isinstance(entity_ids, (list, Tuple)):
216+
kwargs.update({"entity_ids": ",".join(entity_ids)})
217+
else:
218+
kwargs.update({"entity_ids": entity_ids})
219+
kwargs.update({"policy_name": policy_name})
220+
kwargs.update({"entity_type": entity_type})
221+
return await self.api_call(
222+
"admin.auth.policy.assignEntities", http_verb="POST", params=kwargs
223+
)
224+
225+
async def admin_auth_policy_removeEntities(
226+
self,
227+
*,
228+
entity_ids: Union[str, Sequence[str]],
229+
policy_name: str,
230+
entity_type: str,
231+
**kwargs
232+
) -> AsyncSlackResponse:
233+
"""Remove specified entities from a specified authentication policy."""
234+
if isinstance(entity_ids, (list, Tuple)):
235+
kwargs.update({"entity_ids": ",".join(entity_ids)})
236+
else:
237+
kwargs.update({"entity_ids": entity_ids})
238+
kwargs.update({"policy_name": policy_name})
239+
kwargs.update({"entity_type": entity_type})
240+
return await self.api_call(
241+
"admin.auth.policy.removeEntities", http_verb="POST", params=kwargs
242+
)
243+
185244
async def admin_barriers_create(
186245
self,
187246
*,

slack_sdk/web/client.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,65 @@ def admin_apps_uninstall(
165165
kwargs.update({"team_ids": team_ids})
166166
return self.api_call("admin.apps.uninstall", http_verb="POST", params=kwargs)
167167

168+
def admin_auth_policy_getEntities(
169+
self,
170+
*,
171+
policy_name: str,
172+
cursor: Optional[str] = None,
173+
entity_type: Optional[str] = None,
174+
limit: Optional[int] = None,
175+
**kwargs
176+
) -> SlackResponse:
177+
"""Fetch all the entities assigned to a particular authentication policy by name."""
178+
kwargs.update({"policy_name": policy_name})
179+
if cursor is not None:
180+
kwargs.update({"cursor": cursor})
181+
if entity_type is not None:
182+
kwargs.update({"entity_type": entity_type})
183+
if limit is not None:
184+
kwargs.update({"limit": limit})
185+
return self.api_call(
186+
"admin.auth.policy.getEntities", http_verb="POST", params=kwargs
187+
)
188+
189+
def admin_auth_policy_assignEntities(
190+
self,
191+
*,
192+
entity_ids: Union[str, Sequence[str]],
193+
policy_name: str,
194+
entity_type: str,
195+
**kwargs
196+
) -> SlackResponse:
197+
"""Assign entities to a particular authentication policy."""
198+
if isinstance(entity_ids, (list, Tuple)):
199+
kwargs.update({"entity_ids": ",".join(entity_ids)})
200+
else:
201+
kwargs.update({"entity_ids": entity_ids})
202+
kwargs.update({"policy_name": policy_name})
203+
kwargs.update({"entity_type": entity_type})
204+
return self.api_call(
205+
"admin.auth.policy.assignEntities", http_verb="POST", params=kwargs
206+
)
207+
208+
def admin_auth_policy_removeEntities(
209+
self,
210+
*,
211+
entity_ids: Union[str, Sequence[str]],
212+
policy_name: str,
213+
entity_type: str,
214+
**kwargs
215+
) -> SlackResponse:
216+
"""Remove specified entities from a specified authentication policy."""
217+
if isinstance(entity_ids, (list, Tuple)):
218+
kwargs.update({"entity_ids": ",".join(entity_ids)})
219+
else:
220+
kwargs.update({"entity_ids": entity_ids})
221+
kwargs.update({"policy_name": policy_name})
222+
kwargs.update({"entity_type": entity_type})
223+
return self.api_call(
224+
"admin.auth.policy.removeEntities", http_verb="POST", params=kwargs
225+
)
226+
168227
def admin_barriers_create(
169228
self,
170229
*,

slack_sdk/web/legacy_client.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,65 @@ def admin_apps_uninstall(
178178
kwargs.update({"team_ids": team_ids})
179179
return self.api_call("admin.apps.uninstall", http_verb="POST", params=kwargs)
180180

181+
def admin_auth_policy_getEntities(
182+
self,
183+
*,
184+
policy_name: str,
185+
cursor: Optional[str] = None,
186+
entity_type: Optional[str] = None,
187+
limit: Optional[int] = None,
188+
**kwargs
189+
) -> Union[Future, SlackResponse]:
190+
"""Fetch all the entities assigned to a particular authentication policy by name."""
191+
kwargs.update({"policy_name": policy_name})
192+
if cursor is not None:
193+
kwargs.update({"cursor": cursor})
194+
if entity_type is not None:
195+
kwargs.update({"entity_type": entity_type})
196+
if limit is not None:
197+
kwargs.update({"limit": limit})
198+
return self.api_call(
199+
"admin.auth.policy.getEntities", http_verb="POST", params=kwargs
200+
)
201+
202+
def admin_auth_policy_assignEntities(
203+
self,
204+
*,
205+
entity_ids: Union[str, Sequence[str]],
206+
policy_name: str,
207+
entity_type: str,
208+
**kwargs
209+
) -> Union[Future, SlackResponse]:
210+
"""Assign entities to a particular authentication policy."""
211+
if isinstance(entity_ids, (list, Tuple)):
212+
kwargs.update({"entity_ids": ",".join(entity_ids)})
213+
else:
214+
kwargs.update({"entity_ids": entity_ids})
215+
kwargs.update({"policy_name": policy_name})
216+
kwargs.update({"entity_type": entity_type})
217+
return self.api_call(
218+
"admin.auth.policy.assignEntities", http_verb="POST", params=kwargs
219+
)
220+
221+
def admin_auth_policy_removeEntities(
222+
self,
223+
*,
224+
entity_ids: Union[str, Sequence[str]],
225+
policy_name: str,
226+
entity_type: str,
227+
**kwargs
228+
) -> Union[Future, SlackResponse]:
229+
"""Remove specified entities from a specified authentication policy."""
230+
if isinstance(entity_ids, (list, Tuple)):
231+
kwargs.update({"entity_ids": ",".join(entity_ids)})
232+
else:
233+
kwargs.update({"entity_ids": entity_ids})
234+
kwargs.update({"policy_name": policy_name})
235+
kwargs.update({"entity_type": entity_type})
236+
return self.api_call(
237+
"admin.auth.policy.removeEntities", http_verb="POST", params=kwargs
238+
)
239+
181240
def admin_barriers_create(
182241
self,
183242
*,

0 commit comments

Comments
 (0)