diff --git a/examples/outlook/events/create.py b/examples/outlook/events/create.py index a83cdf788..999e160de 100644 --- a/examples/outlook/events/create.py +++ b/examples/outlook/events/create.py @@ -1,16 +1,18 @@ """ Create an event in the current user's default calendar -https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http +https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0 """ from datetime import datetime, timedelta from office365.graph_client import GraphClient -from tests.graph_case import acquire_token_by_username_password +from tests import test_client_id, test_password, test_tenant, test_username when = datetime.utcnow() + timedelta(days=1) -client = GraphClient(acquire_token_by_username_password) +client = GraphClient.with_username_and_password( + test_tenant, test_client_id, test_username, test_password +) new_event = client.me.calendar.events.add( subject="Let's go for lunch", body="Does mid month work for you?", diff --git a/examples/sharepoint/folders/create_with_color.py b/examples/sharepoint/folders/create_with_color.py new file mode 100644 index 000000000..69d63dbd1 --- /dev/null +++ b/examples/sharepoint/folders/create_with_color.py @@ -0,0 +1,15 @@ +""" +Demonstrates how to create a folder with a color +""" +from office365.sharepoint.client_context import ClientContext +from office365.sharepoint.folders.coloring_information import FolderColors +from tests import test_team_site_url, test_user_credentials + +ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials) + + +root_folder = ctx.web.default_document_library().root_folder +folder = root_folder.folders.add( + "Report123", color_hex=FolderColors.DarkGreen +).execute_query() +print("Folder : {0} has been created".format(folder.serverRelativeUrl)) diff --git a/examples/sharepoint/listitems/system_update2.py b/examples/sharepoint/listitems/system_update2.py new file mode 100644 index 000000000..3001bafc3 --- /dev/null +++ b/examples/sharepoint/listitems/system_update2.py @@ -0,0 +1,14 @@ +import sys + +from office365.sharepoint.client_context import ClientContext +from tests import test_client_credentials, test_site_url + +ctx = ClientContext(test_site_url).with_credentials(test_client_credentials) + +target_list = ctx.web.lists.get_by_title("Documents") +items = target_list.items.get().top(1).execute_query() +if len(items) == 0: + sys.exit("No items were found") + +item = items[0] +item.system_update().execute_query() diff --git a/examples/sharepoint/lists/get_changes.py b/examples/sharepoint/lists/get_changes.py new file mode 100644 index 000000000..7ce274e61 --- /dev/null +++ b/examples/sharepoint/lists/get_changes.py @@ -0,0 +1,22 @@ +""" +Gets site changes +""" +from office365.sharepoint.changes.query import ChangeQuery +from office365.sharepoint.client_context import ClientContext +from tests import test_client_credentials, test_team_site_url + +client = ClientContext(test_team_site_url).with_credentials(test_client_credentials) +query = ChangeQuery( + item=True, + add=False, + update=False, + system_update=False, + delete_object=True, + role_assignment_add=False, + role_assignment_delete=False, +) + +list_title = "Documents" +result = client.web.lists.get_by_title(list_title).get_changes(query).execute_query() +for change in result: + print(change.properties) diff --git a/examples/sharepoint/sharing/create_anon_link.py b/examples/sharepoint/sharing/create_anon_link.py new file mode 100644 index 000000000..bbfa8f174 --- /dev/null +++ b/examples/sharepoint/sharing/create_anon_link.py @@ -0,0 +1,14 @@ +""" +Demonstrates creating an anonymous sharing link for a file +""" +from office365.sharepoint.client_context import ClientContext +from office365.sharepoint.sharing.links.kind import SharingLinkKind +from tests import test_team_site_url, test_user_credentials + +ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials) + +remote_file = ctx.web.get_file_by_server_relative_url( + "Shared Documents/Financial Sample.xlsx" +) +result = remote_file.share_link(SharingLinkKind.AnonymousView).execute_query() +print(result.value) diff --git a/office365/sharepoint/activities/facets/delete.py b/office365/sharepoint/activities/facets/delete.py index c3ca1b9c9..4795ffa5c 100644 --- a/office365/sharepoint/activities/facets/delete.py +++ b/office365/sharepoint/activities/facets/delete.py @@ -9,4 +9,4 @@ def __init__(self, name=None): @property def entity_type_name(self): - return "Microsoft.SharePoint.Activities.CreateFacet" + return "Microsoft.SharePoint.Activities.DeleteFacet" diff --git a/office365/sharepoint/activities/tracked_item_service.py b/office365/sharepoint/activities/tracked_item_service.py index 2d211b42f..a7fc5ee8f 100644 --- a/office365/sharepoint/activities/tracked_item_service.py +++ b/office365/sharepoint/activities/tracked_item_service.py @@ -3,15 +3,14 @@ from office365.sharepoint.activities.tracked_item_updates_request import ( TrackedItemUpdatesRequest, ) +from office365.sharepoint.client_context import ClientContext from office365.sharepoint.entity import Entity class TrackedItemService(Entity): @staticmethod def get_tracked_item_updates_for_user(context): - """ - :type context: office365.sharepoint.client_context.ClientContext - """ + # type: (ClientContext) -> ClientResult[str] return_type = ClientResult(context) payload = {"request": TrackedItemUpdatesRequest()} qry = ServiceOperationQuery( diff --git a/office365/sharepoint/folders/collection.py b/office365/sharepoint/folders/collection.py index 8c6e75695..508a04bd5 100644 --- a/office365/sharepoint/folders/collection.py +++ b/office365/sharepoint/folders/collection.py @@ -1,7 +1,10 @@ +import os + from office365.runtime.paths.service_operation import ServiceOperationPath from office365.runtime.paths.v3.entity import EntityPath from office365.runtime.queries.service_operation import ServiceOperationQuery from office365.sharepoint.entity_collection import EntityCollection +from office365.sharepoint.folders.coloring_information import FolderColoringInformation from office365.sharepoint.folders.folder import Folder from office365.sharepoint.types.resource_path import ResourcePath as SPResPath @@ -42,14 +45,28 @@ def ensure_path(self, path): folder = folder.add(name) return folder - def add(self, name): + def add(self, name, color_hex=None): """Adds the folder that is located at the specified URL to the collection. - :param str name: Specifies the Name of the folder. + :param str name: Specifies the Name or Path of the folder. + :param str color_hex: Specifies the color of the folder. """ return_type = Folder(self.context, EntityPath(name, self.resource_path)) - self.add_child(return_type) - qry = ServiceOperationQuery(self, "Add", [name], None, None, return_type) - self.context.add_query(qry) + if color_hex: + + def _add_coloring(): + path = os.path.join( + self.parent.properties.get("ServerRelativeUrl"), name + ) + coloring_info = FolderColoringInformation(color_hex=color_hex) + self.context.folder_coloring.create_folder( + path, coloring_info, return_type=return_type + ) + + self.parent.ensure_property("ServerRelativeUrl", _add_coloring) + else: + self.add_child(return_type) + qry = ServiceOperationQuery(self, "Add", [name], None, None, return_type) + self.context.add_query(qry) return return_type def get_by_url(self, url): diff --git a/office365/sharepoint/folders/coloring.py b/office365/sharepoint/folders/coloring.py index 8b5b5d937..842c943f3 100644 --- a/office365/sharepoint/folders/coloring.py +++ b/office365/sharepoint/folders/coloring.py @@ -4,6 +4,7 @@ from office365.sharepoint.entity import Entity from office365.sharepoint.folders.coloring_information import FolderColoringInformation from office365.sharepoint.folders.folder import Folder +from office365.sharepoint.types.resource_path import ResourcePath as SPResPath class FolderColoring(Entity): @@ -12,22 +13,19 @@ class FolderColoring(Entity): def create_folder( self, decoded_url, - ensure_unique_file_name=True, - overwrite=True, - coloring_information=None, + coloring_information=FolderColoringInformation(color_hex="1"), + return_type=None, ): """ :param str decoded_url: - :param bool ensure_unique_file_name: - :param bool overwrite: :param FolderColoringInformation coloring_information: + :param Folder return_type: Return type """ - return_type = Folder(self.context) + if return_type is None: + return_type = Folder(self.context) payload = { - "DecodedUrl": decoded_url, - "EnsureUniqueFileName": ensure_unique_file_name, - "Overwrite": overwrite, + "path": SPResPath(decoded_url), "coloringInformation": coloring_information, } qry = ServiceOperationQuery( diff --git a/office365/sharepoint/folders/coloring_information.py b/office365/sharepoint/folders/coloring_information.py index 23d016f79..d5900f051 100644 --- a/office365/sharepoint/folders/coloring_information.py +++ b/office365/sharepoint/folders/coloring_information.py @@ -1,6 +1,40 @@ from office365.runtime.client_value import ClientValue +class FolderColors(object): + Yellow = "#FFCE3C" + + Grey = "#B0B7BA" + + DarkRed = "#E73E29" + + LightRed = "#FFBCB2" + + DarkOrange = "#EE7110" + + LightOrange = "#FFBF84" + + DarkGreen = "#3F9F4A" + + LightGreen = "#8ED290" + + DarkTeal = "#27938E" + + LightTeal = "#7AD1CD" + + DarkBlue = "#1E84D0" + + LightBlue = "#86C8F7" + + DarkPurple = "#9A61C7" + + LightPurple = "#D4AFF6" + + DarkPink = "#CC53B4" + + LightPink = "#F7AAE7" + + class FolderColoringInformation(ClientValue): """""" @@ -13,3 +47,7 @@ def __init__(self, color_hex=None, color_tag=None, emoji=None): self.ColorHex = color_hex self.ColorTag = color_tag self.Emoji = emoji + + @property + def entity_type_name(self): + return "SP.FolderColoringInformation" diff --git a/office365/sharepoint/folders/folder.py b/office365/sharepoint/folders/folder.py index eae90fb58..29eb96684 100644 --- a/office365/sharepoint/folders/folder.py +++ b/office365/sharepoint/folders/folder.py @@ -485,7 +485,9 @@ def folders(self): return self.properties.get( "Folders", - FolderCollection(self.context, ResourcePath("Folders", self.resource_path)), + FolderCollection( + self.context, ResourcePath("Folders", self.resource_path), self + ), ) @property diff --git a/office365/sharepoint/lists/list.py b/office365/sharepoint/lists/list.py index a93babbdf..48721e070 100644 --- a/office365/sharepoint/lists/list.py +++ b/office365/sharepoint/lists/list.py @@ -838,6 +838,12 @@ def disable_grid_editing(self): # type: () -> Optional[bool] return self.properties.get("DisableGridEditing", None) + @property + def document_template_url(self): + # type: () -> Optional[str] + """Specifies the URL of the document template assigned to the list.""" + return self.properties.get("DocumentTemplateUrl", None) + @property def effective_base_permissions(self): """ diff --git a/office365/sharepoint/tenant/insights/report.py b/office365/sharepoint/tenant/insights/report.py new file mode 100644 index 000000000..05a4cd8a1 --- /dev/null +++ b/office365/sharepoint/tenant/insights/report.py @@ -0,0 +1,11 @@ +from office365.sharepoint.tenant.insights.report_metadata import ( + SPTenantIBInsightsReportMetadata, +) + + +class SPTenantIBInsightsReport(SPTenantIBInsightsReportMetadata): + """ """ + + @property + def entity_type_name(self): + return "Microsoft.SharePoint.Insights.SPTenantIBInsightsReport" diff --git a/office365/sharepoint/tenant/insights/report_manager.py b/office365/sharepoint/tenant/insights/report_manager.py new file mode 100644 index 000000000..8be2ad89c --- /dev/null +++ b/office365/sharepoint/tenant/insights/report_manager.py @@ -0,0 +1,5 @@ +from office365.sharepoint.entity import Entity + + +class SPTenantIBInsightsReportManager(Entity): + """ """ diff --git a/office365/sharepoint/tenant/insights/report_metadata.py b/office365/sharepoint/tenant/insights/report_metadata.py new file mode 100644 index 000000000..12c67ff78 --- /dev/null +++ b/office365/sharepoint/tenant/insights/report_metadata.py @@ -0,0 +1,5 @@ +from office365.sharepoint.entity import Entity + + +class SPTenantIBInsightsReportMetadata(Entity): + """ """