Skip to content

Commit

Permalink
typings improvements for Outlook and OneDrive APIs, examples updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Oct 25, 2023
1 parent 476b170 commit 4b62b64
Show file tree
Hide file tree
Showing 38 changed files with 202 additions and 95 deletions.
6 changes: 4 additions & 2 deletions examples/onedrive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def ensure_workbook_sample(graph_client):
except ClientRequestException as e:
if e.response.status_code == 404:
local_path = "../../data/Financial Sample.xlsx"
target_file = graph_client.me.drive.root.upload(local_path).execute_query()
print(f"File {target_file.web_url} has been uploaded")
target_file = graph_client.me.drive.root.upload_file(
local_path
).execute_query()
print("File {0} has been uploaded".format(target_file.web_url))
return target_file.workbook
else:
raise ValueError(e.response.text)
12 changes: 2 additions & 10 deletions examples/onedrive/columns/create_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@
from tests import create_unique_name
from tests.graph_case import acquire_token_by_username_password


def clean_up(columns):
"""
:type columns: list[office365.onedrive.columns.definition.ColumnDefinition]
"""
[column.delete_object().execute_query() for column in columns]


client = GraphClient(acquire_token_by_username_password)
lib = client.sites.root.lists["Docs"]
lib = client.sites.root.lists["Documents"]

column_name = create_unique_name("LookupColumn")
lookup_column = lib.columns.add_lookup(column_name, lib).execute_query()
print(lookup_column.display_name)

clean_up([lookup_column])
lookup_column.delete_object().execute_query() # clean up
2 changes: 2 additions & 0 deletions examples/onedrive/files/list_shared_with_me.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
Retrieves a collection of DriveItem resources that have been shared with the current user
https://learn.microsoft.com/en-us/graph/api/drive-sharedwithme?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password
Expand Down
5 changes: 3 additions & 2 deletions examples/onedrive/files/share_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
https://learn.microsoft.com/en-us/graph/api/driveitem-invite?view=graph-rest-1.0
"""
import json
from datetime import datetime, timedelta

from examples import upload_sample_files
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password

Expand All @@ -24,4 +24,5 @@
expiration_datetime=None,
password="password123",
).execute_query()
print(json.dumps(permissions.to_json(), indent=4))
for perm in permissions:
print(perm.granted_to_identities)
2 changes: 1 addition & 1 deletion examples/onedrive/sites/get_all.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
List root sites across geographies in an organization.
https://learn.microsoft.com/en-us/graph/api/site-getallsites?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/site-getallsites?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_client_credentials
Expand Down
2 changes: 1 addition & 1 deletion examples/onedrive/sites/grant_permission.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Grant permissions on a site.
https://learn.microsoft.com/en-us/graph/api/site-post-permissions?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/site-post-permissions?view=graph-rest-1.0
"""
import json

