Skip to content

Commit 9fc40f5

Browse files
author
Alejandro Casanovas
committed
Fixing resource parsing (googleapis#343)
1 parent bd97f66 commit 9fc40f5

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

O365/utils/utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
ME_RESOURCE = 'me'
1414
USERS_RESOURCE = 'users'
15+
GROUPS_RESOURCE = 'groups'
16+
SITES_RESOURCE = 'sites'
1517

1618
NEXT_LINK_KEYWORD = '@odata.nextLink'
1719

@@ -348,13 +350,26 @@ def __repr__(self):
348350
def _parse_resource(resource):
349351
""" Parses and completes resource information """
350352
resource = resource.strip() if resource else resource
351-
if resource in {ME_RESOURCE, USERS_RESOURCE}:
353+
if resource in {ME_RESOURCE, USERS_RESOURCE, GROUPS_RESOURCE, SITES_RESOURCE}:
352354
return resource
355+
elif resource.startswith('user:'):
356+
# user resource shorthand
357+
resource = resource.replace('user:', '', 1)
358+
return '{}/{}'.format(USERS_RESOURCE, resource)
353359
elif '@' in resource and not resource.startswith(USERS_RESOURCE):
360+
# user resource backup
354361
# when for example accessing a shared mailbox the
355362
# resource is set to the email address. we have to prefix
356363
# the email with the resource 'users/' so --> 'users/email_address'
357364
return '{}/{}'.format(USERS_RESOURCE, resource)
365+
elif resource.startswith('group:'):
366+
# group resource shorthand
367+
resource = resource.replace('group:', '', 1)
368+
return '{}/{}'.format(GROUPS_RESOURCE, resource)
369+
elif resource.startswith('site:'):
370+
# sharepoint site resource shorthand
371+
resource = resource.replace('site:', '', 1)
372+
return '{}/{}'.format(SITES_RESOURCE, resource)
358373
else:
359374
return resource
360375

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,10 @@ Usually you will work with the default 'ME' resource, but you can also use one o
537537

538538
- **'me'**: the user which has given consent. the default for every protocol. Overwritten when using "with your own identity" authentication method (Only available on the authorization auth_flow_type).
539539
- **'user:user@domain.com'**: a shared mailbox or a user account for which you have permissions. If you don't provide 'user:' will be infered anyways.
540-
- **'sharepoint:sharepoint-site-id'**: a sharepoint site id.
541-
- **'group:group-site-id'**: a office365 group id.
540+
- **'site:sharepoint-site-id'**: a sharepoint site id.
541+
- **'group:group-site-id'**: a office365 group id.
542+
543+
By setting the resource prefix (such as **'user:'** or **'group:'**) you help the library understand the type of resource. You can also pass it like 'users/example@exampl.com'. Same applies to the other resource prefixes.
542544

543545

544546
## Account Class and Modularity <a name="account"></a>

0 commit comments

Comments
 (0)