Skip to content

Commit

Permalink
bug fixes & typings updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Feb 16, 2024
1 parent a914924 commit 6a16c8f
Show file tree
Hide file tree
Showing 44 changed files with 473 additions and 197 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ The list of examples:

- Working with lists and list items
- [create a list item](examples/sharepoint/lists/data_generator.py)
- [read a list item](examples/sharepoint/lists/read_large.py)
- [read a list item](examples/sharepoint/lists/read_paged.py)
- [update a list item](examples/sharepoint/listitems/update_batch.py)
- [delete a list item](examples/sharepoint/listitems/delete.py)

Expand Down
10 changes: 7 additions & 3 deletions examples/directory/applications/grant_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@


# select specific appRole
names = ["Directory.AccessAsUser.All", "ThreatHunting.Read.All"]
app_role = resource.app_roles["Directory.AccessAsUser.All"]
names = [
"Directory.AccessAsUser.All",
"ThreatHunting.Read.All",
"UserAuthenticationMethod.Read.All",
]
app_role = resource.app_roles["Policy.Read.All"]

# Step 2: Grant an app role to a client app
app = client.applications.get_by_app_id(test_client_id)
resource.grant(app, app_role).execute_query()
# resource.grant(app, app_role).execute_query()


# Step 3. Print app role assignments
Expand Down
16 changes: 16 additions & 0 deletions examples/onedrive/files/get_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
List sharing permissions on a driveItem
https://learn.microsoft.com/en-us/graph/api/driveitem-list-permissions?view=graph-rest-1.0
"""

from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
file_path = "Archive/Financial Sample.xlsx"
file_item = client.me.drive.root.get_by_path(file_path)
permissions = file_item.permissions.get().execute_query()
print(permissions)
95 changes: 95 additions & 0 deletions examples/sharepoint/connect.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 31,
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-02-11T10:23:26.221156714Z",
"start_time": "2024-02-11T10:23:26.197964378Z"
}
},
"outputs": [],
"source": [
"from office365.sharepoint.client_context import ClientContext\n",
"client_id = \"4b7eb3df-afc3-4b7d-ae1d-629f22a3fe42\" \n",
"site_url = \"https://mediadev8.sharepoint.com\"\n",
"tenant_name = \"mediadev8.onmicrosoft.com\""
]
},
{
"cell_type": "code",
"outputs": [],
"source": [
"ctx = ClientContext(site_url).with_interactive(tenant_name, client_id)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-02-11T10:23:27.733534468Z",
"start_time": "2024-02-11T10:23:27.725507872Z"
}
},
"id": "b5504d6537baaebd",
"execution_count": 32
},
{
"cell_type": "code",
"outputs": [
{
"data": {
"text/plain": "[email protected]"
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"me = ctx.web.current_user.get().execute_query()\n",
"me"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-02-11T10:23:36.770634654Z",
"start_time": "2024-02-11T10:23:36.520379564Z"
}
},
"id": "e61a0947e8ef00d5",
"execution_count": 34
},
{
"cell_type": "code",
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
},
"id": "403e49d95b83b674"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests import test_team_site_url, test_user_credentials


def generate_documents(context, amount):
def run(context, amount):
"""
:type context: ClientContext
:type amount: int
Expand Down Expand Up @@ -36,38 +36,6 @@ def generate_documents(context, amount):
print("File '{0}' has been uploaded".format(target_file.serverRelativeUrl))


def generate_contacts(context, amount):
"""
:type context: ClientContext
:type amount: int
"""
contacts_list = context.web.lists.get_by_title("Contacts_Large")

fake = Faker()
for idx in range(0, amount):
contact_properties = {
"Title": fake.name(),
"FullName": fake.name(),
"Email": fake.email(),
"Company": fake.company(),
"WorkPhone": fake.phone_number(),
"WorkAddress": fake.street_address(),
"WorkCity": fake.city(),
"WorkZip": fake.postcode(),
"WorkCountry": fake.country(),
"WebPage": {"Url": fake.url()},
}
# contact_item = contacts_list.add_item(contact_properties).execute_query()
contact_item = contacts_list.add_item(contact_properties)
print(
"({0} of {1}) Contact '{2}' has been created".format(
idx, amount, contact_item.properties["Title"]
)
)
ctx.execute_batch()


