Skip to content

Commit

Permalink
Sharing namespace improvements in SharePoint API, Intune new types
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Aug 3, 2023
1 parent 5fbd62f commit 6be54d6
Show file tree
Hide file tree
Showing 24 changed files with 640 additions and 69 deletions.
3 changes: 2 additions & 1 deletion examples/onedrive/files/create_sharing_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=http
"""

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password


client = GraphClient(acquire_token_by_username_password)
file_path = "archive/Sample.rtf"
file_path = "Financial Sample.xlsx"
drive_item = client.me.drive.root.get_by_path(file_path)
permission = drive_item.create_link("view", "anonymous", password="ThisIsMyPrivatePassword").execute_query()
print(permission.link)
10 changes: 9 additions & 1 deletion examples/sharepoint/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@

def upload_sample(context, path):
"""
:type context: office365.sharepoint.client_context.ClientContext
:type path: str
"""
folder = context.web.default_document_library().root_folder
with open(path, 'rb') as f:
file = folder.files.upload(f).execute_query()
return file
18 changes: 9 additions & 9 deletions examples/sharepoint/sharing/share_file.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import json

from examples.sharepoint import upload_sample
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.sharing.links.kind import SharingLinkKind
from office365.sharepoint.webs.web import Web
from tests import test_user_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)

sharing_messages = {
0: "A value has not been initialized",
1: "A direct link or canonical URL to an object",
Expand All @@ -17,21 +16,22 @@
6: "A tokenized sharing link where properties can change without affecting link URL"
}

file_url = "/sites/team/Shared Documents/SharePoint User Guide.docx"
target_file = ctx.web.get_file_by_server_relative_url(file_url)
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)

remote_file = upload_sample(ctx, "../../data/SharePoint User Guide.docx")

# Share a file link
result = target_file.share_link(SharingLinkKind.AnonymousView).execute_query()
print("Creating a sharing link for a file...")
result = remote_file.share_link(SharingLinkKind.AnonymousView).execute_query()
print(json.dumps(result.value.to_json(), indent=4))
link_url = result.value.sharingLinkInfo.Url

# Verify a link
result = Web.get_sharing_link_kind(ctx, link_url).execute_query()
print(sharing_messages.get(result.value, "Unknown sharing link"))

# Unshare a file link
target_file.unshare_link(SharingLinkKind.AnonymousView).execute_query()
print("Unsharing a file link...")
remote_file.unshare_link(SharingLinkKind.AnonymousView).execute_query()

# Get a file sharing info
info = target_file.get_sharing_information().execute_query()
info = remote_file.get_sharing_information().execute_query()
print("AnonymousViewLink:", info.properties.get('AnonymousViewLink'))
6 changes: 3 additions & 3 deletions examples/sharepoint/sharing/share_file_org.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json

from examples.sharepoint import upload_sample
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.sharing.links.kind import SharingLinkKind
from tests import test_user_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
file_url = "/sites/team/Shared Documents/SharePoint User Guide.docx"
target_file = ctx.web.get_file_by_server_relative_url(file_url)
result = target_file.share_link(SharingLinkKind.OrganizationView).execute_query()
remote_file = upload_sample(ctx, "../../data/Financial Sample.xlsx")
result = remote_file.share_link(SharingLinkKind.OrganizationView).execute_query()
print(json.dumps(result.value.to_json(), indent=4))
16 changes: 16 additions & 0 deletions examples/sharepoint/sharing/share_file_with_password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
"""
import json

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.sharing.links.kind import SharingLinkKind
from office365.sharepoint.sharing.role_type import RoleType
from tests import test_user_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
file_url = "Shared Documents/SharePoint User Guide.docx"
target_file = ctx.web.get_file_by_server_relative_url(file_url)
result = target_file.share_link(SharingLinkKind.Flexible, role=RoleType.Editor, password="password").execute_query()
print(json.dumps(result.value.to_json(), indent=4))
# print("Shared link url: {0}".format(result.value.sharingLinkInfo))
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def export_to_file(path, content):

parser = ArgumentParser()
parser.add_argument("-e", "--endpoint", dest="endpoint",
help="Import metadata endpoint", default="microsoftgraph")
help="Import metadata endpoint", default="sharepoint")
parser.add_argument("-p", "--path",
dest="path", default="./metadata/MicrosoftGraph.xml",
dest="path", default="./metadata/SharePoint.xml",
help="Import metadata endpoint")

args = parser.parse_args()
Expand Down
Loading

0 comments on commit 6be54d6

Please sign in to comment.