Skip to content

Commit d055632

Browse files
xXraphXxxXraphXx
authored andcommitted
Bug fix regarding pagination
#168 The Webex Teams api does not return all parameters when returning the next url link header. Consequently, the object listing can be broken or worse, can succeed without returning objects expected by the provided filter. Example: a bot needs to specify mentionedPeople=me to be allowed to list room messages. If there are several pages to be returned then the listing will fail because the mentionedPeople query parameter won't be specified when fetching the next pages Signed-off-by: xXraphXx <[email protected]>
1 parent 6733127 commit d055632

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

webexteamssdk/restsession.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161

6262
# Helper Functions
63-
def _fix_next_url(next_url):
63+
def _fix_next_url(next_url, params):
6464
"""Remove max=null parameter from URL.
6565
6666
Patch for Webex Teams Defect: "next" URL returned in the Link headers of
@@ -96,6 +96,10 @@ def _fix_next_url(next_url):
9696
query_list.remove("max=null")
9797
warnings.warn("`max=null` still present in next-URL returned "
9898
"from Webex Teams", RuntimeWarning)
99+
if params:
100+
for k, v in params.items():
101+
if not any(p.startswith('{}='.format(k)) for p in query_list):
102+
query_list.append('{}={}'.format(k, v))
99103
new_query = "&".join(query_list)
100104
parsed_url = list(parsed_url)
101105
parsed_url[4] = new_query
@@ -151,7 +155,7 @@ def user_agent(be_geo_id=None, caller=None):
151155
data["cpu"] = platform.machine()
152156

153157
data["organization"] = {}
154-
158+
155159
# Add self-identified organization information to the User-Agent Header.
156160
if be_geo_id:
157161
data["organization"]["be_geo_id"] = be_geo_id
@@ -231,7 +235,6 @@ def __init__(self, access_token, base_url,
231235
if disable_ssl_verify:
232236
self._req_session.verify = False
233237

234-
235238
if proxies is not None:
236239
self._req_session.proxies.update(proxies)
237240

@@ -424,11 +427,13 @@ def get_pages(self, url, params=None, **kwargs):
424427
if response.links.get("next"):
425428
next_url = response.links.get("next").get("url")
426429

427-
# Patch for Webex Teams "max=null" in next URL bug.
430+
# Patch for Webex Teams "max=null" in next URL bug + missing
431+
# params, like mentionedPeople, which can be mandatory for
432+
# bots
428433
# Testing shows that patch is no longer needed; raising a
429434
# warnning if it is still taking effect;
430435
# considering for future removal
431-
next_url = _fix_next_url(next_url)
436+
next_url = _fix_next_url(next_url, params)
432437

433438
# Subsequent requests
434439
response = self.request("GET", next_url, erc, **kwargs)

0 commit comments

Comments
 (0)