Skip to content

Commit a0abb43

Browse files
committed
bookingbusiness namespace updates, examples fixes for directory API
1 parent 66a578e commit a0abb43

File tree

9 files changed

+89
-40
lines changed

9 files changed

+89
-40
lines changed

examples/directory/applications/grant_application_perms.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@
1818
from tests import (
1919
test_admin_principal_name,
2020
test_client_id,
21+
test_client_secret,
2122
test_tenant,
2223
)
2324

24-
client = GraphClient.with_token_interactive(
25-
test_tenant, test_client_id, test_admin_principal_name
26-
)
25+
# client = GraphClient.with_token_interactive(
26+
# test_tenant, test_client_id, test_admin_principal_name
27+
# )
28+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2729

2830
# Step 1: Get the resource service principal
2931
resource = client.service_principals.get_by_name("Microsoft Graph")
3032

3133
# Step 2: Grant an app role to a client app
3234
app = client.applications.get_by_app_id(test_client_id)
33-
resource.grant_application_permissions(app, "MailboxSettings.Read").execute_query()
35+
resource.grant_application_permissions(app, "Bookings.Read.All").execute_query()
3436

3537

36-
# Step 3. Print app role assignments
38+
# Step 3 (optional). Print app role assignments
3739
result = resource.app_role_assigned_to.get_all().execute_query()
3840
for app_role_assignment in result:
3941
print(app_role_assignment)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
How to grant and revoke delegated permissions for an app using Microsoft Graph.
3+
Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API
4+
on behalf of a signed-in user.
5+
6+
7+
https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions
8+
"""
9+
10+
from office365.graph_client import GraphClient
11+
from tests import (
12+
test_client_id,
13+
test_client_secret,
14+
test_tenant,
15+
)
16+
17+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
18+
19+
20+
resource = client.service_principals.get_by_name("Microsoft Graph")
21+
app_role = "Bookings.Read.All"
22+
result = resource.get_application_permissions(test_client_id).execute_query()
23+
if (
24+
len([cur_app_role for cur_app_role in result.value if cur_app_role == app_role])
25+
== 0
26+
):
27+
print("Application permission '{0}' is not granted".format(app_role))
28+
else:
29+
print(result.value)
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Determines whether the delegated permissions is defined by the Microsoft Graph service principal in the tenant.
2+
Determines whether the delegated permissions is granted by the Microsoft Graph service principal in the tenant.
33
44
https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions
55
"""
@@ -8,26 +8,19 @@
88
from tests import (
99
test_admin_principal_name,
1010
test_client_id,
11+
test_client_secret,
1112
test_tenant,
1213
)
1314

14-
# client = GraphClient.with_username_and_password(
15-
# test_tenant, test_client_id, test_username, test_password
16-
# )
17-
client = GraphClient.with_token_interactive(
18-
test_tenant, test_client_id, test_admin_principal_name
19-
)
15+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2016

2117
resource = client.service_principals.get_by_name("Microsoft Graph")
22-
# app_role = "User.Read.All"
23-
app_role = "DeviceLocalCredential.Read.All"
18+
scope = "DeviceLocalCredential.Read.All"
2419
user = client.users.get_by_principal_name(test_admin_principal_name)
2520
client_app = client.applications.get_by_app_id(test_client_id)
26-
# result = resource.get_delegated(client_app, user, app_role).execute_query()
27-
result = resource.get_delegated_permissions(
28-
test_client_id, user, app_role
29-
).execute_query()
30-
if len(result) == 0:
31-
print("Delegated permission '{0}' is not set".format(app_role))
21+
# result = resource.get_delegated_permissions(test_client_id, user).execute_query()
22+
result = resource.get_delegated_permissions(test_client_id).execute_query()
23+
if len([cur_scope for cur_scope in result.value if cur_scope == scope]) == 0:
24+
print("Delegated permission '{0}' is not granted".format(scope))
3225
else:
3326
print(result.value)

examples/directory/applications/list_application_perms.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@
1414
test_tenant,
1515
)
1616

17-
# client = GraphClient.with_token_interactive(
18-
# test_tenant, test_client_id, test_admin_principal_name
19-
# )
20-
2117
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2218

2319

