Skip to content

Commit 8bad836

Browse files
committed
SharePoint API (tenant namespace) & directory improvements
1 parent 98bb317 commit 8bad836

File tree

21 files changed

+224
-37
lines changed

21 files changed

+224
-37
lines changed

examples/directory/applications/list_delegated_perms.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
resource = (
2525
client.service_principals.get_by_name("Microsoft Graph").get().execute_query()
2626
)
27-
result = resource.get_delegated_permissions(
28-
test_client_id, only_admin_consent=True
29-
).execute_query()
27+
result = resource.get_delegated_permissions(test_client_id).execute_query()
3028

3129
for grant in result:
32-
print(grant.scope)
30+
print(grant.scope + ";")

examples/onedrive/sitepages/create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from tests import test_client_id, test_client_secret, test_tenant
8+
from tests import test_client_id, test_client_secret, test_team_site_url, test_tenant
99

1010
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
11-
root_site = client.sites.root.get().execute_query()
12-
page = root_site.pages.add("test").execute_query()
11+
site = client.sites.get_by_url(test_team_site_url)
12+
page = site.pages.add("test456").execute_query()
1313
print("Page url: {0}".format(page))

examples/onedrive/sitepages/list.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
Get the collection of sitePage objects from the site pages list in a site.
3+
4+
https://learn.microsoft.com/en-us/graph/api/sitepage-list?view=graph-rest-1.0
5+
"""
6+
7+
from office365.graph_client import GraphClient
8+
from tests import test_client_id, test_client_secret, test_team_site_url, test_tenant
9+
10+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
11+
site = client.sites.get_by_url(test_team_site_url)
12+
pages = site.pages.get().execute_query()
13+
for page in pages:
14+
print("Page url: {0}".format(page))

generator/metadata/SharePoint.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35662,11 +35662,11 @@
3566235662
</EntityType>
3566335663
<EntityType Name="CorporateCatalogAppMetadata">
3566435664
<Key>
35665-
<PropertyRef Name="AppCatalogVersion"/>
35665+
<PropertyRef Name="AadAppId"/>
3566635666
</Key>
35667-
<Property Name="AadAppId" Type="Edm.String"/>
35667+
<Property Name="AadAppId" Type="Edm.String" Nullable="false"/>
3566835668
<Property Name="AadPermissions" Type="Edm.String"/>
35669-
<Property Name="AppCatalogVersion" Type="Edm.String" Nullable="false"/>
35669+
<Property Name="AppCatalogVersion" Type="Edm.String"/>
3567035670
<Property Name="CanUpgrade" Type="Edm.Boolean" Nullable="false"/>
3567135671
<Property Name="CDNLocation" Type="Edm.String"/>
3567235672
<Property Name="ContainsTenantWideExtension" Type="Edm.Boolean" Nullable="false"/>
@@ -38795,10 +38795,10 @@
3879538795
</EntityType>
3879638796
<EntityType Name="TenantAdminEndpoints">
3879738797
<Key>
38798-
<PropertyRef Name="CdnDefaultEndpoint"/>
38798+
<PropertyRef Name="AADAdminCenterEndpoint"/>
3879938799
</Key>
38800-
<Property Name="AADAdminCenterEndpoint" Type="Edm.String"/>
38801-
<Property Name="CdnDefaultEndpoint" Type="Edm.String" Nullable="false"/>
38800+
<Property Name="AADAdminCenterEndpoint" Type="Edm.String" Nullable="false"/>
38801+
<Property Name="CdnDefaultEndpoint" Type="Edm.String"/>
3880238802
<Property Name="CFRMSGraphEndpoint" Type="Edm.String"/>
3880338803
<Property Name="MigrationAgentUrl" Type="Edm.String"/>
3880438804
<Property Name="MiniMavenEndpoint" Type="Edm.String"/>

office365/directory/serviceprincipals/service_principal.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,32 @@ def _after():
114114
else:
115115
self.context.service_principals.get_by_app(app).get().after_execute(action)
116116

117-
def get_delegated_permissions(self, app, principal=None, only_admin_consent=False):
118-
# type: (Application|str, User|str, bool) -> DeltaCollection[OAuth2PermissionGrant]
117+
def get_delegated_permissions(self, app, principal=None):
118+
# type: (Application|str, User|str) -> ClientResult[StringCollection]
119119
"""Gets a delegated API permission"""
120120

121-
return_type = DeltaCollection(self.context, OAuth2PermissionGrant)
121+
return_type = ClientResult(self.context, StringCollection())
122122

123123
def _get_delegated_permissions(client_id, principal_id=None):
124124
# type: (str, str) -> None
125125

126126
if principal_id is None:
127-
128-
query_text = "clientId eq '{0}'".format(client_id)
129-
if only_admin_consent:
130-
query_text = query_text + " and consentType eq 'AllPrincipals'"
131-
127+
query_text = (
128+
"clientId eq '{0}' and consentType eq 'AllPrincipals'".format(
129+
client_id
130+
)
131+
)
132132
else:
133133
query_text = "principalId eq '{0}' and clientId eq '{1}'".format(
134134
principal_id, client_id
135135
)
136136

137137
def _loaded(col):
138-
[return_type.add_child(g) for g in col if g.resource_id == self.id]
138+
scope_val = next(
139+
iter([g.scope for g in col if g.resource_id == self.id]), None
140+
)
141+
if scope_val is not None:
142+
[return_type.value.add(name) for name in scope_val.split(" ")]
139143

140144
(
141145
self.context.oauth2_permission_grants.get()

office365/onedrive/driveitems/driveItem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def _save_content(return_type):
366366
def download_folder(
367367
self, download_file, after_file_downloaded=None, recursive=True
368368
):
369-
# type: (IO, Callable[[File], None], bool) -> "DriveItem"
369+
# type: (IO, Callable[["DriveItem"], None], bool) -> "DriveItem"
370370
"""
371371
Download the folder content
372372
"""

office365/onedrive/driveitems/retention_label.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from datetime import datetime
12
from typing import Optional
23

34
from office365.directory.permissions.identity_set import IdentitySet
45
from office365.entity import Entity
6+
from office365.onedrive.driveitems.retention_label_settings import (
7+
RetentionLabelSettings,
8+
)
59

610

711
class ItemRetentionLabel(Entity):
@@ -23,3 +27,32 @@ def label_applied_by(self):
2327
# type: () -> Optional[IdentitySet]
2428
"""Identity of the user who applied the label. Read-only."""
2529
return self.properties.get("labelAppliedBy", IdentitySet())
30+
31+
@property
32+
def label_applied_datetime(self):
33+
# type: () -> Optional[datetime]
34+
"""The date and time when the label was applied on the item.
35+
The timestamp type represents date and time information using ISO 8601 format and is always in UTC.
36+
"""
37+
return self.properties.get("labelAppliedDateTime", datetime.min)
38+
39+
@property
40+
def name(self):
41+
# type: () -> Optional[str]
42+
"""The retention label on the document. Read-write."""
43+
return self.properties.get("name", None)
44+
45+
@property
46+
def retention_settings(self):
47+
# type: () -> RetentionLabelSettings
48+
"""The retention settings enforced on the item. Read-write."""
49+
return self.properties.get("retentionSettings", RetentionLabelSettings())
50+
51+
def get_property(self, name, default_value=None):
52+
if default_value is None:
53+
property_mapping = {
54+
"labelAppliedBy": self.label_applied_by,
55+
"retentionSettings": self.retention_settings,
56+
}
57+
default_value = property_mapping.get(name, None)
58+
return super(ItemRetentionLabel, self).get_property(name, default_value)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class RetentionLabelSettings(ClientValue):
5+
"""
6+
Groups all the compliance retention restrictions on the item into a single structure.
7+
"""

office365/onedrive/sitepages/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
class BaseSitePage(BaseItem):
88
"""An abstract type that represents a page in the site page library."""
99

10+
def __repr__(self):
11+
return self.name or self.entity_type_name
12+
1013
@property
1114
def publishing_state(self):
1215
# type: () -> Optional[str]

office365/onedrive/sitepages/collection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ class SitePageCollection(EntityCollection[SitePage]):
1010
def __init__(self, context, resource_path=None):
1111
super(SitePageCollection, self).__init__(context, SitePage, resource_path)
1212

13+
def get(self):
14+
def _construct_request(request):
15+
# type: (RequestOptions) -> None
16+
# request.url += "/microsoft.graph.sitePage"
17+
pass
18+
19+
return super(SitePageCollection, self).get().before_execute(_construct_request)
20+
21+
def get_by_name(self, name):
22+
return self.single("name eq '{0}'".format(name))
23+
1324
def add(self, title):
1425
"""
1526
Create a new sitePage in the site pages list in a site.
1627
28+
:param str title:
1729
"""
1830

1931
def _construct_request(request):

0 commit comments

Comments
 (0)