Skip to content

Commit 6a16c8f

Browse files
committed
bug fixes & typings updates
1 parent a914924 commit 6a16c8f

File tree

44 files changed

+473
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+473
-197
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ The list of examples:
168168

169169
- Working with lists and list items
170170
- [create a list item](examples/sharepoint/lists/data_generator.py)
171-
- [read a list item](examples/sharepoint/lists/read_large.py)
171+
- [read a list item](examples/sharepoint/lists/read_paged.py)
172172
- [update a list item](examples/sharepoint/listitems/update_batch.py)
173173
- [delete a list item](examples/sharepoint/listitems/delete.py)
174174

examples/directory/applications/grant_perms.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@
3535

3636

3737
# select specific appRole
38-
names = ["Directory.AccessAsUser.All", "ThreatHunting.Read.All"]
39-
app_role = resource.app_roles["Directory.AccessAsUser.All"]
38+
names = [
39+
"Directory.AccessAsUser.All",
40+
"ThreatHunting.Read.All",
41+
"UserAuthenticationMethod.Read.All",
42+
]
43+
app_role = resource.app_roles["Policy.Read.All"]
4044

4145
# Step 2: Grant an app role to a client app
4246
app = client.applications.get_by_app_id(test_client_id)
43-
resource.grant(app, app_role).execute_query()
47+
# resource.grant(app, app_role).execute_query()
4448

4549

4650
# Step 3. Print app role assignments
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
List sharing permissions on a driveItem
3+
4+
https://learn.microsoft.com/en-us/graph/api/driveitem-list-permissions?view=graph-rest-1.0
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+
file_path = "Archive/Financial Sample.xlsx"
14+
file_item = client.me.drive.root.get_by_path(file_path)
15+
permissions = file_item.permissions.get().execute_query()
16+
print(permissions)

examples/sharepoint/connect.ipynb

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 31,
6+
"id": "initial_id",
7+
"metadata": {
8+
"collapsed": true,
9+
"ExecuteTime": {
10+
"end_time": "2024-02-11T10:23:26.221156714Z",
11+
"start_time": "2024-02-11T10:23:26.197964378Z"
12+
}
13+
},
14+
"outputs": [],
15+
"source": [
16+
"from office365.sharepoint.client_context import ClientContext\n",
17+
"client_id = \"4b7eb3df-afc3-4b7d-ae1d-629f22a3fe42\" \n",
18+
"site_url = \"https://mediadev8.sharepoint.com\"\n",
19+
"tenant_name = \"mediadev8.onmicrosoft.com\""
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"outputs": [],
25+
"source": [
26+
"ctx = ClientContext(site_url).with_interactive(tenant_name, client_id)"
27+
],
28+
"metadata": {
29+
"collapsed": false,
30+
"ExecuteTime": {
31+
"end_time": "2024-02-11T10:23:27.733534468Z",
32+
"start_time": "2024-02-11T10:23:27.725507872Z"
33+
}
34+
},
35+
"id": "b5504d6537baaebd",
36+
"execution_count": 32
37+
},
38+
{
39+
"cell_type": "code",
40+
"outputs": [
41+
{
42+
"data": {
43+
"text/plain": "[email protected]"
44+
},
45+
"execution_count": 34,
46+
"metadata": {},
47+
"output_type": "execute_result"
48+
}
49+
],
50+
"source": [
51+
"me = ctx.web.current_user.get().execute_query()\n",
52+
"me"
53+
],
54+
"metadata": {
55+
"collapsed": false,
56+
"ExecuteTime": {
57+
"end_time": "2024-02-11T10:23:36.770634654Z",
58+
"start_time": "2024-02-11T10:23:36.520379564Z"
59+
}
60+
},
61+
"id": "e61a0947e8ef00d5",
62+
"execution_count": 34
63+
},
64+
{
65+
"cell_type": "code",
66+
"outputs": [],
67+
"source": [],
68+
"metadata": {
69+
"collapsed": false
70+
},
71+
"id": "403e49d95b83b674"
72+
}
73+
],
74+
"metadata": {
75+
"kernelspec": {
76+
"display_name": "Python 3",
77+
"language": "python",
78+
"name": "python3"
79+
},
80+
"language_info": {
81+
"codemirror_mode": {
82+
"name": "ipython",
83+
"version": 2
84+
},
85+
"file_extension": ".py",
86+
"mimetype": "text/x-python",
87+
"name": "python",
88+
"nbconvert_exporter": "python",
89+
"pygments_lexer": "ipython2",
90+
"version": "2.7.6"
91+
}
92+
},
93+
"nbformat": 4,
94+
"nbformat_minor": 5
95+
}

examples/sharepoint/lists/custom/data_generator.py renamed to examples/sharepoint/import/import_lib.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from tests import test_team_site_url, test_user_credentials
77

88

