Skip to content

Commit 70e6fe8

Browse files
committed
SharePoint new types and model update
1 parent 7674550 commit 70e6fe8

Some content is hidden

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

52 files changed

+641
-74
lines changed

examples/directory/users/update.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
client = GraphClient.with_username_and_password(
1111
test_tenant, test_client_id, test_username, test_password
1212
)
13-
users = client.users.get().filter("startswith(displayName, 'testuser')").top(1).execute_query()
13+
users = (
14+
client.users.get()
15+
.filter("startswith(displayName, 'testuser')")
16+
.top(1)
17+
.execute_query()
18+
)
1419

1520
for u in users:
16-
u.set_property('officeLocation', "18/2111").update().execute_query()
21+
u.set_property("officeLocation", "18/2111").update().execute_query()

examples/directory/users/update_batch.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
client = GraphClient.with_username_and_password(
1111
test_tenant, test_client_id, test_username, test_password
1212
)
13-
users = client.users.get().filter("startswith(displayName, 'testuser')").top(50).execute_query()
13+
users = (
14+
client.users.get()
15+
.filter("startswith(displayName, 'testuser')")
16+
.top(50)
17+
.execute_query()
18+
)
1419

1520
for u in users:
16-
u.set_property('officeLocation', "18/2111").update()
21+
u.set_property("officeLocation", "18/2111").update()
1722

1823
client.execute_batch()
19-
20-
+11-30
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1-
from office365.runtime.client_request_exception import ClientRequestException
2-
from office365.sharepoint.client_context import ClientContext
3-
from office365.sharepoint.tenant.administration.tenant import Tenant
4-
from tests import test_admin_credentials, test_admin_site_url, test_user_principal_name
5-
6-
admin_client = ClientContext(test_admin_site_url).with_credentials(
7-
test_admin_credentials
8-
)
9-
tenant = Tenant(admin_client)
10-
result = tenant.get_site_properties_from_sharepoint_by_filters("").execute_query()
1+
"""
2+
Gets my sites
3+
"""
114

5+
from office365.sharepoint.client_context import ClientContext
6+
from tests import test_site_url, test_user_credentials
127

13-
def try_get_user_permissions(site_url, user_name):
14-
ctx = ClientContext(site_url).with_credentials(test_admin_credentials)
15-
try:
16-
ctx.web.get_user_effective_permissions(user_name).execute_query()
17-
# todo: determine user permissions from result
18-
return True
19-
except ClientRequestException as e:
20-
if e.response.status_code == 404:
21-
return False
22-
else:
23-
raise ValueError(e.response.text)
24-
8+
client = ClientContext(test_site_url).with_credentials(test_user_credentials)
259

26-
for siteProps in result:
27-
print("Current site url: {0}".format(siteProps.url))
28-
if try_get_user_permissions(siteProps.url, test_user_principal_name) is True:
29-
print(
30-
"Site url {0} {1} user has access to".format(
31-
siteProps.url, test_user_principal_name
32-
)
33-
)
10+
result = client.search.query("contentclass:STS_Site").execute_query()
11+
results = result.value.PrimaryQueryResult.RelevantResults
12+
for row in results.Table.Rows:
13+
site_url = row.Cells["Path"]
14+
print(site_url)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.entity import Entity
2+
3+
4+
class AccessRequests(Entity):
5+
""" """

office365/sharepoint/lists/list.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from office365.sharepoint.lists.creatables_info import CreatablesInfo
4646
from office365.sharepoint.lists.data_source import ListDataSource
4747
from office365.sharepoint.lists.rule import SPListRule
48+
from office365.sharepoint.lists.version_policy_manager import VersionPolicyManager
4849
from office365.sharepoint.navigation.configured_metadata_items import (
4950
ConfiguredMetadataNavigationItemCollection,
5051
)
@@ -131,8 +132,8 @@ def _save_schema():
131132
"FileSystemObjectType",
132133
]
133134
)
134-
# .expand(["File", "Folder"])
135-
.get().paged(page_loaded=_export_items)
135+
.get()
136+
.paged(page_loaded=_export_items)
136137
)
137138

138139
self.ensure_properties(["SchemaXml", "RootFolder"], _save_schema)
@@ -1128,6 +1129,16 @@ def user_custom_actions(self):
11281129
),
11291130
)
11301131

