Skip to content

Commit 66a578e

Browse files
committed
SharePoint API (ListItem, GroupSiteManager) and examples improvements
1 parent 0efc1e0 commit 66a578e

File tree

11 files changed

+222
-23
lines changed

11 files changed

+222
-23
lines changed

examples/sharepoint/read_resource_no_model.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
from office365.sharepoint.request import SharePointRequest
88
from tests import test_site_url, test_user_credentials
99

10-
if __name__ == "__main__":
11-
request = SharePointRequest(test_site_url).with_credentials(test_user_credentials)
12-
response = request.execute_request("web")
10+
request = SharePointRequest(test_site_url).with_credentials(test_user_credentials)
11+
12+
try:
13+
response = request.execute_request("web/currentUser")
1314
json = json.loads(response.content)
14-
web_title = json["d"]["Title"]
15-
print("Web title: {0}".format(web_title))
15+
prop_val = json["d"]["UserPrincipalName"]
16+
print("UserPrincipalName: {0}".format(prop_val))
17+
except Exception as e:
18+
print("An error occurred: {0}".format(e))

generator/import_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def export_to_file(path, content):
2626
"--endpoint",
2727
dest="endpoint",
2828
help="Import metadata endpoint",
29-
default="sharepoint",
29+
default="graph",
3030
)
3131
parser.add_argument(
3232
"-p",
3333
"--path",
3434
dest="path",
35-
default="./metadata/SharePoint.xml",
35+
default="./metadata/MicrosoftGraph.xml",
3636
help="Import metadata endpoint",
3737
)
3838

generator/metadata/MicrosoftGraph.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34380,6 +34380,7 @@ within the time frame of their original request."/>
3438034380
<Property Name="teamId" Type="Edm.String"/>
3438134381
</ComplexType>
3438234382
<ComplexType Name="teamsAppAuthorization">
34383+
<Property Name="clientAppId" Type="Edm.String"/>
3438334384
<Property Name="requiredPermissionSet" Type="graph.teamsAppPermissionSet"/>
3438434385
</ComplexType>
3438534386
<ComplexType Name="teamsAppPermissionSet">
@@ -35841,6 +35842,9 @@ within the time frame of their original request."/>
3584135842
</Action>
3584235843
<Action Name="verify" IsBound="true" EntitySetPath="bindingParameter">
3584335844
<Parameter Name="bindingParameter" Type="graph.domain" Nullable="false"/>
35845+
<Parameter Name="forceTakeover" Type="Edm.Boolean">
35846+
<Annotation Term="Org.OData.Core.V1.OptionalParameter"/>
35847+
</Parameter>
3584435848
<ReturnType Type="graph.domain"/>
3584535849
</Action>
3584635850
<Action Name="getAvailableExtensionProperties" IsBound="true" EntitySetPath="bindingParameter">
@@ -41608,7 +41612,7 @@ within the time frame of their original request."/>
4160841612
<Property Name="macAddress" Type="Edm.String"/>
4160941613
<Property Name="manufacturer" Type="Edm.String"/>
4161041614
<Property Name="model" Type="Edm.String"/>
41611-
<Property Name="nics" Type="microsoft.graph.security.nicEvidence"/>
41615+
<Property Name="nics" Type="Collection(microsoft.graph.security.nicEvidence)"/>
4161241616
<Property Name="operatingSystem" Type="Edm.String"/>
4161341617
<Property Name="owners" Type="Collection(Edm.String)"/>
4161441618
<Property Name="protocols" Type="Collection(Edm.String)"/>

generator/metadata/SharePoint.xml

Lines changed: 140 additions & 13 deletions
Large diffs are not rendered by default.

office365/sharepoint/apps/management/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.sharepoint.entity import Entity
2+
3+
4+
class SPAppPrincipalInfo(Entity):
5+
""""""
6+
7+
@property
8+
def entity_type_name(self):
9+
return "Microsoft.SharePoint.AppManagement.SPAppPrincipalInfo"

office365/sharepoint/listitems/listitem.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from office365.sharepoint.likes.liked_by_information import LikedByInformation
1919
from office365.sharepoint.listitems.compliance_info import ListItemComplianceInfo
2020
from office365.sharepoint.listitems.form_update_value import ListItemFormUpdateValue
21+
from office365.sharepoint.listitems.update_parameters import ListItemUpdateParameters
2122
from office365.sharepoint.listitems.versions.collection import ListItemVersionCollection
2223
from office365.sharepoint.permissions.securable_object import SecurableObject
2324
from office365.sharepoint.policy.dlp_policy_tip import DlpPolicyTip
@@ -311,6 +312,21 @@ def update(self):
311312
super(ListItem, self).update()
312313
return self
313314

