Skip to content

Commit d6d8201

Browse files
committed
OneDrive model & method updates
1 parent 0be4212 commit d6d8201

File tree

18 files changed

+1330
-241
lines changed

18 files changed

+1330
-241
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from examples import acquire_token_by_username_password
2+
from office365.graph_client import GraphClient
3+
4+
5+
client = GraphClient(acquire_token_by_username_password)
6+
7+
remote_drive = client.me.drive.root
8+
pptx_file = remote_drive.create_powerpoint("sample.pptx").execute_query()
9+
print(f"File {pptx_file.web_url} has been uploaded")

generator/metadata/SharePoint.xml

Lines changed: 1170 additions & 234 deletions
Large diffs are not rendered by default.

office365/directory/authentication/authentication.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def phone_methods(self):
2626
EntityCollection(self.context, PhoneAuthenticationMethod,
2727
ResourcePath("phoneMethods", self.resource_path)))
2828

29+
@property
30+
def password_methods(self):
31+
"""Represents the password that's registered to a user for authentication. For security, the password itself
32+
will never be returned in the object, but action can be taken to reset a password."""
33+
from office365.directory.authentication.methods.password import PasswordAuthenticationMethod
34+
return self.properties.get('passwordMethods',
35+
EntityCollection(self.context, PasswordAuthenticationMethod,
36+
ResourcePath("passwordMethods", self.resource_path)))
37+
2938
@property
3039
def methods(self):
3140
"""Represents all authentication methods registered to a user."""
@@ -37,6 +46,7 @@ def get_property(self, name, default_value=None):
3746
if default_value is None:
3847
property_mapping = {
3948
"fido2Methods": self.fido2_methods,
49+
"passwordMethods": self.password_methods,
4050
"phoneMethods": self.phone_methods
4151
}
4252
default_value = property_mapping.get(name, None)

office365/directory/authentication/methods/fido.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33

44
class Fido2AuthenticationMethod(AuthenticationMethod):
55
"""Representation of a FIDO2 security key registered to a user. FIDO2 is a sign-in authentication method."""
6-
7-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from office365.directory.authentication.methods.method import AuthenticationMethod
2+
3+
4+
class PasswordAuthenticationMethod(AuthenticationMethod):
5+
"""A representation of a user's password. For security, the password itself will never be returned in the object,
6+
but action can be taken to reset a password."""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1+
from office365.directory.identities.identity_set import IdentitySet
2+
from office365.onedrive.documentsets.version_item import DocumentSetVersionItem
13
from office365.onedrive.versions.list_item import ListItemVersion
4+
from office365.runtime.client_value_collection import ClientValueCollection
25

36

47
class DocumentSetVersion(ListItemVersion):
58
"""Represents the version of a document set item in a list."""
9+
10+
@property
11+
def comment(self):
12+
"""Comment about the captured version."""
13+
return self.properties.get("comment", None)
14+
15+
@property
16+
def created_by(self):
17+
"""User who captured the version."""
18+
return self.properties.get("createdBy", IdentitySet())
19+
20+
@property
21+
def items(self):
22+
"""Items within the document set that are captured as part of this version."""
23+
return self.properties.get("items", ClientValueCollection(DocumentSetVersionItem))
24+
25+
@property
26+
def should_capture_minor_version(self):
27+
"""
28+
If true, minor versions of items are also captured; otherwise, only major versions will be captured.
29+
Default value is false.
30+
"""
31+
return self.properties.get("shouldCaptureMinorVersion", None)

office365/onedrive/driveitems/driveItem.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def get_by_path(self, url_path):
4646
"""
4747
return DriveItem(self.context, UrlPath(url_path, self.resource_path), self.children)
4848

49+
def create_powerpoint(self, name):
50+
"""
51+
Creates a PowerPoint file
52+
53+
:param str name:
54+
"""
55+
return self.upload(name, None)
56+
4957
def create_link(self, link_type, scope="", expiration_datetime=None, password=None, message=None):
5058
"""
5159
The createLink action will create a new sharing link if the specified link type doesn't already exist
@@ -154,7 +162,7 @@ def upload(self, name, content):
154162
:param name: The contents of the request body should be the binary stream of the file to be uploaded.
155163
:type name: str
156164
:param content: The contents of the request body should be the binary stream of the file to be uploaded.
157-
:type content: str or bytes
165+
:type content: str or bytes or None
158166
:rtype: DriveItem
159167
"""
160168
qry = create_upload_content_query(self, name, content)

office365/onedrive/driveitems/publication_facet.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
class PublicationFacet(ClientValue):
55

6-
def __init__(self, level=None, versionId=None):
6+
def __init__(self, level=None, version_id=None):
77
"""
8+
The publicationFacet resource provides details on the published status of a driveItemVersion
9+
or driveItem resource.
810
911
:param str level: The state of publication for this document. Either published or checkout. Read-only.
10-
:param str versionId: The unique identifier for the version that is visible to the current caller. Read-only.
12+
:param str version_id: The unique identifier for the version that is visible to the current caller. Read-only.
1113
"""
1214
super(PublicationFacet, self).__init__()
1315
self.level = level
14-
self.versionId = versionId
16+
self.versionId = version_id

office365/onedrive/driveitems/remote_item.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from office365.directory.identities.identity_set import IdentitySet
12
from office365.runtime.client_value import ClientValue
23

34

@@ -9,3 +10,6 @@ class RemoteItem(ClientValue):
910
DriveItems with a non-null remoteItem facet are resources that are shared, added to the user's OneDrive,
1011
or on items returned from hetrogenous collections of items (like search results).
1112
"""
13+
14+
def __init__(self, created_by=IdentitySet()):
15+
self.createdBy = created_by
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from office365.entity_collection import EntityCollection
2+
from office365.onedrive.analytics.item_activity_stat import ItemActivityStat
3+
from office365.runtime.http.http_method import HttpMethod
4+
from office365.runtime.queries.service_operation import ServiceOperationQuery
5+
6+
7+
def build_get_activities_by_interval_query(binding_type, start_dt=None, end_dt=None, interval=None):
8+
"""
9+
:param office365.entity.Entity binding_type: Binding type
10+
:param datetime.datetime start_dt: The start time over which to aggregate activities.
11+
:param datetime.datetime end_dt: The end time over which to aggregate activities.
12+
:param str interval: The aggregation interval.
13+
"""
14+
params = {
15+
"startDateTime": start_dt.strftime('%m-%d-%Y') if start_dt else None,
16+
"endDateTime": end_dt.strftime('%m-%d-%Y') if end_dt else None,
17+
"interval": interval
18+
}
19+
return_type = EntityCollection(binding_type.context, ItemActivityStat, binding_type.resource_path)
20+
qry = ServiceOperationQuery(binding_type, "getActivitiesByInterval", params, None, None, return_type)
21+
22+
def _construct_request(request):
23+
request.method = HttpMethod.Get
24+
binding_type.context.before_execute(_construct_request)
25+
return qry

0 commit comments

Comments
 (0)