if __name__ == "__main__":
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
# generate_contacts(ctx, 5000)
generate_documents(ctx, 100)
run(ctx, 100)
49 changes: 49 additions & 0 deletions examples/sharepoint/import/import_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from faker import Faker

from office365.sharepoint.client_context import ClientContext
from tests import test_team_site_url, test_user_credentials


def print_progress(items_count):
print("{0} list items has been created".format(items_count))


def load_data_source(amount=1000):
fake = Faker()
contacts = []
for idx in range(0, amount):
contact = {
"Title": fake.name(),
"FullName": fake.name(),
"Email": fake.email(),
"Company": fake.company(),
"WorkPhone": fake.phone_number(),
"WorkAddress": fake.street_address(),
"WorkCity": fake.city(),
"WorkZip": fake.postcode(),
"WorkCountry": fake.country()
# "WebPage": {"Url": fake.url()},
}
contacts.append(contact)

return contacts


def run(context):
# type: (ClientContext) -> None
contacts_data = load_data_source()
contacts_list = context.web.lists.get_by_title("Contacts_Large")
for idx, contact in enumerate(contacts_data):
# contact_item = contacts_list.add_item(contact).execute_query()
contacts_list.add_item(contact)
# print(
# "({0} of {1}) Contact '{2}' has been created".format(
# idx, len(contacts_data), contact_item.properties["Title"]
# )
# )
ctx.execute_batch(items_per_batch=2, success_callback=print_progress)


if __name__ == "__main__":
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
run(ctx)
15 changes: 8 additions & 7 deletions examples/sharepoint/lists/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
This example deletes a SharePoint all the list items.
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.listitem import ListItem
from tests import test_client_credentials, test_team_site_url


def print_progress(items_count):
print("List items count: {0}".format(target_list.item_count))


ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
target_list = ctx.web.lists.get_by_title("Tasks")
items = target_list.items.get().execute_query()
for item in items: # type: ListItem
item.delete_object()
ctx.execute_batch()
print("Items deleted count: {0}".format(len(items)))
target_list = ctx.web.lists.get_by_title("Contacts_Large")
target_list.clear().get().execute_batch()
print("List items count: {0}".format(target_list.item_count))
19 changes: 19 additions & 0 deletions examples/sharepoint/lists/read_paged.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.collection import ListItemCollection
from office365.sharepoint.listitems.listitem import ListItem
from tests import test_client_credentials, test_team_site_url