315+
def update_ex(self, bypass_quota_check=None, bypass_shared_lock=None):
316+
"""
317+
318+
:param bool bypass_quota_check:
319+
:param bool bypass_shared_lock:
320+
"""
321+
payload = {
322+
"parameters": ListItemUpdateParameters(
323+
bypass_quota_check, bypass_shared_lock
324+
)
325+
}
326+
qry = ServiceOperationQuery(self, "UpdateEx", None, payload)
327+
self.context.add_query(qry)
328+
return self
329+
314330
def system_update(self):
315331
"""Update the list item."""
316332

@@ -349,7 +365,6 @@ def _list_loaded():
349365
self.context.add_query(next_qry)
350366

351367
self.parent_list.ensure_properties(["BaseTemplate"], _list_loaded)
352-
# self.ensure_properties(sys_metadata, _system_update)
353368
return self
354369

355370
def update_overwrite_version(self):
@@ -368,6 +383,17 @@ def set_comments_disabled(self, value):
368383
self.context.add_query(qry)
369384
return self
370385

386+
def set_compliance_tag_with_hold(self, compliance_tag):
387+
"""
388+
Sets a compliance tag with a hold
389+
390+
:param str compliance_tag: The applying label (tag) to the list item
391+
"""
392+
payload = {"complianceTag": compliance_tag}
393+
qry = ServiceOperationQuery(self, "SetComplianceTagWithHold", None, payload)
394+
self.context.add_query(qry)
395+
return self
396+
371397
def get_comments(self):
372398
"""Retrieve ListItem comments"""
373399
return_type = CommentCollection(self.context)

office365/sharepoint/listitems/update_parameters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33

44
class ListItemUpdateParameters(ClientValue):
5-
pass
5+
6+
def __init__(self, bypass_quota_check=None, bypass_shared_lock=None):
7+
self.BypassQuotaCheck = bypass_quota_check
8+
self.BypassSharedLock = bypass_shared_lock

office365/sharepoint/portal/groups/site_manager.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from office365.runtime.http.request_options import RequestOptions
55
from office365.runtime.paths.resource_path import ResourcePath
66
from office365.runtime.queries.service_operation import ServiceOperationQuery
7+
from office365.sharepoint.portal.channels.info_collection import ChannelInfoCollection
78
from office365.sharepoint.portal.groups.creation_context import GroupCreationContext
89
from office365.sharepoint.portal.groups.creation_information import (
910
GroupCreationInformation,
@@ -88,6 +89,7 @@ def delete(self, site_url):
8889
return self
8990

9091
def ensure_team_for_group(self):
92+
""" """
9193
return_type = ClientResult(self.context)
9294
qry = ServiceOperationQuery(
9395
self, "EnsureTeamForGroup", None, None, None, return_type
@@ -96,6 +98,7 @@ def ensure_team_for_group(self):
9698
return return_type
9799

98100
def get_group_creation_context(self):
101+
""" """
99102
return_type = ClientResult(self.context, GroupCreationContext())
100103
qry = ServiceOperationQuery(
101104
self, "GetGroupCreationContext", None, None, None, return_type
@@ -178,6 +181,21 @@ def get_team_channels_direct(self, team_id):
178181
self.context.add_query(qry)
179182
return return_type
180183

184+
def get_team_channels_with_site_url(self, site_url):
185+
"""
186+
Returns a list of team channels associated with a Microsoft 365 Group.
187+
:param str site_url:
188+
"""
189+
return_type = ClientResult(self.context, ChannelInfoCollection())
190+
payload = {
191+
"siteUrl": site_url,
192+
}
193+
qry = ServiceOperationQuery(
194+
self, "GetTeamChannelsWithSiteUrl", None, payload, None, return_type
195+
)
196+
self.context.add_query(qry)
197+
return return_type
198+
181199
def notebook(self, group_id):
182200
"""
183201
:param str group_id:

office365/sharepoint/request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class SharePointRequest(ODataRequest):
1515
def __init__(self, base_url):
16+
"""
17+
:param str base_url: Absolute Web or Site Url
18+
"""
1619
super().__init__(JsonLightFormat())
1720
self._auth_context = AuthenticationContext(url=base_url)
1821
self.beforeExecute += self._authenticate_request

tests/sharepoint/test_team_site.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ def test9_get_current_user_shared_channel_member_groups(self):
6666
self.client.group_site_manager.get_current_user_shared_channel_member_groups().execute_query()
6767
)
6868
self.assertIsNotNone(result.value)
69+
70+
def test_10_recent_and_joined_teams(self):
71+
result = (
72+
self.client.group_site_manager.recent_and_joined_teams().execute_query()
73+
)
74+
self.assertIsNotNone(result.value)

0 commit comments

Comments
 (0)