1132+
@property
1133+
def version_policies(self):
1134+
""" """
1135+
return self.properties.get(
1136+
"VersionPolicies",
1137+
VersionPolicyManager(
1138+
self.context, ResourcePath("VersionPolicies", self.resource_path)
1139+
),
1140+
)
1141+
11311142
@property
11321143
def custom_action_elements(self):
11331144
return self.properties.get(
@@ -1408,6 +1419,7 @@ def get_property(self, name, default_value=None):
14081419
"RootFolder": self.root_folder,
14091420
"TitleResource": self.title_resource,
14101421
"UserCustomActions": self.user_custom_actions,
1422+
"VersionPolicies": self.version_policies,
14111423
}
14121424
default_value = property_mapping.get(name, None)
14131425
return super(List, self).get_property(name, default_value)
@@ -1420,4 +1432,8 @@ def set_property(self, name, value, persist_changes=True):
14201432
self._resource_path = self.parent_collection.get_by_id(
14211433
value
14221434
).resource_path
1435+
elif name == "Url":
1436+
self._resource_path = ServiceOperationPath(
1437+
"getList", [value], self.context.web.resource_path
1438+
)
14231439
return self
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.entity import Entity
2+
3+
4+
class VersionPolicyManager(Entity):
5+
""" """
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1+
from office365.runtime.queries.service_operation import ServiceOperationQuery
12
from office365.sharepoint.entity import Entity
3+
from office365.sharepoint.entity_collection import EntityCollection
4+
from office365.sharepoint.userprofiles.sharedwithme.document import SharedWithMeDocument
25

36

47
class DocumentsSharedWithGroup(Entity):
58
"""
69
Provides methods for working with a list that shares documents with a SharePoint Group on the user's personal site.
710
"""
811

