Skip to content

Commit

Permalink
SharePoint API (ListItem, GroupSiteManager) and examples improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Oct 20, 2024
1 parent 0efc1e0 commit 66a578e
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 23 deletions.
13 changes: 8 additions & 5 deletions examples/sharepoint/read_resource_no_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
6 changes: 5 additions & 1 deletion generator/metadata/MicrosoftGraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34380,6 +34380,7 @@ within the time frame of their original request."/>
<Property Name="teamId" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="teamsAppAuthorization">
<Property Name="clientAppId" Type="Edm.String"/>
<Property Name="requiredPermissionSet" Type="graph.teamsAppPermissionSet"/>
</ComplexType>
<ComplexType Name="teamsAppPermissionSet">
Expand Down Expand Up @@ -35841,6 +35842,9 @@ within the time frame of their original request."/>
</Action>
<Action Name="verify" IsBound="true" EntitySetPath="bindingParameter">
<Parameter Name="bindingParameter" Type="graph.domain" Nullable="false"/>
<Parameter Name="forceTakeover" Type="Edm.Boolean">
<Annotation Term="Org.OData.Core.V1.OptionalParameter"/>
</Parameter>
<ReturnType Type="graph.domain"/>
</Action>
<Action Name="getAvailableExtensionProperties" IsBound="true" EntitySetPath="bindingParameter">
Expand Down Expand Up @@ -41608,7 +41612,7 @@ within the time frame of their original request."/>
<Property Name="macAddress" Type="Edm.String"/>
<Property Name="manufacturer" Type="Edm.String"/>
<Property Name="model" Type="Edm.String"/>
<Property Name="nics" Type="microsoft.graph.security.nicEvidence"/>
<Property Name="nics" Type="Collection(microsoft.graph.security.nicEvidence)"/>
<Property Name="operatingSystem" Type="Edm.String"/>
<Property Name="owners" Type="Collection(Edm.String)"/>
<Property Name="protocols" Type="Collection(Edm.String)"/>
Expand Down
153 changes: 140 additions & 13 deletions generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

Empty file.
9 changes: 9 additions & 0 deletions office365/sharepoint/apps/management/principal_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.sharepoint.entity import Entity


class SPAppPrincipalInfo(Entity):
""""""

@property
def entity_type_name(self):
return "Microsoft.SharePoint.AppManagement.SPAppPrincipalInfo"
28 changes: 27 additions & 1 deletion office365/sharepoint/listitems/listitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion office365/sharepoint/listitems/update_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions office365/sharepoint/portal/groups/site_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions office365/sharepoint/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/sharepoint/test_team_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 66a578e

Please sign in to comment.