Skip to content

Commit 190e9dd

Browse files
Refactorings & improvements (fluent interface for ClientResult, crud operations moved to base entity classes), bug fixes
1 parent 48eebbf commit 190e9dd

File tree

87 files changed

+345
-386
lines changed

Some content is hidden

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

87 files changed

+345
-386
lines changed

examples/directory/delete_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
print("Group deleted.")
1414
index += 1
1515

16-
deleted_groups = client.directory.deletedGroups.get().execute_query()
16+
deleted_groups = client.directory.deleted_groups.get().execute_query()
1717
groups_count = len(deleted_groups)
1818
index = 0
1919
while len(deleted_groups) > 0:

office365/actions/download_content_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(self, entity_type, format_name=None):
99
:type entity_type: office365.runtime.client_object.ClientObject
1010
:type format_name: str or None
1111
"""
12-
result = ClientResult(None)
12+
result = ClientResult(entity_type.context)
1313
action_name = "content"
1414
if format_name is not None:
1515
action_name = action_name + r"?format={0}".format(format_name)

office365/directory/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def delete_object(self, permanent_delete=False):
3737
"""
3838
super(Application, self).delete_object()
3939
if permanent_delete:
40-
deleted_item = self.context.directory.deletedApplications[self.id]
40+
deleted_item = self.context.directory.deleted_applications[self.id]
4141
deleted_item.delete_object()
4242
return self
4343

