Skip to content

Commit 1951be0

Browse files
committed
OneDrive new actions
1 parent ab9b2ec commit 1951be0

File tree

16 files changed

+206
-33
lines changed

16 files changed

+206
-33
lines changed

examples/directory/applications/has_application_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
resource = client.service_principals.get_by_name("Microsoft Graph")
2323
app_role = "Place.Read.All" # "Bookings.Read.All"
2424
result = resource.get_application_permissions(test_client_id).execute_query()
25-
#if app_role not in result.value:
25+
# if app_role not in result.value:
2626
if not any(role.value == app_role for role in result.value):
2727
print("Application permission '{0}' is not granted".format(app_role))
2828
else:

office365/directory/identitygovernance/entitlementmanagement/accesspackage/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from office365.entity import Entity
2+
3+
4+
class AccessPackageCatalog(Entity):
5+
"""In Microsoft Entra entitlement management, an access package catalog is a container for zero or more access
6+
packages. Microsoft Entra entitlement management includes a built-in catalog named General.
7+
8+
An access package catalog might also have linked resources that are used in those access packages
9+
to provide access. To view or change the membership of catalog-scoped roles, use the role assignments API
10+
with the entitlement management RBAC provider."""
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.entity import Entity
2+
3+
4+
class AccessPackageResourceRequest(Entity):
5+
"""In Microsoft Entra entitlement management, an access package resource request is a request
6+
to add a resource to a catalog so that the roles of the resource can be used in one or more of the catalog's
7+
access packages, update a resource in a catalog to have different attribute requirements, or to remove a resource
8+
from a catalog that is no longer needed by the access packages."""
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
from office365.directory.identitygovernance.entitlementmanagement.accesspackage.resource_request import (
2+
AccessPackageResourceRequest,
3+
)
14
from office365.entity import Entity
5+
from office365.entity_collection import EntityCollection
6+
from office365.runtime.paths.resource_path import ResourcePath
27

38

49
class EntitlementManagement(Entity):
510
"""The entitlement management singleton is the container for entitlement management resources,
611
including accessPackageCatalog, connectedOrganization, and entitlementManagementSettings.
712
"""
13+
14+
@property
15+
def resource_requests(self):
16+
"""Represents a request to add or remove a resource to or from a catalog respectively."""
17+
return self.properties.get(
18+
"resourceRequests",
19+
EntityCollection(
20+
self.context,
21+
AccessPackageResourceRequest,
22+
ResourcePath("resourceRequests", self.resource_path),
23+
),
24+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Optional
2+
3+
from office365.entity import Entity
4+
5+
6+
class CustomCalloutExtension(Entity):
7+
"""An abstract type that defines the configuration for apps that can extend the customer's identity flows."""
8+
9+
@property
10+
def display_name(self):
11+
# type: () -> Optional[str]
12+
"""Display name for the customCalloutExtension object."""
13+
return self.properties.get("displayName", None)

office365/directory/users/user.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,59 @@ def change_password(self, current_password, new_password):
233233
self.context.add_query(qry)
234234
return self
235235

236+
def follow_site(self, site):
237+
# type: (str|Site) -> None
238+
"""follow a site"""
239+
240+
def _follow_site(site_id):
241+
# type: (str) -> None
242+
payload = {
243+
"value": [
244+
{
245+
"id": site_id,
246+
}
247+
]
248+
}
249+
query = ServiceOperationQuery(self.followed_sites, "add", None, payload)
250+
self.context.add_query(query)
251+
252+
if isinstance(site, Site):
253+
254+
def _user_loaded():
255+
_follow_site(site.id)
256+
257+
site.ensure_property("id", _user_loaded)
258+
else:
259+
_follow_site(site)
260+
return self
261+
262+
def unfollow_site(self, site):
263+
# type: (str|Site) -> None
264+
"""Unfollow a user's site or multiple sites."""
265+
266+
def _unfollow_site(site_id):
267+
# type: (str) -> None
268+
payload = {
269+
"value": [
270+
{
271+
"id": site_id,
272+
}
273+
]
274+
}
275+
query = ServiceOperationQuery(self.followed_sites, "remove", None, payload)
276+
self.context.add_query(query)
277+
278+
if isinstance(site, Site):
279+
280+
def _user_loaded():
281+
_unfollow_site(site.id)
282+
283+
site.ensure_property("id", _user_loaded)
284+
else:
285+
_unfollow_site(site)
286+
287+
return self
288+
236289
def get_mail_tips(self, email_addresses, mail_tips_options=None):
237290
"""Get the MailTips of one or more recipients as available to the signed-in user.
238291
:param list[str] email_addresses: A collection of SMTP addresses of recipients to get MailTips for.

office365/graph_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,7 @@ def security(self):
527527
def schema_extensions(self):
528528
"""Get a list of schemaExtension objects in your tenant"""
529529
return EntityCollection(self, SchemaExtension, ResourcePath("schemaExtensions"))
530+
531+
@property
532+
def tenant_name(self):
533+
return self._tenant
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
from office365.runtime.compat import is_absolute_url, urlparse
1+
from office365.runtime.compat import urlparse
22
from office365.runtime.paths.resource_path import ResourcePath
33
from office365.runtime.paths.v4.entity import EntityPath
44

55

66
class SitePath(EntityPath):
77
"""Resource path for addressing Site resource"""
88

9-
@property
10-
def segment(self):
11-
if is_absolute_url(self._key):
12-
url_result = urlparse(self._key)
13-
return ":".join([url_result.hostname, url_result.path])
14-
else:
15-
return super(SitePath, self).segment
9+
def __init__(self, host_name, relative_path, parent=None):
10+
super(SitePath, self).__init__(
11+
":".join([host_name, relative_path]), parent, ResourcePath("sites")
12+
)
1613

17-
@property
18-
def collection(self):
19-
if self._collection is None:
20-
self._collection = ResourcePath("sites")
21-
return self._collection
14+
@staticmethod
15+
def from_url(url, parent=None):
16+
url_result = urlparse(url)
17+
return SitePath(url_result.hostname, url_result.path, parent)

office365/onedrive/sites/sites_with_root.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,24 @@ def get_all_sites(self):
2121
self.context.add_query(qry)
2222
return return_type
2323

24+
def get_by_path(self, path):
25+
"""Address Site resource by server relative path
26+
27+
:param str path: Server relative path
28+
"""
29+
tenant_part = self.context.tenant_name.split(".")[0]
30+
host_name = "{0}.sharepoint.com".format(tenant_part)
31+
return_type = Site(self.context, SitePath(host_name, path, self.resource_path))
32+
qry = ReadEntityQuery(return_type)
33+
self.context.add_query(qry)
34+
return return_type
35+
2436
def get_by_url(self, url):
2537
"""Address Site resource by absolute url
2638
2739
:param str url: Site absolute url
2840
"""
29-
return_type = Site(self.context, SitePath(url, self.resource_path))
41+
return_type = Site(self.context, SitePath.from_url(url, self.resource_path))
3042
qry = ReadEntityQuery(return_type)
3143
self.context.add_query(qry)
3244
return return_type

0 commit comments

Comments
 (0)