Skip to content

Commit

Permalink
SharePoint new types and model updates, List export method introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Sep 19, 2024
1 parent 79a8f28 commit b880908
Show file tree
Hide file tree
Showing 38 changed files with 626 additions and 23 deletions.
19 changes: 19 additions & 0 deletions examples/onedrive/drives/get_for_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Demonstrates how to get a drive for a user.
"""

from office365.graph_client import GraphClient
from tests import (
test_client_id,
test_client_secret,
test_tenant,
test_user_principal_name,
)

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
site = (
client.users.get_by_principal_name(test_user_principal_name)
.get_my_site()
.execute_query()
)
print("Drive url: {0}".format(site.web_url))
25 changes: 25 additions & 0 deletions examples/sharepoint/lists/export_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import tempfile

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
from office365.sharepoint.listitems.listitem import ListItem
from tests import test_client_credentials, test_team_site_url


def print_progress(item):
# type: (ListItem|File) -> None
if isinstance(item, ListItem):
print("List Item has been exported...")
else:
print("File has been downloaded...")


ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)

list_title = "Orders"
lib = ctx.web.lists.get_by_title(list_title)
export_path = os.path.join(tempfile.mkdtemp(), "{0}.zip".format(list_title))
with open(export_path, "wb") as f:
lib.export(f, True, print_progress).execute_query()
print("List has been export into {0} ...".format(export_path))
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="graph",
default="sharepoint",
)
parser.add_argument(
"-p",
"--path",
dest="path",
default="./metadata/MicrosoftGraph.xml",
default="./metadata/SharePoint.xml",
help="Import metadata endpoint",
)

Expand Down
3 changes: 3 additions & 0 deletions generator/metadata/MicrosoftGraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25913,6 +25913,9 @@
<EntityType Name="administrativeUnit" BaseType="graph.directoryObject" OpenType="true">
<Property Name="description" Type="Edm.String"/>
<Property Name="displayName" Type="Edm.String"/>
<Property Name="membershipRule" Type="Edm.String"/>
<Property Name="membershipRuleProcessingState" Type="Edm.String"/>
<Property Name="membershipType" Type="Edm.String"/>
<Property Name="visibility" Type="Edm.String"/>
<NavigationProperty Name="members" Type="Collection(graph.directoryObject)"/>
<NavigationProperty Name="scopedRoleMembers" Type="Collection(graph.scopedRoleMembership)" ContainsTarget="true"/>
Expand Down
138 changes: 129 additions & 9 deletions generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions office365/directory/users/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ def get_mail_tips(self, email_addresses, mail_tips_options=None):
self.context.add_query(qry)
return return_type

def get_my_site(self):
"""Gets user's site"""
return_type = Site(self.context)

def _loaded():
return_type.set_property("webUrl", self.my_site)

self.ensure_property("mySite", _loaded)
return return_type