2420
resource = client.service_principals.get_by_name("Microsoft Graph")
25-
2621
result = resource.get_application_permissions(test_client_id).execute_query()
2722
for app_role in result.value:
2823
print(app_role)
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
How to grant and revoke delegated permissions for an app using Microsoft Graph.
2+
How to list delegated permissions for an app using Microsoft Graph.
33
Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API
44
on behalf of a signed-in user.
55
@@ -14,17 +14,11 @@
1414
test_tenant,
1515
)
1616

17-
# client = GraphClient.with_token_interactive(
18-
# test_tenant, test_client_id, test_admin_principal_name
19-
# )
20-
2117
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2218

2319

24-
resource = (
25-
client.service_principals.get_by_name("Microsoft Graph").get().execute_query()
26-
)
20+
resource = client.service_principals.get_by_name("Microsoft Graph")
2721
result = resource.get_delegated_permissions(test_client_id).execute_query()
2822

29-
for grant in result:
30-
print(grant.scope + ";")
23+
for scope in result.value:
24+
print(scope)

office365/booking/business/business.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def get_staff_availability(
4646
self.context.add_query(qry)
4747
return return_type
4848

49+
def publish(self):
50+
"""
51+
Make the scheduling page of a business available to external customers.
52+
53+
Set the isPublished property to true, and the publicUrl property to the URL of the scheduling page.
54+
"""
55+
qry = ServiceOperationQuery(
56+
self,
57+
"publish",
58+
)
59+
self.context.add_query(qry)
60+
return self
61+
4962
@property
5063
def address(self):
5164
"""
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from typing import Optional
2+
13
from office365.booking.business.business import BookingBusiness
24
from office365.entity_collection import EntityCollection
5+
from office365.outlook.mail.physical_address import PhysicalAddress
36

47

58
class BookingBusinessCollection(EntityCollection[BookingBusiness]):
@@ -10,12 +13,13 @@ def __init__(self, context, resource_path=None):
1013
context, BookingBusiness, resource_path
1114
)
1215

13-
def add(self, display_name):
16+
def add(self, display_name, address=None, email=None):
17+
# type: (str, Optional[PhysicalAddress], Optional[str]) -> BookingBusiness
1418
"""
1519
Create a new Microsoft Bookings business in a tenant.
1620
:param str display_name: The business display name.
21+
:param PhysicalAddress address: The business display name.
22+
:param str email: The email address for the business.
1723
"""
18-
props = {
19-
"displayName": display_name,
20-
}
24+
props = {"displayName": display_name, "address": address, "email": email}
2125
return super(BookingBusinessCollection, self).add(**props)

office365/sharepoint/lists/list.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
EventReceiverDefinitionCollection,
2222
)
2323
from office365.sharepoint.fields.collection import FieldCollection
24+
from office365.sharepoint.fields.field import Field
2425
from office365.sharepoint.fields.related_field_collection import RelatedFieldCollection
2526
from office365.sharepoint.files.checked_out_file_collection import (
2627
CheckedOutFileCollection,
@@ -212,6 +213,16 @@ def _list_loaded():
212213
self.ensure_property("RootFolder", _list_loaded)
213214
return return_type
214215

216+
def ensure_signoff_status_field(self):
217+
""""""
218+
return_type = Field(self.context)
219+
self.fields.add_child(return_type)
220+
qry = ServiceOperationQuery(
221+
self, "EnsureSignoffStatusField", None, None, None, return_type
222+
)
223+
self.context.add_query(qry)
224+
return return_type
225+
215226
def get_all_rules(self):
216227
"""Retrieves rules of a List"""
217228
return_type = ClientResult(self.context, ClientValueCollection(SPListRule))

tests/booking/test_business.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,13 @@ def test2_create_booking_business(self):
2020
# result = self.__class__.business.get_staff_availability().execute_query()
2121
# self.assertIsNotNone(result.resource_path)
2222

23-
def test4_delete_booking_business(self):
23+
def test3_get(self):
24+
result = self.__class__.business.get().execute_query()
25+
self.assertIsNotNone(result.resource_path)
26+
27+
def test4_publish(self):
28+
result = self.__class__.business.publish().execute_query()
29+
self.assertIsNotNone(result.resource_path)
30+
31+
def test5_delete_booking_business(self):
2432
self.__class__.business.delete_object().execute_query()

0 commit comments

Comments
 (0)