I need to know if a `principalId` from the ACL is for a user or a team so I can load the correct data. How can I know which method to call based on the results from the ACL, or is there a different way to get all the permissions for an entity that will give me this information?
Example:
```
entity = syn.get('syn123')
acl = syn._getACL(entity)
# {
# "id": "syn123",
# "creationDate": "2018-09-10T19:34:41.655Z",
# "etag": "92b28c92-6753-4ba6-b25c-4bfe3f14d2a3",
# "resourceAccess": [
# {
# "principalId": 3392139,
# "accessType": [
# "READ",
# "DOWNLOAD"
# ]
# },
# {
# "principalId": 3392133,
# "accessType": [
# "READ",
# "DOWNLOAD"
# ]
# }
# ]
# }
for resource in acl['resourceAccess']:
principal_id = resource['principalId']
if is_user:
return syn.getUserProfile(principal_id)
elif is_team:
return syn.getTeam(principal_id)
```
Created by pstoutdev > there is no overlap in the ids of teams and users
Thanks @larssono, that's what I needed! My real code tries (with exception handling) users first then teams but I didn't know if the the IDs overlapped. Can you use an exception instead (there is not overlap in the ids of teams and users).
```
for resource in acl['resourceAccess']:
principal_id = resource['principalId']
try:
return syn.getUserProfile(principal_id)
except synapseclient.exceptions.SynapseHTTPError:
return syn.getTeam(principal_id)
````
You can be more precise in the exception and verify that you are getting a 404.
Drop files to upload
How to determine if principalId is for a user or a team in ACL? page is loading…