Skip to content

Commit d824cc6

Browse files
committed
Microsoft Search API improvements
1 parent a0abb43 commit d824cc6

File tree

23 files changed

+293
-53
lines changed

23 files changed

+293
-53
lines changed

examples/directory/applications/grant_application_perms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
from office365.graph_client import GraphClient
1818
from tests import (
19-
test_admin_principal_name,
2019
test_client_id,
2120
test_client_secret,
2221
test_tenant,
2322
)
2423

2524
# client = GraphClient.with_token_interactive(
26-
# test_tenant, test_client_id, test_admin_principal_name
25+
# test_tenant, test_client_id, test_admin_principal_name
2726
# )
2827
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2928

examples/outlook/messages/__init__.py

Whitespace-only changes.

examples/outlook/messages/create_draft.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
test_client_secret,
1111
test_tenant,
1212
test_user_principal_name,
13+
test_username,
1314
)
1415

1516
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
16-
client.users[test_user_principal_name].messages.add(
17-
subject="Meet for lunch?",
18-
body="The new cafeteria is open.",
19-
to_recipients=["fannyd@contoso.onmicrosoft.com"],
20-
).send().execute_query()
17+
draft_message = (
18+
client.users[test_user_principal_name]
19+
.messages.add(
20+
subject="Meet for lunch?",
21+
body="The new cafeteria is open.",
22+
to_recipients=["fannyd@contoso.onmicrosoft.com", test_username],
23+
)
24+
.execute_query()
25+
)
26+
print(draft_message)

examples/outlook/messages/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
client = GraphClient.with_username_and_password(
1111
test_tenant, test_client_id, test_username, test_password
1212
)
13-
result = client.search.query_messages("Let's go for lunch").execute_query()
13+
result = client.search.query_messages("Meet for lunch?").execute_query()
1414
for item in result.value:
1515
for hit in item.hitsContainers[0].hits:
1616
print(hit.resource.get("webLink"))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Search messages in a user's mailbox
3+
4+
https://learn.microsoft.com/en-us/graph/search-concept-messages
5+
"""
6+
7+
from office365.graph_client import GraphClient
8+
from tests import test_client_id, test_password, test_tenant, test_username
9+
10+
client = GraphClient.with_username_and_password(
11+
test_tenant, test_client_id, test_username, test_password
12+
)
13+
result = client.search.query_messages(
14+
"Meet for lunch?", page_from=1, size=10
15+
).execute_query()
16+
for item in result.value:
17+
for hit in item.hitsContainers[0].hits:
18+
print(hit.resource.get_property("webLink"))

examples/outlook/messages/update.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Create a single-value extended property for a message
3+
4+
Demonstrates how to update the properties of a message object.
5+
6+
https://learn.microsoft.com/en-us/graph/api/message-update?view=graph-rest-1.0
7+
"""
8+
9+
import sys
10+
11+
from office365.graph_client import GraphClient
12+
from tests import test_client_id, test_password, test_tenant, test_username
13+
14+
client = GraphClient.with_username_and_password(
15+
test_tenant, test_client_id, test_username, test_password
16+
)
17+
messages = client.me.messages.top(1).get().execute_query()
18+
if len(messages) == 0:
19+
sys.exit("No messages were found")
20+
21+
22+
message = messages[0]
23+
message.subject = "Updated subject"
24+
message.body = "Updated body text"
25+
message.update().execute_query()

generator/builders/type_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _resolve_template_file(self, type_name):
4747
"EntityType": "entity_type.py",
4848
}
4949
path = abspath(
50-
os.path.join(self._options["templatePath"], file_mapping[type_name])
50+
os.path.join(self._options.get("templatepath"), file_mapping[type_name])
5151
)
5252
return path
5353

@@ -65,7 +65,7 @@ def _resolve_type(self, type_name):
6565
else:
6666
type_info["state"] = "detached"
6767
type_info["file"] = abspath(
68-
os.path.join(self._options["outputPath"], type_name + ".py")
68+
os.path.join(self._options["outputpath"], type_name + ".py")
6969
)
7070
return type_info
7171

generator/generate_model.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
from configparser import ConfigParser
2+
13
from generator import load_settings
24
from generator.builders.type_builder import TypeBuilder
5+
from office365.runtime.odata.model import ODataModel
36
from office365.runtime.odata.v3.metadata_reader import ODataV3Reader
47
from office365.runtime.odata.v4.metadata_reader import ODataV4Reader
58

69

710
def generate_files(model, options):
8-
"""
9-
:type model: office365.runtime.odata.model.ODataModel
10-
:type options: ConfigParser
11-
"""
11+
# type: (ODataModel, dict) -> None
1212
for name in model.types:
1313
type_schema = model.types[name]
1414
builder = TypeBuilder(type_schema, options)
@@ -18,16 +18,18 @@ def generate_files(model, options):
1818

1919

2020
def generate_sharepoint_model(settings):
21+
# type: (ConfigParser) -> None
2122
reader = ODataV3Reader(settings.get("sharepoint", "metadataPath"))
2223
reader.format_file()
2324
model = reader.generate_model()
24-
generate_files(model, settings)
25+
generate_files(model, dict(settings.items("sharepoint")))
2526

2627