9-
def generate_documents(context, amount):
9+
def run(context, amount):
1010
"""
1111
:type context: ClientContext
1212
:type amount: int
@@ -36,38 +36,6 @@ def generate_documents(context, amount):
3636
print("File '{0}' has been uploaded".format(target_file.serverRelativeUrl))
3737

3838

39-
def generate_contacts(context, amount):
40-
"""
41-
:type context: ClientContext
42-
:type amount: int
43-
"""
44-
contacts_list = context.web.lists.get_by_title("Contacts_Large")
45-
46-
fake = Faker()
47-
for idx in range(0, amount):
48-
contact_properties = {
49-
"Title": fake.name(),
50-
"FullName": fake.name(),
51-
"Email": fake.email(),
52-
"Company": fake.company(),
53-
"WorkPhone": fake.phone_number(),
54-
"WorkAddress": fake.street_address(),
55-
"WorkCity": fake.city(),
56-
"WorkZip": fake.postcode(),
57-
"WorkCountry": fake.country(),
58-
"WebPage": {"Url": fake.url()},
59-
}
60-
# contact_item = contacts_list.add_item(contact_properties).execute_query()
61-
contact_item = contacts_list.add_item(contact_properties)
62-
print(
63-
"({0} of {1}) Contact '{2}' has been created".format(
64-
idx, amount, contact_item.properties["Title"]
65-
)
66-
)
67-
ctx.execute_batch()
68-
69-
7039
if __name__ == "__main__":
7140
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
72-
# generate_contacts(ctx, 5000)
73-
generate_documents(ctx, 100)
41+
run(ctx, 100)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from faker import Faker
2+
3+
from office365.sharepoint.client_context import ClientContext
4+
from tests import test_team_site_url, test_user_credentials
5+
6+
7+
def print_progress(items_count):
8+
print("{0} list items has been created".format(items_count))
9+
10+
11+
def load_data_source(amount=1000):
12+
fake = Faker()
13+
contacts = []
14+
for idx in range(0, amount):
15+
contact = {
16+
"Title": fake.name(),
17+
"FullName": fake.name(),
18+
"Email": fake.email(),
19+
"Company": fake.company(),
20+
"WorkPhone": fake.phone_number(),
21+
"WorkAddress": fake.street_address(),
22+
"WorkCity": fake.city(),
23+
"WorkZip": fake.postcode(),
24+
"WorkCountry": fake.country()
25+
# "WebPage": {"Url": fake.url()},
26+
}
27+
contacts.append(contact)
28+
29+
return contacts
30+
31+
32+
def run(context):
33+
# type: (ClientContext) -> None
34+
contacts_data = load_data_source()
35+
contacts_list = context.web.lists.get_by_title("Contacts_Large")
36+
for idx, contact in enumerate(contacts_data):
37+
# contact_item = contacts_list.add_item(contact).execute_query()
38+
contacts_list.add_item(contact)
39+
# print(
40+
# "({0} of {1}) Contact '{2}' has been created".format(
41+
# idx, len(contacts_data), contact_item.properties["Title"]
42+
# )
43+
# )
44+
ctx.execute_batch(items_per_batch=2, success_callback=print_progress)
45+
46+
47+
if __name__ == "__main__":
48+
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
49+
run(ctx)

examples/sharepoint/lists/clear.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
This example deletes a SharePoint all the list items.
33
"""
44
from office365.sharepoint.client_context import ClientContext
5-
from office365.sharepoint.listitems.listitem import ListItem
65
from tests import test_client_credentials, test_team_site_url
76

7+
8+
def print_progress(items_count):
9+
print("List items count: {0}".format(target_list.item_count))
10+
11+
812
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
9-
target_list = ctx.web.lists.get_by_title("Tasks")
10-
items = target_list.items.get().execute_query()
11-
for item in items: # type: ListItem
12-
item.delete_object()
13-
ctx.execute_batch()
14-
print("Items deleted count: {0}".format(len(items)))
13+
target_list = ctx.web.lists.get_by_title("Contacts_Large")
14+
target_list.clear().get().execute_batch()
15+
print("List items count: {0}".format(target_list.item_count))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from office365.sharepoint.client_context import ClientContext
2+
from office365.sharepoint.listitems.collection import ListItemCollection
3+
from office365.sharepoint.listitems.listitem import ListItem
4+
from tests import test_client_credentials, test_team_site_url
5+
6+
7+
def print_progress(items):
8+
# type: (ListItemCollection) -> None
9+
print("Items read: {0}".format(len(items)))
10+
11+
12+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
13+
large_list = ctx.web.lists.get_by_title("Contacts_Large")
14+
paged_items = (
15+
large_list.items.paged(5000, page_loaded=print_progress).get().execute_query()
16+
)
17+
for index, item in enumerate(paged_items): # type: int, ListItem
18+
pass
19+
# print("{0}: {1}".format(index, item.id))

examples/sharepoint/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy
2+
pandas