office365/directory/directory.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ class Directory(Entity):
88
"container". Deleted items will remain available to restore for up to 30 days. After 30 days, the items are
99
permanently deleted. """
1010

11-
def deletedItems(self, entity_type=None):
11+
def deleted_items(self, entity_type=None):
1212
"""Recently deleted items. Read-only. Nullable."""
1313
if entity_type:
14-
return DirectoryObjectCollection(self.context, ResourcePath(entity_type,
15-
ResourcePath("deletedItems",
16-
self.resource_path)))
14+
return DirectoryObjectCollection(self.context,
15+
ResourcePath(entity_type,
16+
ResourcePath("deletedItems", self.resource_path)))
1717
else:
1818
return self.properties.get('deletedItems',
1919
DirectoryObjectCollection(self.context,
2020
ResourcePath("deletedItems", self.resource_path)))
2121

2222
@property
23-
def deletedGroups(self):
23+
def deleted_groups(self):
2424
"""Recently deleted groups"""
25-
return self.deletedItems("microsoft.graph.group")
25+
return self.deleted_items("microsoft.graph.group")
2626

2727
@property
28-
def deletedUsers(self):
28+
def deleted_users(self):
2929
"""Recently deleted users"""
30-
return self.deletedItems("microsoft.graph.user")
30+
return self.deleted_items("microsoft.graph.user")
3131

3232
@property
33-
def deletedApplications(self):
33+
def deleted_applications(self):
3434
"""Recently deleted applications"""
35-
return self.deletedItems("microsoft.graph.application")
35+
return self.deleted_items("microsoft.graph.application")

office365/directory/directoryObject.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from office365.entity import Entity
22
from office365.runtime.client_result import ClientResult
3+
from office365.runtime.client_value_collection import ClientValueCollection
34
from office365.runtime.queries.service_operation_query import ServiceOperationQuery
45

56

@@ -12,7 +13,7 @@ def get_member_objects(self, security_enabled_only=True):
1213
This function is transitive.
1314
1415
:type security_enabled_only: bool"""
15-
result = ClientResult(None)
16+
result = ClientResult(self.context, ClientValueCollection(str))
1617
payload = {
1718
"securityEnabledOnly": security_enabled_only
1819
}
@@ -25,7 +26,7 @@ def get_member_groups(self, security_enabled_only=True):
2526
transitive.
2627
2728
:type security_enabled_only: bool"""
28-
result = ClientResult(None)
29+
result = ClientResult(self.context)
2930
payload = {
3031
"securityEnabledOnly": security_enabled_only
3132
}

office365/directory/directoryObjectCollection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __getitem__(self, key):
2626

2727
def getByIds(self, ids):
2828
"""Returns the directory objects specified in a list of IDs."""
29-
result = ClientResult(None)
29+
result = ClientResult(self.context)
3030
qry = ServiceOperationQuery(self, "getByIds", None, None, None, result)
3131
self.context.add_query(qry)
3232
return result

office365/directory/group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check_member_groups(self, group_ids):
4242
4343
:type group_ids: list
4444
"""
45-
result = ClientResult(None)
45+
result = ClientResult(self.context)
4646
qry = ServiceOperationQuery(self, "checkMemberGroups", None, group_ids, None, result)
4747
self.context.add_query(qry)
4848
return result
@@ -72,7 +72,7 @@ def delete_object(self, permanent_delete=False):
7272
"""
7373
super(Group, self).delete_object()
7474
if permanent_delete:
75-
deleted_item = self.context.directory.deletedGroups[self.id]
75+
deleted_item = self.context.directory.deleted_groups[self.id]
7676
deleted_item.delete_object()
7777
return self
7878

@@ -106,7 +106,7 @@ def events(self):
106106
return self.properties.get('events', EventCollection(self.context, ResourcePath("events", self.resource_path)))
107107

108108
@property
109-
def appRoleAssignments(self):
109+
def app_role_assignments(self):
110110
"""Get an event collection or an appRoleAssignments."""
111111
return self.properties.get('appRoleAssignments',
112112
AppRoleAssignmentCollection(self.context,

office365/directory/permission.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,13 @@
88
class Permission(Entity):
99
"""The Permission resource provides information about a sharing permission granted for a DriveItem resource."""
1010

11-
def update(self):
12-
"""Updates the Permission entity."""
13-
qry = UpdateEntityQuery(self)
14-
self.context.add_query(qry)
15-
return self
16-
17-
def delete_object(self):
18-
"""Deletes the Permission entity."""
19-
qry = DeleteEntityQuery(self)
20-
self.context.add_query(qry)
21-
self.remove_from_parent_collection()
22-
return self
23-
2411
@property
2512
def invitation(self):
2613
"""For user type permissions, the details of the users & applications for this permission."""
2714
return self.properties.get('invitation', SharingInvitation())
2815

2916
@property
30-
def grantedTo(self):
17+
def granted_to(self):
3118
"""For user type permissions, the details of the users & applications for this permission."""
3219
return self.properties.get('grantedTo', IdentitySet())
3320

@@ -37,15 +24,15 @@ def roles(self):
3724
return self.properties.get('roles', [])
3825

3926
@property
40-
def shareId(self):
27+
def share_id(self):
4128
"""A unique token that can be used to access this shared item via the shares API. Read-only.
4229
4330
:rtype: str
4431
"""
4532
return self.properties.get('shareId', None)
4633

4734
@property
48-
def hasPassword(self):
35+
def has_password(self):
4936
"""This indicates whether password is set for this permission, it's only showing in response.
5037
Optional and Read-only and for OneDrive Personal only.
5138

office365/directory/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def delete_object(self, permanent_delete=False):
142142
"""
143143
super(User, self).delete_object()
144144
if permanent_delete:
145-
deleted_user = self.context.directory.deletedUsers[self.id]
145+
deleted_user = self.context.directory.deleted_users[self.id]
146146
deleted_user.delete_object()
147147
return self
148148

office365/entity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class Entity(ClientObject):
8+
"""Base entity"""
89

910
def update(self):
1011
"""Updates the entity."""
@@ -40,7 +41,5 @@ def id(self):
4041
def set_property(self, name, value, persist_changes=True):
4142
super(Entity, self).set_property(name, value, persist_changes)
4243
if name == "id" and self._resource_path is None:
43-
self._resource_path = ResourcePath(
44-
value,
45-
self._parent_collection.resource_path)
44+
self._resource_path = ResourcePath(value,self._parent_collection.resource_path)
4645
return self

0 commit comments

Comments
 (0)