def send_mail(
self,
subject,
Expand Down Expand Up @@ -535,11 +545,21 @@ def chats(self):
@property
def given_name(self):
# type: () -> Optional[str]
"""
The given name (first name) of the user. Maximum length is 64 characters.
"""
"""The given name (first name) of the user. Maximum length is 64 characters"""
return self.properties.get("givenName", None)

@property
def my_site(self):
# type: () -> Optional[str]
"""The URL for the user's site."""
return self.properties.get("mySite", None)

@property
def office_location(self):
# type: () -> Optional[str]
"""The office location in the user's place of business."""
return self.properties.get("officeLocation", None)

@property
def user_principal_name(self):
# type: () -> Optional[str]
Expand Down
41 changes: 41 additions & 0 deletions office365/sharepoint/apps/context_site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from office365.onedrive.sites.site import Site
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.paths.service_operation import ServiceOperationPath
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.entity import Entity
from office365.sharepoint.webs.web import Web


class AppContextSite(Entity):
""" """

def __init__(self, context, site_url):
# type: (ClientContext, str) -> None
""""""
static_path = ServiceOperationPath(
"SP.AppContextSite",
{"siteUrl": site_url},
)
super(AppContextSite, self).__init__(context, static_path)

@property
def site(self):
""""""
return self.properties.get(
"Site",
Site(
self.context,
ResourcePath("Site", self.resource_path),
),
)

@property
def web(self):
""""""
return self.properties.get(
"Web",
Web(
self.context,
ResourcePath("Web", self.resource_path),
),
)
4 changes: 1 addition & 3 deletions office365/sharepoint/changes/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def change_type_name(self):

@property
def change_token(self):
"""
Returns an ChangeToken that represents the change.
"""
"""Returns an ChangeToken that represents the change."""
return self.properties.get("ChangeToken", ChangeToken())

@property
Expand Down
3 changes: 3 additions & 0 deletions office365/sharepoint/changes/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _resolve_change_type(self, properties):
from office365.sharepoint.changes.item import ChangeItem
from office365.sharepoint.changes.list import ChangeList
from office365.sharepoint.changes.user import ChangeUser
from office365.sharepoint.changes.view import ChangeView
from office365.sharepoint.changes.web import ChangeWeb

if "ItemId" in properties and "ListId" in properties:
Expand All @@ -40,3 +41,5 @@ def _resolve_change_type(self, properties):
self._item_type = ChangeAlert
elif "FieldId" in properties:
self._item_type = ChangeField
elif "ViewId" in properties:
self._item_type = ChangeView
6 changes: 6 additions & 0 deletions office365/sharepoint/changes/folder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.sharepoint.changes.change import Change


Expand All @@ -6,8 +8,12 @@ class ChangeFolder(Change):

@property
def unique_id(self):
# type: () -> Optional[str]
"""Identifies the folder that has changed."""
return self.properties.get("UniqueId", None)

@property
def web_id(self):
# type: () -> Optional[str]
"""Identifies the site that contains the changed folder."""
return self.properties.get("WebId", None)
3 changes: 3 additions & 0 deletions office365/sharepoint/changes/group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.sharepoint.changes.change import Change


Expand All @@ -6,5 +8,6 @@ class ChangeGroup(Change):

@property
def group_id(self):
# type: () -> Optional[int]
"""Identifies the changed group."""
return self.properties.get("GroupId", None)
13 changes: 13 additions & 0 deletions office365/sharepoint/changes/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ def __repr__(self):

@property
def base_template(self):
# type: () -> Optional[int]
"""An SP.ListTemplateType object that returns the list template type of the list."""
return self.properties.get("BaseTemplate", None)

@property
def editor(self):
# type: () -> Optional[str]
"""A string that returns the name of the user who modified the list."""
return self.properties.get("Editor", None)

@property
def hidden(self):
# type: () -> Optional[bool]
"""Returns a Boolean value that indicates whether a list is a hidden list."""
return self.properties.get("Hidden", None)

@property
def list_id(self):
# type: () -> Optional[str]
Expand Down
25 changes: 25 additions & 0 deletions office365/sharepoint/changes/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Optional

from office365.sharepoint.changes.change import Change


class ChangeView(Change):
"""Specifies a change on a view."""

@property
def view_id(self):
# type: () -> Optional[str]
"""Identifies the changed view."""
return self.properties.get("ViewId", None)

@property
def list_id(self):
# type: () -> Optional[str]
"""Identifies the list that contains the changed view."""
return self.properties.get("ListId", None)

@property
def web_id(self):
# type: () -> Optional[str]
"""Identifies the site that contains the changed view."""
return self.properties.get("WebId", None)
10 changes: 10 additions & 0 deletions office365/sharepoint/client_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,16 @@ def workflow_services_manager(self):

return WorkflowServicesManager.current(self)

@property
def workflow_deployment_service(self):
"""Alias to WorkflowServicesManager"""

from office365.sharepoint.workflowservices.deployment_service import (
WorkflowDeploymentService,
)

return WorkflowDeploymentService(self)

@property
def work_items(self):
""""""
Expand Down
5 changes: 5 additions & 0 deletions office365/sharepoint/directory/provider/alternate_id_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
class AlternateIdData(ClientValue):
""""""

def __init__(self, email=None, identifying_property=None, user_principal_name=None):
self.Email = email
self.IdentifyingProperty = identifying_property
self.UserPrincipalName = user_principal_name

@property
def entity_type_name(self):
return "SP.Directory.Provider.AlternateIdData"
8 changes: 8 additions & 0 deletions office365/sharepoint/directory/provider/notification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity


Expand All @@ -10,6 +11,13 @@ def __init__(self, context, resource_path=None):
resource_path = ResourcePath("SP.Directory.Provider.DirectoryNotification")
super(DirectoryNotification, self).__init__(context, resource_path)

def notify_changes(self, directory_object_changes):
""" """
payload = {"directoryObjectChanges": directory_object_changes}
qry = ServiceOperationQuery(self, "NotifyChanges", None, payload, None, None)
self.context.add_query(qry)
return self

@property
def entity_type_name(self):
return "SP.Directory.Provider.DirectoryNotification"
5 changes: 5 additions & 0 deletions office365/sharepoint/directory/provider/object_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.runtime.client_value import ClientValue


class DirectoryObjectChanges(ClientValue):
""" """
29 changes: 26 additions & 3 deletions office365/sharepoint/directory/provider/object_data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
from office365.runtime.client_value import ClientValue
from office365.sharepoint.directory.provider.alternate_id_data import AlternateIdData
from office365.sharepoint.directory.provider.session_data import DirectorySessionData


class DirectoryObjectData(ClientValue):
""""""

def __init__(self, AlternateId=AlternateIdData(), Id=None):
self.AlternateId = AlternateId
self.Id = Id
def __init__(
self,
alternate_id=AlternateIdData(),
attribute_expiration_times=None,
change_marker=None,
directory_object_sub_type=None,
directory_object_type=None,
directory_session_data=DirectorySessionData(),
id_=None,
is_new=None,
last_modified_time=None,
tenant_context_id=None,
version=None,
):
self.AlternateId = alternate_id
self.AttributeExpirationTimes = attribute_expiration_times
self.ChangeMarker = change_marker
self.DirectoryObjectSubType = directory_object_sub_type
self.DirectoryObjectType = directory_object_type
self.DirectorySessionData = directory_session_data
self.Id = id_
self.IsNew = is_new
self.LastModifiedTime = last_modified_time
self.TenantContextId = tenant_context_id
self.Version = version

@property
def entity_type_name(self):
Expand Down
1 change: 1 addition & 0 deletions office365/sharepoint/directory/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, context, resource_path=None):
super(SharePointDirectoryProvider, self).__init__(context, resource_path)

def read_directory_object(self, data):
# type: (DirectoryObjectData) -> ClientResult[DirectoryObjectData]
""""""
return_type = ClientResult(self.context, DirectoryObjectData())
payload = {"data": data}
Expand Down
9 changes: 9 additions & 0 deletions office365/sharepoint/directory/provider/session_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.runtime.client_value import ClientValue


class DirectorySessionData(ClientValue):

@property
def entity_type_name(self):
# type: () -> str
return "SP.Directory.Provider.DirectorySessionData"
Loading

0 comments on commit b880908

Please sign in to comment.