-
-
Notifications
You must be signed in to change notification settings - Fork 318
/
check.py
22 lines (20 loc) · 844 Bytes
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
Demonstrates how to determine whether user has the permissions for a list
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.permissions.kind import PermissionKind
from tests import (
test_team_site_url,
test_user_credentials,
test_user_principal_name_alt,
)
client = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
file_url = "Shared Documents/Financial Sample.xlsx"
target_user = client.web.site_users.get_by_email(test_user_principal_name_alt)
target_file = client.web.get_file_by_server_relative_path(file_url)
result = target_file.listItemAllFields.get_user_effective_permissions(
target_user
).execute_query()
# verify whether user has Reader role to a file
if result.value.has(PermissionKind.OpenItems):
print("User has access to read a file")