Office365-REST-Python-Client
Office365-REST-Python-Client copied to clipboard
Sharepoint get user's files and folder that he has access to
i need to get a list of files and folder that the user's has access to in a certain path in a sharepoint site using sharepoint rest api.
Looking for the same
@maryam-hesham96 @timepasser69 You could get the file and then check if user has permission to it as below
userEmail = "your Azure AD user email"
userLoginName = ctx.web.site_users.get_by_email(userEmail)
target_file = ctx.web.get_file_by_server_relative_path(file_url)
try:
result = target_file.listItemAllFields.get_user_effective_permissions(userLoginName).execute_query_retry()
# verify whether user has Reader role to a file
if result.value.has(PermissionKind.OpenItems):
print("User has access to read the file")
else:
print("User does not have access to read the file")
except ClientRequestException as e:
print("error : User, file, error ",userLoginName,file_url, e.message)