Expand Down
4 changes: 2 additions & 2 deletions examples/onedrive/sites/list_permissions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
List site permissions
https://learn.microsoft.com/en-us/graph/api/site-list-permissions?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/site-list-permissions?view=graph-rest-1.0
"""

from office365.graph_client import GraphClient
Expand All @@ -12,4 +12,4 @@
client.sites.get_by_url(test_team_site_url).permissions.get().execute_query()
)
for perm in permissions:
print(perm)
print(perm.granted_to)
2 changes: 1 addition & 1 deletion examples/outlook/calendars/list_my.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
client = GraphClient(acquire_token_by_username_password)
calendars = client.me.calendars.top(10).get().execute_query()
for cal in calendars:
print(cal.name)
print(cal)
5 changes: 3 additions & 2 deletions examples/outlook/events/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
https://learn.microsoft.com/en-us/graph/api/calendar-list-events?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from office365.outlook.calendar.events.event import Event
from tests.graph_case import acquire_token_by_username_password

client = GraphClient(acquire_token_by_username_password)
events = client.me.calendar.events.get_all().select(["subject", "body"]).execute_query()
events = (
client.me.calendar.events.get().top(100).select(["subject", "body"]).execute_query()
)
for event in events:
print(event.subject)
103 changes: 77 additions & 26 deletions generator/metadata/MicrosoftGraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14985,10 +14985,10 @@
<Annotations Target="microsoft.graph.schedulingGroup/isActive">
<Annotation Term="Org.OData.Core.V1.Computed" Bool="true"/>
</Annotations>
<Annotations Target="microsoft.graph.security.host">
<Annotations Target="microsoft.graph.security.hostComponent">
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
<Record>
<PropertyValue Property="Countable" Bool="false"/>
<PropertyValue Property="Countable" Bool="true"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.ExpandRestrictions">
Expand All @@ -15011,18 +15011,13 @@
<PropertyValue Property="Selectable" Bool="true"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="false"/>
<Annotation Term="Org.OData.Capabilities.V1.SortRestrictions">
<Record>
<PropertyValue Property="Sortable" Bool="false"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="false"/>
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="true"/>
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="true"/>
</Annotations>
<Annotations Target="microsoft.graph.security.article">
<Annotations Target="microsoft.graph.security.host">
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
<Record>
<PropertyValue Property="Countable" Bool="true"/>
<PropertyValue Property="Countable" Bool="false"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.ExpandRestrictions">
Expand All @@ -15037,23 +15032,23 @@
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
<Record>
<PropertyValue Property="Searchable" Bool="true"/>
<PropertyValue Property="Searchable" Bool="false"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SelectRestrictions">
<Record>
<PropertyValue Property="Selectable" Bool="true"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="true"/>
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="false"/>
<Annotation Term="Org.OData.Capabilities.V1.SortRestrictions">
<Record>
<PropertyValue Property="Sortable" Bool="false"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="true"/>
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="false"/>
</Annotations>
<Annotations Target="microsoft.graph.security.articleIndicator">
<Annotations Target="microsoft.graph.security.article">
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
<Record>
<PropertyValue Property="Countable" Bool="true"/>
Expand All @@ -15071,7 +15066,7 @@
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
<Record>
<PropertyValue Property="Searchable" Bool="false"/>
<PropertyValue Property="Searchable" Bool="true"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SelectRestrictions">
Expand All @@ -15080,9 +15075,14 @@
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="true"/>
<Annotation Term="Org.OData.Capabilities.V1.SortRestrictions">
<Record>
<PropertyValue Property="Sortable" Bool="false"/>
</Record>
</Annotation>
<Annotation Term="Org.OData.Capabilities.V1.TopSupported" Bool="true"/>
</Annotations>
<Annotations Target="microsoft.graph.security.hostComponent">
<Annotations Target="microsoft.graph.security.articleIndicator">
<Annotation Term="Org.OData.Capabilities.V1.CountRestrictions">
<Record>
<PropertyValue Property="Countable" Bool="true"/>
Expand Down Expand Up @@ -37265,6 +37265,17 @@
<Member Name="appGovernanceDetection" Value="2097152"/>
<Member Name="unknownFutureValue" Value="4194303"/>
<Member Name="microsoftDefenderForCloud" Value="4194304"/>
<Member Name="microsoftDefenderForIoT" Value="1073741833"/>
<Member Name="microsoftDefenderForServers" Value="1073741834"/>
<Member Name="microsoftDefenderForStorage" Value="1073741835"/>
<Member Name="microsoftDefenderForDNS" Value="1073741836"/>
<Member Name="microsoftDefenderForDatabases" Value="1073741837"/>
<Member Name="microsoftDefenderForContainers" Value="1073741838"/>
<Member Name="microsoftDefenderForNetwork" Value="1073741839"/>
<Member Name="microsoftDefenderForAppService" Value="1073741840"/>
<Member Name="microsoftDefenderForKeyVault" Value="1073741841"/>
<Member Name="microsoftDefenderForResourceManager" Value="1073741842"/>
<Member Name="microsoftDefenderForApiManagement" Value="1073741843"/>
<Member Name="nrtAlerts" Value="1073741844"/>
<Member Name="scheduledAlerts" Value="1073741845"/>
<Member Name="microsoftDefenderThreatIntelligenceAnalytics" Value="1073741846"/>
Expand Down Expand Up @@ -37424,6 +37435,17 @@
<Member Name="markdown" Value="2"/>
<Member Name="unknownFutureValue" Value="3"/>
</EnumType>
<EnumType Name="hostPortProtocol">
<Member Name="tcp" Value="0"/>
<Member Name="udp" Value="1"/>
<Member Name="unknownFutureValue" Value="2"/>
</EnumType>
<EnumType Name="hostPortStatus">
<Member Name="open" Value="0"/>
<Member Name="filtered" Value="1"/>
<Member Name="closed" Value="2"/>
<Member Name="unknownFutureValue" Value="3"/>
</EnumType>
<EnumType Name="hostReputationClassification">
<Member Name="unknown" Value="0"/>
<Member Name="neutral" Value="1"/>
Expand Down Expand Up @@ -37532,6 +37554,7 @@
<NavigationProperty Name="hostComponents" Type="Collection(microsoft.graph.security.hostComponent)" ContainsTarget="true"/>
<NavigationProperty Name="hostCookies" Type="Collection(microsoft.graph.security.hostCookie)" ContainsTarget="true"/>
<NavigationProperty Name="hostPairs" Type="Collection(microsoft.graph.security.hostPair)" ContainsTarget="true"/>
<NavigationProperty Name="hostPorts" Type="Collection(microsoft.graph.security.hostPort)" ContainsTarget="true"/>
<NavigationProperty Name="hosts" Type="Collection(microsoft.graph.security.host)" ContainsTarget="true"/>
<NavigationProperty Name="hostSslCertificates" Type="Collection(microsoft.graph.security.hostSslCertificate)" ContainsTarget="true"/>
<NavigationProperty Name="hostTrackers" Type="Collection(microsoft.graph.security.hostTracker)" ContainsTarget="true"/>
Expand Down Expand Up @@ -38026,6 +38049,28 @@
<Property Name="content" Type="Edm.String"/>
<Property Name="format" Type="microsoft.graph.security.contentFormat"/>
</ComplexType>
<ComplexType Name="hostPortBanner">
<Property Name="banner" Type="Edm.String" Nullable="false"/>
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="scanProtocol" Type="Edm.String"/>
<Property Name="timesObserved" Type="Edm.Int32"/>
</ComplexType>
<ComplexType Name="hostPortComponent">
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="isRecent" Type="Edm.Boolean"/>
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset"/>
<NavigationProperty Name="component" Type="microsoft.graph.security.hostComponent"/>
</ComplexType>
<EntityType Name="artifact" BaseType="graph.entity" Abstract="true"/>
<EntityType Name="hostComponent" BaseType="microsoft.graph.security.artifact">
<Property Name="category" Type="Edm.String"/>
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
<Property Name="name" Type="Edm.String" Nullable="false"/>
<Property Name="version" Type="Edm.String"/>
<NavigationProperty Name="host" Type="microsoft.graph.security.host" Nullable="false"/>
</EntityType>
<ComplexType Name="hostReputationRule">
<Property Name="description" Type="Edm.String" Nullable="false"/>
<Property Name="name" Type="Edm.String" Nullable="false"/>
Expand Down Expand Up @@ -38069,7 +38114,6 @@
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset"/>
<NavigationProperty Name="host" Type="microsoft.graph.security.host" Nullable="false"/>
</ComplexType>
<EntityType Name="artifact" BaseType="graph.entity" Abstract="true"/>
<EntityType Name="host" BaseType="microsoft.graph.security.artifact" Abstract="true">
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset"/>
Expand All @@ -38080,6 +38124,7 @@
<NavigationProperty Name="parentHostPairs" Type="Collection(microsoft.graph.security.hostPair)"/>
<NavigationProperty Name="passiveDns" Type="Collection(microsoft.graph.security.passiveDnsRecord)"/>
<NavigationProperty Name="passiveDnsReverse" Type="Collection(microsoft.graph.security.passiveDnsRecord)"/>
<NavigationProperty Name="ports" Type="Collection(microsoft.graph.security.hostPort)"/>
<NavigationProperty Name="reputation" Type="microsoft.graph.security.hostReputation" ContainsTarget="true"/>
<NavigationProperty Name="sslCertificates" Type="Collection(microsoft.graph.security.hostSslCertificate)"/>
<NavigationProperty Name="subdomains" Type="Collection(microsoft.graph.security.subdomain)"/>
Expand Down Expand Up @@ -38109,14 +38154,6 @@
<NavigationProperty Name="childHost" Type="microsoft.graph.security.host" Nullable="false"/>
<NavigationProperty Name="parentHost" Type="microsoft.graph.security.host" Nullable="false"/>
</EntityType>
<EntityType Name="hostComponent" BaseType="microsoft.graph.security.artifact">
<Property Name="category" Type="Edm.String"/>
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
<Property Name="name" Type="Edm.String" Nullable="false"/>
<Property Name="version" Type="Edm.String"/>
<NavigationProperty Name="host" Type="microsoft.graph.security.host" Nullable="false"/>
</EntityType>
<EntityType Name="hostCookie" BaseType="microsoft.graph.security.artifact">
<Property Name="domain" Type="Edm.String" Nullable="false"/>
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
Expand All @@ -38132,6 +38169,19 @@
<NavigationProperty Name="artifact" Type="microsoft.graph.security.artifact" Nullable="false"/>
<NavigationProperty Name="parentHost" Type="microsoft.graph.security.host" Nullable="false"/>
</EntityType>
<EntityType Name="hostPort" BaseType="graph.entity">
<Property Name="banners" Type="Collection(microsoft.graph.security.hostPortBanner)"/>
<Property Name="firstSeenDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="lastScanDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="lastSeenDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="port" Type="Edm.Int32" Nullable="false"/>
<Property Name="protocol" Type="microsoft.graph.security.hostPortProtocol"/>
<Property Name="services" Type="Collection(microsoft.graph.security.hostPortComponent)"/>
<Property Name="status" Type="microsoft.graph.security.hostPortStatus"/>
<Property Name="timesObserved" Type="Edm.Int32"/>
<NavigationProperty Name="host" Type="microsoft.graph.security.host" Nullable="false"/>
<NavigationProperty Name="mostRecentSslCertificate" Type="microsoft.graph.security.sslCertificate"/>
</EntityType>
<EntityType Name="hostReputation" BaseType="graph.entity">
<Property Name="classification" Type="microsoft.graph.security.hostReputationClassification" Nullable="false"/>
<Property Name="rules" Type="Collection(microsoft.graph.security.hostReputationRule)"/>
Expand Down Expand Up @@ -38926,6 +38976,7 @@
<EntityType Name="externalConnection" BaseType="graph.entity">
<Property Name="activitySettings" Type="microsoft.graph.externalConnectors.activitySettings"/>
<Property Name="configuration" Type="microsoft.graph.externalConnectors.configuration"/>
<Property Name="connectorId" Type="Edm.String"/>
<Property Name="description" Type="Edm.String"/>
<Property Name="name" Type="Edm.String"/>
<Property Name="searchSettings" Type="microsoft.graph.externalConnectors.searchSettings"/>
Expand Down
5 changes: 2 additions & 3 deletions office365/directory/object_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from office365.entity_collection import EntityCollection
from office365.runtime.client_result import ClientResult
from office365.runtime.http.http_method import HttpMethod
from office365.runtime.http.request_options import RequestOptions
from office365.runtime.queries.service_operation import ServiceOperationQuery


Expand Down Expand Up @@ -68,9 +69,7 @@ def remove(self, user_id):
qry = ServiceOperationQuery(self, "{0}/$ref".format(user_id))

def _construct_request(request):
"""
:type request: RequestOptions
"""
# type: (RequestOptions) -> None
request.method = HttpMethod.Delete

self.context.add_query(qry).before_query_execute(_construct_request)
Expand Down
8 changes: 8 additions & 0 deletions office365/directory/permissions/email_identity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from typing import Optional

from office365.directory.permissions.identity import Identity


class EmailIdentity(Identity):
"""Represents the email identity of a user."""

@property
def email(self):
# type: () -> Optional[str]
"""Email address of the user"""
return self.properties.get("email", None)
3 changes: 3 additions & 0 deletions office365/directory/permissions/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ def __init__(self, display_name=None, _id=None):
super(Identity, self).__init__()
self.displayName = display_name
self.id = _id

def __repr__(self):
return repr(self.to_json())
3 changes: 3 additions & 0 deletions office365/directory/permissions/identity_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ def __init__(self, application=Identity(), device=Identity(), user=Identity()):
self.application = application
self.device = device
self.user = user

def __repr__(self):
return repr({n: v.to_json() for n, v in self if v.to_json()})
Loading

0 comments on commit 4b62b64

Please sign in to comment.