12+
@staticmethod
13+
def get_shared_with_group_docs(context, group_id=None):
14+
"""
15+
Gets a shared documents for a group.
16+
17+
:param office365.sharepoint.client_context.ClientContext context: SharePoint context
18+
:param str group_id:
19+
"""
20+
return_type = EntityCollection(context, SharedWithMeDocument)
21+
payload = {"groupId": group_id}
22+
qry = ServiceOperationQuery(
23+
DocumentsSharedWithGroup(context),
24+
"GetSharedWithGroupDocs",
25+
None,
26+
payload,
27+
None,
28+
return_type,
29+
True,
30+
)
31+
context.add_query(qry)
32+
return return_type
33+
934
@property
1035
def entity_type_name(self):
11-
return "Microsoft.SharePoint.Portal.UserProfiles.DocumentsSharedWithGroup"
36+
return "Microsoft.SharePoint.Portal.UserProfiles.group_id"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class SitePageCoAuthState(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "SP.Publishing.SitePageCoAuthState"

office365/sharepoint/publishing/pages/page.py

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from office365.runtime.paths.resource_path import ResourcePath
66
from office365.runtime.queries.service_operation import ServiceOperationQuery
77
from office365.runtime.types.collections import StringCollection
8+
from office365.sharepoint.publishing.pages.coauth_state import SitePageCoAuthState
89
from office365.sharepoint.publishing.pages.fields_data import SitePageFieldsData
910
from office365.sharepoint.publishing.pages.metadata import SitePageMetadata
1011
from office365.sharepoint.translation.status_collection import (
@@ -135,6 +136,16 @@ def save_page_as_template(self):
135136
self.context.add_query(qry)
136137
return return_type
137138

139+
def save_page_co_auth(self, page_stream):
140+
""" """
141+
return_type = ClientResult(self.context, SitePageCoAuthState())
142+
payload = {"pageStream": page_stream}
143+
qry = ServiceOperationQuery(
144+
self, "SavePageCoAuth", None, payload, None, return_type
145+
)
146+
self.context.add_query(qry)
147+
return return_type
148+
138149
def demote_from_news(self):
139150
"""
140151
Updates the promoted state of the site page to 0. On success MUST return true.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class SitePageStreamContent(ClientValue):
5+
""" """
6+
7+
@property
8+
def entity_type_name(self):
9+
return "SP.Publishing.SitePageStreamContent"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class SitePageStreamData(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "SP.Publishing.SitePageStreamData"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.sharepoint.entity import Entity
2+
3+
4+
class NonQuotaBackfillApi(Entity):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.SharePoint.QuotaManagement.Consumer.NonQuotaBackfillApi"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
from office365.runtime.client_result import ClientResult
2+
from office365.runtime.queries.service_operation import ServiceOperationQuery
13
from office365.sharepoint.entity import Entity
24

35

46
class SiteContentProcessingInfoProvider(Entity):
7+
8+
def get_azure_container_token(self):
9+
return_type = ClientResult(self.context, str())
10+
qry = ServiceOperationQuery(
11+
self, "GetAzureContainerToken", None, None, None, return_type
12+
)
13+
self.context.add_query(qry)
14+
return return_type
15+
516
@property
617
def entity_type_name(self):
718
return "Microsoft.SharePoint.Client.Search.Administration.SiteContentProcessingInfoProvider"

office365/sharepoint/search/ranking_labeling.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def add_judgment(self, user_query, url, label_id):
2828
return self
2929

3030
def normalize_result_url(self, url):
31+
# type: (str) -> ClientResult[str]
3132
"""
3233
A URL string after normalization. The input and output URL strings MUST resolve to the same document.
3334

office365/sharepoint/search/reports/abandonedqueries/__init__.py

Whitespace-only changes.

office365/sharepoint/search/reports/abandonedqueries/data.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ReportAbandonedQueriesItem(ClientValue):
5+
pass

office365/sharepoint/search/reports/noresult/__init__.py

Whitespace-only changes.

office365/sharepoint/search/reports/numberofqueries/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
from office365.runtime.client_value_collection import ClientValueCollection
12
from office365.sharepoint.search.reports.base import ReportBase
3+
from office365.sharepoint.search.reports.topqueries.item import ReportTopQueriesItem
24

35

46
class ReportTopQueries(ReportBase):
7+
8+
def __init__(self, reports=None):
9+
super(ReportTopQueries, self).__init__()
10+
self.Reports = ClientValueCollection(ReportTopQueriesItem, reports)
11+
512
@property
613
def entity_type_name(self):
714
return "Microsoft.Office.Server.Search.REST.ReportTopQueries"

office365/sharepoint/search/reports/topqueries/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ReportTopQueriesData(ClientValue):
5+
""" """
6+
7+
@property
8+
def entity_type_name(self):
9+
return "Microsoft.Office.Server.Search.REST.ReportTopQueriesData"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from office365.runtime.client_value import ClientValue
2+
from office365.runtime.client_value_collection import ClientValueCollection
3+
from office365.sharepoint.search.reports.topqueries.data import ReportTopQueriesData
4+
5+
6+
class ReportTopQueriesItem(ClientValue):
7+
""" """
8+
9+
def __init__(self, date=None, report=None):
10+
self.Date = date
11+
self.Report = ClientValueCollection(ReportTopQueriesData, report)
12+
13+
@property
14+
def entity_type_name(self):
15+
return "Microsoft.Office.Server.Search.REST.ReportTopQueriesItem"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ScsEndpoint(ClientValue):
5+
""" """
6+
7+
@property
8+
def entity_type_name(self):
9+
return "Microsoft.Office.Server.Search.REST.ScsEndpoint"

office365/sharepoint/sites/version_policy_manager.py

+25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Optional
22

3+
from office365.runtime.paths.resource_path import ResourcePath
34
from office365.runtime.queries.service_operation import ServiceOperationQuery
45
from office365.sharepoint.entity import Entity
6+
from office365.sharepoint.lists.version_policy_manager import VersionPolicyManager
57

68

79
class SiteVersionPolicyManager(Entity):
@@ -13,8 +15,31 @@ def major_version_limit(self):
1315
""" """
1416
return self.properties.get("MajorVersionLimit", None)
1517

18+
@property
19+
def version_policies(self):
20+
return self.properties.get(
21+
"VersionPolicies",
22+
VersionPolicyManager(
23+
self.context, ResourcePath("VersionPolicies", self.resource_path)
24+
),
25+
)
26+
27+
def inherit_tenant_settings(self):
28+
""" """
29+
qry = ServiceOperationQuery(self, "InheritTenantSettings")
30+
self.context.add_query(qry)
31+
return self
32+
1633
def set_auto_expiration(self):
1734
""""""
1835
qry = ServiceOperationQuery(self, "SetAutoExpiration")
1936
self.context.add_query(qry)
2037
return self
38+
39+
def get_property(self, name, default_value=None):
40+
if default_value is None:
41+
property_mapping = {
42+
"VersionPolicies": self.version_policies,
43+
}
44+
default_value = property_mapping.get(name, None)
45+
return super(SiteVersionPolicyManager, self).get_property(name, default_value)

office365/sharepoint/sitescripts/utility.py

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ def create_list_design(context, info):
4242
context.add_query(qry)
4343
return return_type
4444

45+
@staticmethod
46+
def get_list_designs(context, store=None):
47+
"""
48+
Gets a list designs.
49+
50+
:param office365.sharepoint.client_context.ClientContext context: SharePoint context
51+
:param str store:
52+
"""
53+
return_type = ClientResult(context, SiteDesignMetadata())
54+
utility = SiteScriptUtility(context)
55+
payload = {"store": store}
56+
qry = ServiceOperationQuery(
57+
utility, "GetListDesigns", None, payload, None, return_type, True
58+
)
59+
context.add_query(qry)
60+
return return_type
61+
4562
@staticmethod
4663
def add_site_design_task(context, web_url, site_design_id):
4764
"""

office365/sharepoint/tenant/administration/internal/aad/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)