From 66a578efb0ff7883cee8e9ea1cfcd844f67909e2 Mon Sep 17 00:00:00 2001 From: vgrem Date: Sun, 20 Oct 2024 14:56:14 +0300 Subject: [PATCH] SharePoint API (ListItem, GroupSiteManager) and examples improvements --- examples/sharepoint/read_resource_no_model.py | 13 +- generator/import_metadata.py | 4 +- generator/metadata/MicrosoftGraph.xml | 6 +- generator/metadata/SharePoint.xml | 153 ++++++++++++++++-- .../sharepoint/apps/management/__init__.py | 0 .../apps/management/principal_info.py | 9 ++ office365/sharepoint/listitems/listitem.py | 28 +++- .../sharepoint/listitems/update_parameters.py | 5 +- .../sharepoint/portal/groups/site_manager.py | 18 +++ office365/sharepoint/request.py | 3 + tests/sharepoint/test_team_site.py | 6 + 11 files changed, 222 insertions(+), 23 deletions(-) create mode 100644 office365/sharepoint/apps/management/__init__.py create mode 100644 office365/sharepoint/apps/management/principal_info.py diff --git a/examples/sharepoint/read_resource_no_model.py b/examples/sharepoint/read_resource_no_model.py index 8c458b898..3fb8eb8a3 100644 --- a/examples/sharepoint/read_resource_no_model.py +++ b/examples/sharepoint/read_resource_no_model.py @@ -7,9 +7,12 @@ from office365.sharepoint.request import SharePointRequest from tests import test_site_url, test_user_credentials -if __name__ == "__main__": - request = SharePointRequest(test_site_url).with_credentials(test_user_credentials) - response = request.execute_request("web") +request = SharePointRequest(test_site_url).with_credentials(test_user_credentials) + +try: + response = request.execute_request("web/currentUser") json = json.loads(response.content) - web_title = json["d"]["Title"] - print("Web title: {0}".format(web_title)) + prop_val = json["d"]["UserPrincipalName"] + print("UserPrincipalName: {0}".format(prop_val)) +except Exception as e: + print("An error occurred: {0}".format(e)) diff --git a/generator/import_metadata.py b/generator/import_metadata.py index 324762b51..310481611 100644 --- a/generator/import_metadata.py +++ b/generator/import_metadata.py @@ -26,13 +26,13 @@ def export_to_file(path, content): "--endpoint", dest="endpoint", help="Import metadata endpoint", - default="sharepoint", + default="graph", ) parser.add_argument( "-p", "--path", dest="path", - default="./metadata/SharePoint.xml", + default="./metadata/MicrosoftGraph.xml", help="Import metadata endpoint", ) diff --git a/generator/metadata/MicrosoftGraph.xml b/generator/metadata/MicrosoftGraph.xml index d7365ef90..13008358f 100644 --- a/generator/metadata/MicrosoftGraph.xml +++ b/generator/metadata/MicrosoftGraph.xml @@ -34380,6 +34380,7 @@ within the time frame of their original request."/> + @@ -35841,6 +35842,9 @@ within the time frame of their original request."/> + + + @@ -41608,7 +41612,7 @@ within the time frame of their original request."/> - + diff --git a/generator/metadata/SharePoint.xml b/generator/metadata/SharePoint.xml index f0ba8a3e7..40b13da7d 100644 --- a/generator/metadata/SharePoint.xml +++ b/generator/metadata/SharePoint.xml @@ -1080,6 +1080,7 @@ + @@ -2254,6 +2255,7 @@ + @@ -3217,6 +3219,12 @@ + + + + + + @@ -4833,6 +4841,8 @@ + + @@ -5094,6 +5104,7 @@ + @@ -8848,6 +8859,13 @@ + + + + + + + @@ -8891,6 +8909,9 @@ + + + @@ -9723,6 +9744,9 @@ + + + @@ -10546,21 +10570,17 @@ - + - + - - - - - + @@ -10573,12 +10593,6 @@ - - - - - - @@ -10604,6 +10618,7 @@ + @@ -10614,6 +10629,7 @@ + @@ -11865,6 +11881,10 @@ + + + + @@ -11886,6 +11906,9 @@ + + + @@ -13978,6 +14001,9 @@ + + + @@ -16817,6 +16843,7 @@ + @@ -16825,6 +16852,11 @@ + + + + + @@ -18055,6 +18087,7 @@ + @@ -18071,9 +18104,11 @@ + + @@ -18197,6 +18232,7 @@ + @@ -18231,6 +18267,7 @@ + @@ -18709,6 +18746,10 @@ + + + + @@ -21143,6 +21184,15 @@ + + + + + + + + + @@ -23558,6 +23608,9 @@ + + + @@ -26040,6 +26093,9 @@ + + + @@ -26070,6 +26126,9 @@ + + + @@ -26643,6 +26702,9 @@ + + + @@ -27450,6 +27512,9 @@ + + + @@ -28038,6 +28103,9 @@ + + + @@ -28611,12 +28679,18 @@ + + + + + + @@ -29561,6 +29635,7 @@ + @@ -33076,6 +33151,7 @@ + @@ -34153,6 +34229,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -38945,6 +39048,8 @@ + + @@ -39517,6 +39622,7 @@ + @@ -39655,6 +39761,10 @@ + + + + @@ -40912,6 +41022,23 @@ + + + + + + + + + + + + + + + + + diff --git a/office365/sharepoint/apps/management/__init__.py b/office365/sharepoint/apps/management/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/office365/sharepoint/apps/management/principal_info.py b/office365/sharepoint/apps/management/principal_info.py new file mode 100644 index 000000000..29f8200b8 --- /dev/null +++ b/office365/sharepoint/apps/management/principal_info.py @@ -0,0 +1,9 @@ +from office365.sharepoint.entity import Entity + + +class SPAppPrincipalInfo(Entity): + """""" + + @property + def entity_type_name(self): + return "Microsoft.SharePoint.AppManagement.SPAppPrincipalInfo" diff --git a/office365/sharepoint/listitems/listitem.py b/office365/sharepoint/listitems/listitem.py index 7943f5ea5..67a6b1887 100644 --- a/office365/sharepoint/listitems/listitem.py +++ b/office365/sharepoint/listitems/listitem.py @@ -18,6 +18,7 @@ from office365.sharepoint.likes.liked_by_information import LikedByInformation from office365.sharepoint.listitems.compliance_info import ListItemComplianceInfo from office365.sharepoint.listitems.form_update_value import ListItemFormUpdateValue +from office365.sharepoint.listitems.update_parameters import ListItemUpdateParameters from office365.sharepoint.listitems.versions.collection import ListItemVersionCollection from office365.sharepoint.permissions.securable_object import SecurableObject from office365.sharepoint.policy.dlp_policy_tip import DlpPolicyTip @@ -311,6 +312,21 @@ def update(self): super(ListItem, self).update() return self + def update_ex(self, bypass_quota_check=None, bypass_shared_lock=None): + """ + + :param bool bypass_quota_check: + :param bool bypass_shared_lock: + """ + payload = { + "parameters": ListItemUpdateParameters( + bypass_quota_check, bypass_shared_lock + ) + } + qry = ServiceOperationQuery(self, "UpdateEx", None, payload) + self.context.add_query(qry) + return self + def system_update(self): """Update the list item.""" @@ -349,7 +365,6 @@ def _list_loaded(): self.context.add_query(next_qry) self.parent_list.ensure_properties(["BaseTemplate"], _list_loaded) - # self.ensure_properties(sys_metadata, _system_update) return self def update_overwrite_version(self): @@ -368,6 +383,17 @@ def set_comments_disabled(self, value): self.context.add_query(qry) return self + def set_compliance_tag_with_hold(self, compliance_tag): + """ + Sets a compliance tag with a hold + + :param str compliance_tag: The applying label (tag) to the list item + """ + payload = {"complianceTag": compliance_tag} + qry = ServiceOperationQuery(self, "SetComplianceTagWithHold", None, payload) + self.context.add_query(qry) + return self + def get_comments(self): """Retrieve ListItem comments""" return_type = CommentCollection(self.context) diff --git a/office365/sharepoint/listitems/update_parameters.py b/office365/sharepoint/listitems/update_parameters.py index 8bc36639a..39b293aff 100644 --- a/office365/sharepoint/listitems/update_parameters.py +++ b/office365/sharepoint/listitems/update_parameters.py @@ -2,4 +2,7 @@ class ListItemUpdateParameters(ClientValue): - pass + + def __init__(self, bypass_quota_check=None, bypass_shared_lock=None): + self.BypassQuotaCheck = bypass_quota_check + self.BypassSharedLock = bypass_shared_lock diff --git a/office365/sharepoint/portal/groups/site_manager.py b/office365/sharepoint/portal/groups/site_manager.py index f9c10e048..6224c1f2b 100644 --- a/office365/sharepoint/portal/groups/site_manager.py +++ b/office365/sharepoint/portal/groups/site_manager.py @@ -4,6 +4,7 @@ from office365.runtime.http.request_options import RequestOptions from office365.runtime.paths.resource_path import ResourcePath from office365.runtime.queries.service_operation import ServiceOperationQuery +from office365.sharepoint.portal.channels.info_collection import ChannelInfoCollection from office365.sharepoint.portal.groups.creation_context import GroupCreationContext from office365.sharepoint.portal.groups.creation_information import ( GroupCreationInformation, @@ -88,6 +89,7 @@ def delete(self, site_url): return self def ensure_team_for_group(self): + """ """ return_type = ClientResult(self.context) qry = ServiceOperationQuery( self, "EnsureTeamForGroup", None, None, None, return_type @@ -96,6 +98,7 @@ def ensure_team_for_group(self): return return_type def get_group_creation_context(self): + """ """ return_type = ClientResult(self.context, GroupCreationContext()) qry = ServiceOperationQuery( self, "GetGroupCreationContext", None, None, None, return_type @@ -178,6 +181,21 @@ def get_team_channels_direct(self, team_id): self.context.add_query(qry) return return_type + def get_team_channels_with_site_url(self, site_url): + """ + Returns a list of team channels associated with a Microsoft 365 Group. + :param str site_url: + """ + return_type = ClientResult(self.context, ChannelInfoCollection()) + payload = { + "siteUrl": site_url, + } + qry = ServiceOperationQuery( + self, "GetTeamChannelsWithSiteUrl", None, payload, None, return_type + ) + self.context.add_query(qry) + return return_type + def notebook(self, group_id): """ :param str group_id: diff --git a/office365/sharepoint/request.py b/office365/sharepoint/request.py index e1e16660f..e925c58e9 100644 --- a/office365/sharepoint/request.py +++ b/office365/sharepoint/request.py @@ -13,6 +13,9 @@ class SharePointRequest(ODataRequest): def __init__(self, base_url): + """ + :param str base_url: Absolute Web or Site Url + """ super().__init__(JsonLightFormat()) self._auth_context = AuthenticationContext(url=base_url) self.beforeExecute += self._authenticate_request diff --git a/tests/sharepoint/test_team_site.py b/tests/sharepoint/test_team_site.py index 3d6811f13..5034cef7c 100644 --- a/tests/sharepoint/test_team_site.py +++ b/tests/sharepoint/test_team_site.py @@ -66,3 +66,9 @@ def test9_get_current_user_shared_channel_member_groups(self): self.client.group_site_manager.get_current_user_shared_channel_member_groups().execute_query() ) self.assertIsNotNone(result.value) + + def test_10_recent_and_joined_teams(self): + result = ( + self.client.group_site_manager.recent_and_joined_teams().execute_query() + ) + self.assertIsNotNone(result.value)