Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

Sharepoint get user's files and folder that he has access to

Open maryam-hesham96 opened this issue 3 years ago • 2 comments

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.

maryam-hesham96 avatar Oct 26 '22 08:10 maryam-hesham96

Looking for the same

timepasser69 avatar Oct 30 '22 07:10 timepasser69

@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)

ssmails avatar Feb 15 '24 20:02 ssmails