generator/metadata/MicrosoftGraph.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20587,6 +20587,7 @@
2058720587
<Property Name="spa" Type="graph.spaApplication"/>
2058820588
<Property Name="tags" Type="Collection(Edm.String)" Nullable="false"/>
2058920589
<Property Name="tokenEncryptionKeyId" Type="Edm.Guid"/>
20590+
<Property Name="uniqueName" Type="Edm.String"/>
2059020591
<Property Name="verifiedPublisher" Type="graph.verifiedPublisher"/>
2059120592
<Property Name="web" Type="graph.webApplication"/>
2059220593
<NavigationProperty Name="appManagementPolicies" Type="Collection(graph.appManagementPolicy)"/>
@@ -20610,6 +20611,16 @@
2061020611
</Collection>
2061120612
</PropertyValue>
2061220613
</Record>
20614+
<Record Type="Org.OData.Core.V1.AlternateKey">
20615+
<PropertyValue Property="Key">
20616+
<Collection>
20617+
<Record Type="Org.OData.Core.V1.PropertyRef">
20618+
<PropertyValue Property="Alias" String="uniqueName"/>
20619+
<PropertyValue Property="Name" PropertyPath="uniqueName"/>
20620+
</Record>
20621+
</Collection>
20622+
</PropertyValue>
20623+
</Record>
2061320624
</Collection>
2061420625
</Annotation>
2061520626
</EntityType>
@@ -23303,6 +23314,7 @@
2330323314
<Property Name="securityIdentifier" Type="Edm.String"/>
2330423315
<Property Name="serviceProvisioningErrors" Type="Collection(graph.serviceProvisioningError)"/>
2330523316
<Property Name="theme" Type="Edm.String"/>
23317+
<Property Name="uniqueName" Type="Edm.String"/>
2330623318
<Property Name="visibility" Type="Edm.String"/>
2330723319
<Property Name="allowExternalSenders" Type="Edm.Boolean"/>
2330823320
<Property Name="autoSubscribeNewMembers" Type="Edm.Boolean"/>
@@ -23338,6 +23350,20 @@
2333823350
<NavigationProperty Name="photo" Type="graph.profilePhoto" ContainsTarget="true"/>
2333923351
<NavigationProperty Name="photos" Type="Collection(graph.profilePhoto)" ContainsTarget="true"/>
2334023352
<NavigationProperty Name="team" Type="graph.team" ContainsTarget="true"/>
23353+
<Annotation Term="Org.OData.Core.V1.AlternateKeys">
23354+
<Collection>
23355+
<Record Type="Org.OData.Core.V1.AlternateKey">
23356+
<PropertyValue Property="Key">
23357+
<Collection>
23358+
<Record Type="Org.OData.Core.V1.PropertyRef">
23359+
<PropertyValue Property="Alias" String="uniqueName"/>
23360+
<PropertyValue Property="Name" PropertyPath="uniqueName"/>
23361+
</Record>
23362+
</Collection>
23363+
</PropertyValue>
23364+
</Record>
23365+
</Collection>
23366+
</Annotation>
2334123367
</EntityType>
2334223368
<EntityType Name="teamsAppInstallation" BaseType="graph.entity">
2334323369
<Property Name="consentedPermissionSet" Type="graph.teamsAppPermissionSet"/>
@@ -26287,6 +26313,7 @@
2628726313
<EntityType Name="attributeMappingFunctionSchema" BaseType="graph.entity">
2628826314
<Property Name="parameters" Type="Collection(graph.attributeMappingParameterSchema)"/>
2628926315
</EntityType>
26316+
<EntityType Name="bulkUpload" BaseType="graph.entity" HasStream="true"/>
2629026317
<EntityType Name="directoryDefinition" BaseType="graph.entity">
2629126318
<Property Name="discoverabilities" Type="graph.directoryDefinitionDiscoverabilities" Nullable="false"/>
2629226319
<Property Name="discoveryDateTime" Type="Edm.DateTimeOffset"/>
@@ -26305,6 +26332,7 @@
2630526332
<Property Name="status" Type="graph.synchronizationStatus"/>
2630626333
<Property Name="synchronizationJobSettings" Type="Collection(graph.keyValuePair)"/>
2630726334
<Property Name="templateId" Type="Edm.String"/>
26335+
<NavigationProperty Name="bulkUpload" Type="graph.bulkUpload" ContainsTarget="true"/>
2630826336
<NavigationProperty Name="schema" Type="graph.synchronizationSchema" ContainsTarget="true"/>
2630926337
</EntityType>
2631026338
<EntityType Name="synchronizationTemplate" BaseType="graph.entity">
@@ -26618,6 +26646,7 @@
2661826646
<NavigationProperty Name="internalSponsors" Type="Collection(graph.directoryObject)" ContainsTarget="true"/>
2661926647
</EntityType>
2662026648
<EntityType Name="accessPackageResourceEnvironment" BaseType="graph.entity">
26649+
<Property Name="connectionInfo" Type="graph.connectionInfo"/>
2662126650
<Property Name="createdDateTime" Type="Edm.DateTimeOffset"/>
2662226651
<Property Name="description" Type="Edm.String"/>
2662326652
<Property Name="displayName" Type="Edm.String"/>

0 commit comments

Comments
 (0)