2728
def generate_graph_model(settings):
29+
# type: (ConfigParser) -> None
2830
reader = ODataV4Reader(settings.get("microsoftgraph", "metadataPath"))
2931
model = reader.generate_model()
30-
generate_files(model, settings)
32+
generate_files(model, dict(settings.items("microsoftgraph")))
3133

3234

3335
if __name__ == "__main__":

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: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,6 +3948,11 @@
39483948
<PropertyValue Property="Filterable" Bool="true"/>
39493949
</Record>
39503950
</Annotation>
3951+
<Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
3952+
<Record>
3953+
<PropertyValue Property="Referenceable" Bool="false"/>
3954+
</Record>
3955+
</Annotation>
39513956
<Annotation Term="Org.OData.Capabilities.V1.SelectSupport">
39523957
<Record>
39533958
<PropertyValue Property="Supported" Bool="true"/>
@@ -5350,6 +5355,11 @@
53505355
<PropertyValue Property="Insertable" Bool="false"/>
53515356
</Record>
53525357
</Annotation>
5358+
<Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
5359+
<Record>
5360+
<PropertyValue Property="Referenceable" Bool="false"/>
5361+
</Record>
5362+
</Annotation>
53535363
<Annotation Term="Org.OData.Capabilities.V1.SelectSupport">
53545364
<Record>
53555365
<PropertyValue Property="Supported" Bool="false"/>
@@ -5401,6 +5411,11 @@
54015411
<PropertyValue Property="Insertable" Bool="false"/>
54025412
</Record>
54035413
</Annotation>
5414+
<Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
5415+
<Record>
5416+
<PropertyValue Property="Referenceable" Bool="false"/>
5417+
</Record>
5418+
</Annotation>
54045419
<Annotation Term="Org.OData.Capabilities.V1.SkipSupported" Bool="false"/>
54055420
<Annotation Term="Org.OData.Capabilities.V1.SortRestrictions">
54065421
<Record>
@@ -28342,6 +28357,9 @@ within the time frame of their original request."/>
2834228357
<Property Name="isSearchable" Type="Edm.Boolean"/>
2834328358
<Property Name="value" Type="Edm.String" Nullable="false"/>
2834428359
</ComplexType>
28360+
<ComplexType Name="fileStorageContainerSettings">
28361+
<Property Name="isOcrEnabled" Type="Edm.Boolean"/>
28362+
</ComplexType>
2834528363
<ComplexType Name="fileStorageContainerViewpoint">
2834628364
<Property Name="effectiveRole" Type="Edm.String" Nullable="false"/>
2834728365
</ComplexType>
@@ -28359,6 +28377,7 @@ within the time frame of their original request."/>
2835928377
<Property Name="customProperties" Type="graph.fileStorageContainerCustomPropertyDictionary"/>
2836028378
<Property Name="description" Type="Edm.String"/>
2836128379
<Property Name="displayName" Type="Edm.String" Nullable="false"/>
28380+
<Property Name="settings" Type="graph.fileStorageContainerSettings" Nullable="false"/>
2836228381
<Property Name="status" Type="graph.fileStorageContainerStatus"/>
2836328382
<Property Name="viewpoint" Type="graph.fileStorageContainerViewpoint"/>
2836428383
<NavigationProperty Name="drive" Type="graph.drive" ContainsTarget="true"/>
@@ -34260,6 +34279,8 @@ within the time frame of their original request."/>
3426034279
</ComplexType>
3426134280
<ComplexType Name="chatMessageReaction">
3426234281
<Property Name="createdDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
34282+
<Property Name="displayName" Type="Edm.String"/>
34283+
<Property Name="reactionContentUrl" Type="Edm.String"/>
3426334284
<Property Name="reactionType" Type="Edm.String" Nullable="false"/>
3426434285
<Property Name="user" Type="graph.chatMessageReactionIdentitySet" Nullable="false"/>
3426534286
</ComplexType>
@@ -35397,6 +35418,9 @@ within the time frame of their original request."/>
3539735418
<Action Name="instantiate" IsBound="true">
3539835419
<Parameter Name="bindingParameter" Type="graph.applicationTemplate"/>
3539935420
<Parameter Name="displayName" Type="Edm.String" Unicode="false"/>
35421+
<Parameter Name="serviceManagementReference" Type="Edm.String" Unicode="false">
35422+
<Annotation Term="Org.OData.Core.V1.OptionalParameter"/>
35423+
</Parameter>
3540035424
<ReturnType Type="graph.applicationServicePrincipal"/>
3540135425
</Action>
3540235426
<Action Name="setVerifiedPublisher" IsBound="true">
@@ -40705,8 +40729,8 @@ within the time frame of their original request."/>
4070540729
</EnumType>
4070640730
<EnumType Name="purgeType">
4070740731
<Member Name="recoverable" Value="0"/>
40708-
<Member Name="permanentlyDeleted" Value="1"/>
40709-
<Member Name="unknownFutureValue" Value="2"/>
40732+
<Member Name="unknownFutureValue" Value="1"/>
40733+
<Member Name="permanentlyDelete" Value="2"/>
4071040734
</EnumType>
4071140735
<EnumType Name="sourceType" IsFlags="true">
4071240736
<Member Name="mailbox" Value="1"/>

0 commit comments

Comments
 (0)