Skip to content

Commit b880908

Browse files
committed
SharePoint new types and model updates, List export method introduced
1 parent 79a8f28 commit b880908

38 files changed

+626
-23
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Demonstrates how to get a drive for a user.
3+
"""
4+
5+
from office365.graph_client import GraphClient
6+
from tests import (
7+
test_client_id,
8+
test_client_secret,
9+
test_tenant,
10+
test_user_principal_name,
11+
)
12+
13+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
14+
site = (
15+
client.users.get_by_principal_name(test_user_principal_name)
16+
.get_my_site()
17+
.execute_query()
18+
)
19+
print("Drive url: {0}".format(site.web_url))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import tempfile
3+
4+
from office365.sharepoint.client_context import ClientContext
5+
from office365.sharepoint.files.file import File
6+
from office365.sharepoint.listitems.listitem import ListItem
7+
from tests import test_client_credentials, test_team_site_url
8+
9+
10+
def print_progress(item):
11+
# type: (ListItem|File) -> None
12+
if isinstance(item, ListItem):
13+
print("List Item has been exported...")
14+
else:
15+
print("File has been downloaded...")
16+
17+
18+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
19+
20+
list_title = "Orders"
21+
lib = ctx.web.lists.get_by_title(list_title)
22+
export_path = os.path.join(tempfile.mkdtemp(), "{0}.zip".format(list_title))
23+
with open(export_path, "wb") as f:
24+
lib.export(f, True, print_progress).execute_query()
25+
print("List has been export into {0} ...".format(export_path))

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="graph",
29+
default="sharepoint",
3030
)
3131
parser.add_argument(
3232
"-p",
3333
"--path",
3434
dest="path",
35-
default="./metadata/MicrosoftGraph.xml",
35+
default="./metadata/SharePoint.xml",
3636
help="Import metadata endpoint",
3737
)
3838

generator/metadata/MicrosoftGraph.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25913,6 +25913,9 @@
2591325913
<EntityType Name="administrativeUnit" BaseType="graph.directoryObject" OpenType="true">
2591425914
<Property Name="description" Type="Edm.String"/>
2591525915
<Property Name="displayName" Type="Edm.String"/>
25916+
<Property Name="membershipRule" Type="Edm.String"/>
25917+
<Property Name="membershipRuleProcessingState" Type="Edm.String"/>
25918+
<Property Name="membershipType" Type="Edm.String"/>
2591625919
<Property Name="visibility" Type="Edm.String"/>
2591725920
<NavigationProperty Name="members" Type="Collection(graph.directoryObject)"/>
2591825921
<NavigationProperty Name="scopedRoleMembers" Type="Collection(graph.scopedRoleMembership)" ContainsTarget="true"/>

generator/metadata/SharePoint.xml

Lines changed: 129 additions & 9 deletions
Large diffs are not rendered by default.

office365/directory/users/user.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ def get_mail_tips(self, email_addresses, mail_tips_options=None):
193193
self.context.add_query(qry)
194194
return return_type
195195

196+
def get_my_site(self):
197+
"""Gets user's site"""
198+
return_type = Site(self.context)
199+
200+
def _loaded():
201+
return_type.set_property("webUrl", self.my_site)
202+
203+
self.ensure_property("mySite", _loaded)
204+
return return_type
205+
196206
def send_mail(
197207
self,
198208
subject,
@@ -535,11 +545,21 @@ def chats(self):
535545
@property
536546
def given_name(self):
537547
# type: () -> Optional[str]
538-
"""
539-
The given name (first name) of the user. Maximum length is 64 characters.
540-
"""
548+
"""The given name (first name) of the user. Maximum length is 64 characters"""
541549
return self.properties.get("givenName", None)
542550

551+
@property
552+
def my_site(self):
553+
# type: () -> Optional[str]
554+
"""The URL for the user's site."""
555+
return self.properties.get("mySite", None)
556+
557+
@property
558+
def office_location(self):
559+
# type: () -> Optional[str]
560+
"""The office location in the user's place of business."""
561+
return self.properties.get("officeLocation", None)
562+
543563
@property
544564
def user_principal_name(self):
545565
# type: () -> Optional[str]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from office365.onedrive.sites.site import Site
2+
from office365.runtime.paths.resource_path import ResourcePath
3+
from office365.runtime.paths.service_operation import ServiceOperationPath
4+
from office365.sharepoint.client_context import ClientContext
5+
from office365.sharepoint.entity import Entity
6+
from office365.sharepoint.webs.web import Web
7+
8+
9+
class AppContextSite(Entity):
10+
""" """
11+
12+
def __init__(self, context, site_url):
13+
# type: (ClientContext, str) -> None
14+
""""""
15+
static_path = ServiceOperationPath(
16+
"SP.AppContextSite",
17+
{"siteUrl": site_url},
18+
)
19+
super(AppContextSite, self).__init__(context, static_path)
20+
21+
@property
22+
def site(self):
23+
""""""
24+
return self.properties.get(
25+
"Site",
26+
Site(
27+
self.context,
28+
ResourcePath("Site", self.resource_path),
29+
),
30+
)
31+
32+
@property
33+
def web(self):
34+
""""""
35+
return self.properties.get(
36+
"Web",
37+
Web(
38+
self.context,
39+
ResourcePath("Web", self.resource_path),
40+
),
41+
)

office365/sharepoint/changes/change.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ def change_type_name(self):
1616

1717
@property
1818
def change_token(self):
19-
"""
20-
Returns an ChangeToken that represents the change.
21-
"""
19+
"""Returns an ChangeToken that represents the change."""
2220
return self.properties.get("ChangeToken", ChangeToken())
2321

2422
@property

office365/sharepoint/changes/collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def _resolve_change_type(self, properties):
2222
from office365.sharepoint.changes.item import ChangeItem
2323
from office365.sharepoint.changes.list import ChangeList
2424
from office365.sharepoint.changes.user import ChangeUser
25+
from office365.sharepoint.changes.view import ChangeView
2526
from office365.sharepoint.changes.web import ChangeWeb
2627

2728
if "ItemId" in properties and "ListId" in properties:
@@ -40,3 +41,5 @@ def _resolve_change_type(self, properties):
4041
self._item_type = ChangeAlert
4142
elif "FieldId" in properties:
4243
self._item_type = ChangeField
44+
elif "ViewId" in properties:
45+
self._item_type = ChangeView

office365/sharepoint/changes/folder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.sharepoint.changes.change import Change
24

35

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

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

1115
@property
1216
def web_id(self):
17+
# type: () -> Optional[str]
18+
"""Identifies the site that contains the changed folder."""
1319
return self.properties.get("WebId", None)

office365/sharepoint/changes/group.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.sharepoint.changes.change import Change
24

35

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

79
@property
810
def group_id(self):
11+
# type: () -> Optional[int]
912
"""Identifies the changed group."""
1013
return self.properties.get("GroupId", None)

office365/sharepoint/changes/list.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@ def __repr__(self):
1616

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

23+
@property
24+
def editor(self):
25+
# type: () -> Optional[str]
26+
"""A string that returns the name of the user who modified the list."""
27+
return self.properties.get("Editor", None)
28+
29+
@property
30+
def hidden(self):
31+
# type: () -> Optional[bool]
32+
"""Returns a Boolean value that indicates whether a list is a hidden list."""
33+
return self.properties.get("Hidden", None)
34+
2235
@property
2336
def list_id(self):
2437
# type: () -> Optional[str]

office365/sharepoint/changes/view.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import Optional
2+
3+
from office365.sharepoint.changes.change import Change
4+
5+
6+
class ChangeView(Change):
7+
"""Specifies a change on a view."""
8+
9+
@property
10+
def view_id(self):
11+
# type: () -> Optional[str]
12+
"""Identifies the changed view."""
13+
return self.properties.get("ViewId", None)
14+
15+
@property
16+
def list_id(self):
17+
# type: () -> Optional[str]
18+
"""Identifies the list that contains the changed view."""
19+
return self.properties.get("ListId", None)
20+
21+
@property
22+
def web_id(self):
23+
# type: () -> Optional[str]
24+
"""Identifies the site that contains the changed view."""
25+
return self.properties.get("WebId", None)

office365/sharepoint/client_context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,16 @@ def workflow_services_manager(self):
710710

711711
return WorkflowServicesManager.current(self)
712712

713+
@property
714+
def workflow_deployment_service(self):
715+
"""Alias to WorkflowServicesManager"""
716+
717+
from office365.sharepoint.workflowservices.deployment_service import (
718+
WorkflowDeploymentService,
719+
)
720+
721+
return WorkflowDeploymentService(self)
722+
713723
@property
714724
def work_items(self):
715725
""""""

office365/sharepoint/directory/provider/alternate_id_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
class AlternateIdData(ClientValue):
55
""""""
66

7+
def __init__(self, email=None, identifying_property=None, user_principal_name=None):
8+
self.Email = email
9+
self.IdentifyingProperty = identifying_property
10+
self.UserPrincipalName = user_principal_name
11+
712
@property
813
def entity_type_name(self):
914
return "SP.Directory.Provider.AlternateIdData"

office365/sharepoint/directory/provider/notification.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from office365.runtime.paths.resource_path import ResourcePath
2+
from office365.runtime.queries.service_operation import ServiceOperationQuery
23
from office365.sharepoint.entity import Entity
34

45

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

14+
def notify_changes(self, directory_object_changes):
15+
""" """
16+
payload = {"directoryObjectChanges": directory_object_changes}
17+
qry = ServiceOperationQuery(self, "NotifyChanges", None, payload, None, None)
18+
self.context.add_query(qry)
19+
return self
20+
1321
@property
1422
def entity_type_name(self):
1523
return "SP.Directory.Provider.DirectoryNotification"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class DirectoryObjectChanges(ClientValue):
5+
""" """

office365/sharepoint/directory/provider/object_data.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
from office365.runtime.client_value import ClientValue
22
from office365.sharepoint.directory.provider.alternate_id_data import AlternateIdData
3+
from office365.sharepoint.directory.provider.session_data import DirectorySessionData
34

45

56
class DirectoryObjectData(ClientValue):
67
""""""
78

8-
def __init__(self, AlternateId=AlternateIdData(), Id=None):
9-
self.AlternateId = AlternateId
10-
self.Id = Id
9+
def __init__(
10+
self,
11+
alternate_id=AlternateIdData(),
12+
attribute_expiration_times=None,
13+
change_marker=None,
14+
directory_object_sub_type=None,
15+
directory_object_type=None,
16+
directory_session_data=DirectorySessionData(),
17+
id_=None,
18+
is_new=None,
19+
last_modified_time=None,
20+
tenant_context_id=None,
21+
version=None,
22+
):
23+
self.AlternateId = alternate_id
24+
self.AttributeExpirationTimes = attribute_expiration_times
25+
self.ChangeMarker = change_marker
26+
self.DirectoryObjectSubType = directory_object_sub_type
27+
self.DirectoryObjectType = directory_object_type
28+
self.DirectorySessionData = directory_session_data
29+
self.Id = id_
30+
self.IsNew = is_new
31+
self.LastModifiedTime = last_modified_time
32+
self.TenantContextId = tenant_context_id
33+
self.Version = version
1134

1235
@property
1336
def entity_type_name(self):

office365/sharepoint/directory/provider/provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, context, resource_path=None):
1414
super(SharePointDirectoryProvider, self).__init__(context, resource_path)
1515

1616
def read_directory_object(self, data):
17+
# type: (DirectoryObjectData) -> ClientResult[DirectoryObjectData]
1718
""""""
1819
return_type = ClientResult(self.context, DirectoryObjectData())
1920
payload = {"data": data}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class DirectorySessionData(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
# type: () -> str
9+
return "SP.Directory.Provider.DirectorySessionData"

0 commit comments

Comments
 (0)