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)

0 commit comments

Comments
 (0)