def print_progress(items):
# type: (ListItemCollection) -> None
print("Items read: {0}".format(len(items)))


ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
large_list = ctx.web.lists.get_by_title("Contacts_Large")
paged_items = (
large_list.items.paged(5000, page_loaded=print_progress).get().execute_query()
)
for index, item in enumerate(paged_items): # type: int, ListItem
pass
# print("{0}: {1}".format(index, item.id))
2 changes: 2 additions & 0 deletions examples/sharepoint/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
pandas
29 changes: 29 additions & 0 deletions generator/metadata/MicrosoftGraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20587,6 +20587,7 @@
<Property Name="spa" Type="graph.spaApplication"/>
<Property Name="tags" Type="Collection(Edm.String)" Nullable="false"/>
<Property Name="tokenEncryptionKeyId" Type="Edm.Guid"/>
<Property Name="uniqueName" Type="Edm.String"/>
<Property Name="verifiedPublisher" Type="graph.verifiedPublisher"/>
<Property Name="web" Type="graph.webApplication"/>
<NavigationProperty Name="appManagementPolicies" Type="Collection(graph.appManagementPolicy)"/>
Expand All @@ -20610,6 +20611,16 @@
</Collection>
</PropertyValue>
</Record>
<Record Type="Org.OData.Core.V1.AlternateKey">
<PropertyValue Property="Key">
<Collection>
<Record Type="Org.OData.Core.V1.PropertyRef">
<PropertyValue Property="Alias" String="uniqueName"/>
<PropertyValue Property="Name" PropertyPath="uniqueName"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</EntityType>
Expand Down Expand Up @@ -23303,6 +23314,7 @@
<Property Name="securityIdentifier" Type="Edm.String"/>
<Property Name="serviceProvisioningErrors" Type="Collection(graph.serviceProvisioningError)"/>
<Property Name="theme" Type="Edm.String"/>
<Property Name="uniqueName" Type="Edm.String"/>
<Property Name="visibility" Type="Edm.String"/>
<Property Name="allowExternalSenders" Type="Edm.Boolean"/>
<Property Name="autoSubscribeNewMembers" Type="Edm.Boolean"/>
Expand Down Expand Up @@ -23338,6 +23350,20 @@
<NavigationProperty Name="photo" Type="graph.profilePhoto" ContainsTarget="true"/>
<NavigationProperty Name="photos" Type="Collection(graph.profilePhoto)" ContainsTarget="true"/>
<NavigationProperty Name="team" Type="graph.team" ContainsTarget="true"/>
<Annotation Term="Org.OData.Core.V1.AlternateKeys">
<Collection>
<Record Type="Org.OData.Core.V1.AlternateKey">
<PropertyValue Property="Key">
<Collection>
<Record Type="Org.OData.Core.V1.PropertyRef">
<PropertyValue Property="Alias" String="uniqueName"/>
<PropertyValue Property="Name" PropertyPath="uniqueName"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</EntityType>
<EntityType Name="teamsAppInstallation" BaseType="graph.entity">
<Property Name="consentedPermissionSet" Type="graph.teamsAppPermissionSet"/>
Expand Down Expand Up @@ -26287,6 +26313,7 @@
<EntityType Name="attributeMappingFunctionSchema" BaseType="graph.entity">
<Property Name="parameters" Type="Collection(graph.attributeMappingParameterSchema)"/>
</EntityType>
<EntityType Name="bulkUpload" BaseType="graph.entity" HasStream="true"/>
<EntityType Name="directoryDefinition" BaseType="graph.entity">
<Property Name="discoverabilities" Type="graph.directoryDefinitionDiscoverabilities" Nullable="false"/>
<Property Name="discoveryDateTime" Type="Edm.DateTimeOffset"/>
Expand All @@ -26305,6 +26332,7 @@
<Property Name="status" Type="graph.synchronizationStatus"/>
<Property Name="synchronizationJobSettings" Type="Collection(graph.keyValuePair)"/>
<Property Name="templateId" Type="Edm.String"/>
<NavigationProperty Name="bulkUpload" Type="graph.bulkUpload" ContainsTarget="true"/>
<NavigationProperty Name="schema" Type="graph.synchronizationSchema" ContainsTarget="true"/>
</EntityType>
<EntityType Name="synchronizationTemplate" BaseType="graph.entity">
Expand Down Expand Up @@ -26618,6 +26646,7 @@
<NavigationProperty Name="internalSponsors" Type="Collection(graph.directoryObject)" ContainsTarget="true"/>
</EntityType>
<EntityType Name="accessPackageResourceEnvironment" BaseType="graph.entity">
<Property Name="connectionInfo" Type="graph.connectionInfo"/>
<Property Name="createdDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="description" Type="Edm.String"/>
<Property Name="displayName" Type="Edm.String"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from office365.entity_collection import EntityCollection


class AppRoleAssignmentCollection(EntityCollection):
class AppRoleAssignmentCollection(EntityCollection[AppRoleAssignment]):
def __init__(self, context, resource_path=None):
super(AppRoleAssignmentCollection, self).__init__(
context, AppRoleAssignment, resource_path
Expand Down
4 changes: 2 additions & 2 deletions office365/directory/applications/roles/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class AppRoleCollection(ClientValueCollection[AppRole]):
def __init__(self, initial_values=None):
super(AppRoleCollection, self).__init__(AppRole, initial_values)

def __getitem__(self, name):
def __getitem__(self, key):
# type: (str) -> AppRole
return next(iter([item for item in self._data if item.value == name]), None)
return next(iter([item for item in self._data if item.value == key]), None)
8 changes: 8 additions & 0 deletions office365/directory/authentication/method_mode_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from office365.entity import Entity


class AuthenticationMethodModeDetail(Entity):
"""
The details of the authenticationMethodModes objects that can be defined for the allowedCombinations property
of the authenticationstrengthpolicy.
"""
5 changes: 5 additions & 0 deletions office365/directory/authentication/method_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class AuthenticationMethodTarget(Entity):
""""""
Loading

0 comments on commit 6a16c8f

Please sign in to comment.