Skip to content

Commit dd08028

Browse files
committed
OneDrive API : fix for shared path addressing (#801)
1 parent 40ae03a commit dd08028

File tree

15 files changed

+143
-38
lines changed

15 files changed

+143
-38
lines changed

examples/onedrive/files/get_by_abs_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tests import test_team_site_url
66
from tests.graph_case import acquire_token_by_username_password
77

8-
file_abs_url = "{0}/Shared Documents/big_buck_bunny.mp4".format(test_team_site_url)
8+
file_abs_url = "{0}/Shared Documents/Financial Sample.xlsx".format(test_team_site_url)
99

1010
client = GraphClient(acquire_token_by_username_password)
1111
file_item = client.shares.by_url(file_abs_url).drive_item.get().execute_query()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
Get workbook
3+
"""
4+
from office365.graph_client import GraphClient
5+
from tests import test_team_site_url
6+
from tests.graph_case import acquire_token_by_username_password
7+
8+
file_abs_url = "{0}/Shared Documents/Financial Sample.xlsx".format(test_team_site_url)
9+
10+
client = GraphClient(acquire_token_by_username_password)
11+
drive_item = client.shares.by_url(file_abs_url).drive_item.get().execute_query()
12+
worksheets = drive_item.workbook.worksheets.get().execute_query()
13+
for ws in worksheets:
14+
print(ws)

examples/onenote/__init__.py

Whitespace-only changes.

examples/onenote/create_notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Demonstrates how to create a new OneNote notebook
33
4-
https://learn.microsoft.com/en-us/graph/api/onenote-post-notebooks?view=graph-rest-1.0&tabs=http
4+
https://learn.microsoft.com/en-us/graph/api/onenote-post-notebooks?view=graph-rest-1.0
55
"""
66

77
from office365.graph_client import GraphClient

office365/directory/applications/template.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
24
from office365.runtime.client_result import ClientResult
35
from office365.runtime.queries.service_operation import ServiceOperationQuery
@@ -25,11 +27,8 @@ def instantiate(self, display_name):
2527

2628
@property
2729
def display_name(self):
28-
"""
29-
The name of the application.
30-
31-
:rtype: str or None
32-
"""
30+
# type: () -> Optional[str]
31+
"""The name of the application."""
3332
return self.properties.get("displayName", None)
3433

3534
@property
@@ -44,9 +43,7 @@ def categories(self):
4443

4544
@property
4645
def supported_provisioning_types(self):
47-
"""
48-
The list of provisioning modes supported by this application
49-
"""
46+
"""The list of provisioning modes supported by this application"""
5047
return self.properties.get("supportedProvisioningTypes", StringCollection())
5148

5249
@property

office365/directory/protection/riskyusers/history_item.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.directory.protection.riskyusers.activity import RiskUserActivity
24
from office365.directory.protection.riskyusers.risky_user import RiskyUser
35

@@ -13,7 +15,6 @@ def activity(self):
1315

1416
@property
1517
def initiated_by(self):
16-
"""The ID of actor that does the operation.
17-
:rtype: str
18-
"""
18+
# type: () -> Optional[str]
19+
"""The ID of actor that does the operation."""
1920
return self.properties.get("initiatedBy", None)

office365/onedrive/driveitems/driveItem.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ def subscriptions(self):
795795
),
796796
)
797797

798+
def set_property(self, name, value, persist_changes=True):
799+
super(DriveItem, self).set_property(name, value, persist_changes)
800+
if name == "parentReference":
801+
self._resource_path.parent.patch(self.parent_reference.driveId)
802+
return self
803+
798804
def get_property(self, name, default_value=None):
799805
# type: (str, P_T) -> P_T
800806
if default_value is None:
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import base64
22

33
from office365.runtime.paths.resource_path import ResourcePath
4+
from office365.runtime.paths.v4.entity import EntityPath
45

56

67
def _url_to_shared_token(url):
7-
"""
8-
Converts url into shared token
9-
:param str url:
10-
"""
8+
# type: (str) -> str
9+
"""Converts url into shared token"""
1110
value = base64.b64encode(url.encode("ascii")).decode("ascii")
1211
if value.endswith("="):
1312
value = value[:-1]
1413
return "u!" + value.replace("/", "_").replace("+", "-")
1514

1615

17-
class SharedPath(ResourcePath):
16+
class SharedPath(EntityPath):
1817
"""Shared token path"""
1918

19+
def patch(self, key):
20+
self._key = "items"
21+
self._parent = ResourcePath(key, ResourcePath("drives"))
22+
self.__class__ = ResourcePath
23+
return self
24+
2025
@property
2126
def segment(self):
2227
return _url_to_shared_token(self._key)

office365/onedrive/shares/drive_item.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from office365.onedrive.permissions.permission import Permission
99
from office365.onedrive.sites.site import Site
1010
from office365.runtime.paths.resource_path import ResourcePath
11+
from office365.runtime.paths.v4.entity import EntityPath
1112

1213

1314
class SharedDriveItem(BaseItem):
@@ -47,7 +48,7 @@ def drive_item(self):
4748
"""Used to access the underlying driveItem"""
4849
return self.properties.get(
4950
"driveItem",
50-
DriveItem(self.context, ResourcePath("driveItem", self.resource_path)),
51+
DriveItem(self.context, EntityPath("driveItem", self.resource_path)),
5152
)
5253

5354
@property

office365/onedrive/workbooks/names/named_item.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
4+
from office365.onedrive.workbooks.ranges.range import WorkbookRange
25
from office365.runtime.paths.resource_path import ResourcePath
6+
from office365.runtime.queries.function import FunctionQuery
37

48

59
class WorkbookNamedItem(Entity):
610
"""Represents a defined name for a range of cells or value. Names can be primitive named objects
711
(as seen in the type below), range object, reference to a range. This object can be used to obtain range
812
object associated with names."""
913

14+
def range(self):
15+
"""Returns the range object that is associated with the name. Throws an exception if the named item's type
16+
isn't a range."""
17+
return_type = WorkbookRange(
18+
self.context, ResourcePath("range", self.resource_path)
19+
)
20+
qry = FunctionQuery(self, "range", return_type=return_type)
21+
self.context.add_query(qry)
22+
return return_type
23+
1024
@property
1125
def name(self):
12-
"""The name of the object. Read-only.
13-
:rtype str or None
14-
"""
26+
# type: () -> Optional[str]
27+
"""The name of the object."""
1528
return self.properties.get("name", None)
1629

1730
@property
1831
def comment(self):
19-
"""Represents the comment associated with this name.
20-
:rtype str or None
21-
"""
32+
# type: () -> Optional[str]
33+
"""Represents the comment associated with this name."""
2234
return self.properties.get("comment", None)
2335

2436
@property

0 commit comments

Comments
 (0)