Skip to content

Commit e6a1329

Browse files
committed
support for advanced query capabilities
1 parent 03e5dac commit e6a1329

File tree

25 files changed

+272
-62
lines changed

25 files changed

+272
-62
lines changed

examples/directory/roles/for_user.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
client = GraphClient(tenant=test_tenant).with_username_and_password(
1111
test_client_id, test_username, test_password
1212
)
13-
result = client.me.member_of.get().execute_query()
14-
role_template_ids = [
15-
o.properties.get("roleTemplateId", None)
16-
for o in result
17-
if o.properties.get("roleTemplateId", None)
18-
]
19-
result = client.directory_roles.get().execute_query()
20-
for role in result:
21-
if role.properties.get("roleTemplateId", None) in role_template_ids:
22-
print(role)
13+
14+
directory_roles = client.directory_roles.get().execute_query()
15+
role_template_map = {
16+
role.properties.get("roleTemplateId"): role for role in directory_roles
17+
}
18+
19+
memberships = client.me.member_of.get().execute_query()
20+
user_roles = []
21+
for item in memberships:
22+
role_id = item.properties.get("roleTemplateId")
23+
if role_id and role_id in role_template_map:
24+
user_roles.append(role_template_map[role_id])
25+
26+
27+
# Print roles the user is assigned to
28+
for role in user_roles:
29+
print(f"User has role: {role.display_name}")

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="sharepoint",
29+
default="graph",
3030
)
3131
parser.add_argument(
3232
"-p",
3333
"--path",
3434
dest="path",
35-
default="./metadata/SharePoint.xml",
35+
default="./metadata/Graph.xml",
3636
help="Import metadata endpoint",
3737
)
3838

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class CallTranscript(Entity):
5+
"""Represents a transcript associated with an online meeting."""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class OnlineMeetingBase(Entity):
5+
"""Represents a base online meeting. The base type of onlineMeeting and virtualEventSession."""

office365/communications/onlinemeetings/online_meeting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from datetime import datetime
22
from typing import AnyStr, Optional
33

4+
from office365.communications.onlinemeetings.base import OnlineMeetingBase
45
from office365.communications.onlinemeetings.participants import MeetingParticipants
56
from office365.communications.onlinemeetings.recordings.call import CallRecording
6-
from office365.entity import Entity
77
from office365.entity_collection import EntityCollection
88
from office365.outlook.mail.item_body import ItemBody
99
from office365.runtime.client_result import ClientResult
@@ -12,7 +12,7 @@
1212
from office365.runtime.types.collections import StringCollection
1313

1414

15-
class OnlineMeeting(Entity):
15+
class OnlineMeeting(OnlineMeetingBase):
1616
"""
1717
Contains information about a meeting, including the URL used to join a meeting,
1818
the attendees list, and the description.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class VirtualEventPresenter(Entity):
5+
"""Represents information about a presenter of a virtual event."""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.communications.onlinemeetings.base import OnlineMeetingBase
2+
3+
4+
class VirtualEventSession(OnlineMeetingBase):
5+
"""Represents a session in a virtualEvent."""
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
1+
from typing import Optional
2+
3+
from office365.communications.virtualevents.presenter import VirtualEventPresenter
4+
from office365.communications.virtualevents.session import VirtualEventSession
15
from office365.entity import Entity
6+
from office365.entity_collection import EntityCollection
7+
from office365.outlook.mail.item_body import ItemBody
8+
from office365.runtime.paths.resource_path import ResourcePath
29

310

411
class VirtualEvent(Entity):
512
"""Represents an abstract base type for a virtual event.
613
Base type of virtualEventTownhall and virtualEventWebinar."""
14+
15+
@property
16+
def description(self):
17+
# type: () -> Optional[str]
18+
"""A description of the virtual event."""
19+
return self.properties.get("Description", ItemBody())
20+
21+
@property
22+
def presenters(self):
23+
"""The virtual event presenters."""
24+
return self.properties.get(
25+
"presenters",
26+
EntityCollection(
27+
self.context,
28+
VirtualEventPresenter,
29+
ResourcePath("presenters", self.resource_path),
30+
),
31+
)
32+
33+
@property
34+
def sessions(self):
35+
"""The virtual event presenters."""
36+
return self.properties.get(
37+
"sessions",
38+
EntityCollection(
39+
self.context,
40+
VirtualEventSession,
41+
ResourcePath("sessions", self.resource_path),
42+
),
43+
)

office365/copilot/root.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from office365.copilot.admin import CopilotAdmin
22
from office365.runtime.paths.resource_path import ResourcePath
33
from office365.sharepoint.entity import Entity
4+
from office365.teams.aiinteractions.history import AIInteractionHistory
45

56

67
class CopilotRoot(Entity):
@@ -13,3 +14,13 @@ def admin(self):
1314
"admin",
1415
CopilotAdmin(self.context, ResourcePath("admin", self.resource_path)),
1516
)
17+
18+
@property
19+
def interaction_history(self):
20+
"""The history of interactions between AI agents and users."""
21+
return self.properties.get(
22+
"interactionHistory",
23+
AIInteractionHistory(
24+
self.context, ResourcePath("interactionHistory", self.resource_path)
25+
),
26+
)

office365/count_collection.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from office365.delta_collection import DeltaCollection
2+
from office365.runtime.client_object import T
3+
from office365.runtime.client_result import ClientResult
4+
from office365.runtime.http.request_options import RequestOptions
5+
from office365.runtime.queries.function import FunctionQuery
6+
7+
8+
class CountCollection(DeltaCollection[T]):
9+
"""Collection with support for OData $count operation"""
10+
11+
def count(self):
12+
# type: () -> ClientResult[int]
13+
"""Executes a $count query to get the number of items in the collection"""
14+
return_type = ClientResult(self.context, int())
15+
16+
def _construct_request(request):
17+
# type: (RequestOptions) -> None
18+
request.headers.pop("Accept", None)
19+
request.ensure_header("ConsistencyLevel", "eventual")
20+
21+
qry = FunctionQuery(self, "$count", None, return_type)
22+
self.context.add_query(qry).before_execute(_construct_request)
23+
return return_type

0 commit comments

Comments
 (0)