Skip to content

Commit a3dd31f

Browse files
committed
publishing namespace enhancements: new types & methods
1 parent 75b1fee commit a3dd31f

File tree

15 files changed

+137
-35
lines changed

15 files changed

+137
-35
lines changed

examples/sharepoint/pages/create_modern_page.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import uuid
2+
13
from office365.sharepoint.client_context import ClientContext
24
from office365.sharepoint.publishing.pages.page import SitePage
35
from tests import test_client_credentials, test_team_site_url
46

57
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
8+
page_title = "Site Page {0}".format(uuid.uuid4().hex)
69
new_page = ctx.site_pages.pages.add()
7-
new_page.save_draft(title="Latest News 456")
10+
new_page.save_draft(title=page_title)
811
new_page.publish().execute_query()
912

1013
pages = ctx.site_pages.pages.get().execute_query()

office365/sharepoint/portal/groups/site_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def __init__(self, context, resource_path=None):
1616
resource_path = ResourcePath("GroupSiteManager")
1717
super(GroupSiteManager, self).__init__(context, resource_path)
1818

19+
def can_user_create_group(self):
20+
return_type = ClientResult(self.context, bool())
21+
qry = ServiceOperationQuery(self, "CanUserCreateGroup", None, None, None, return_type)
22+
self.context.add_query(qry)
23+
return return_type
24+
1925
def create_group_for_site(self, display_name, alias, is_public=None, optional_params=None):
2026
"""
2127
Create a modern site
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from office365.runtime.client_value import ClientValue
2+
from office365.runtime.client_value_collection import ClientValueCollection
3+
from office365.sharepoint.publishing.diagnostics.page_result import PageDiagnosticsResult
24

35

46
class PageDiagnostics(ClientValue):
57

8+
def __init__(self, results=None):
9+
self.Results = ClientValueCollection(PageDiagnosticsResult, results)
10+
611
@property
712
def entity_type_name(self):
813
return "Microsoft.SharePoint.Publishing.Diagnostics.PageDiagnostics"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class PageDiagnosticsResult(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.SharePoint.Publishing.Diagnostics.PageDiagnosticsResult"
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
from office365.runtime.client_value import ClientValue
2+
from office365.sharepoint.administration.orgassets.org_assets import OrgAssets
23

34

45
class FilePickerOptions(ClientValue):
5-
pass
6+
7+
def __init__(self, search_enabled=None, central_asset_repository=OrgAssets(), org_assets=OrgAssets()):
8+
self.BingSearchEnabled = search_enabled
9+
self.CentralAssetRepository = central_asset_repository
10+
self.OrgAssets = org_assets
11+
12+
@property
13+
def entity_type_name(self):
14+
return "SP.Publishing.FilePickerOptions"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.sharepoint.publishing.pages.page import SitePage
2+
3+
4+
class CampaignPublication(SitePage):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "SP.Publishing.CampaignPublication"

office365/sharepoint/publishing/pages/collection.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from office365.runtime.client_result import ClientResult
2+
from office365.runtime.paths.service_operation import ServiceOperationPath
23
from office365.runtime.queries.create_entity import CreateEntityQuery
34
from office365.runtime.queries.service_operation import ServiceOperationQuery
45
from office365.runtime.paths.resource_path import ResourcePath
@@ -49,7 +50,7 @@ def is_site_page(self, url):
4950
5051
:param str url: URL of the SitePage to be checked.
5152
"""
52-
return_type = ClientResult(self.context)
53+
return_type = ClientResult(self.context, bool())
5354
qry = ServiceOperationQuery(self, "IsSitePage", [url], None, None, return_type)
5455
self.context.add_query(qry)
5556
return return_type
@@ -60,7 +61,18 @@ def get_page_column_state(self, url):
6061
6162
:param str url: URL of the SitePage for which to return state.
6263
"""
63-
return_type = ClientResult(self.context)
64+
return_type = ClientResult(self.context, int())
6465
qry = ServiceOperationQuery(self, "GetPageColumnState", [url], None, None, return_type)
6566
self.context.add_query(qry)
6667
return return_type
68+
69+
def get_by_url(self, url):
70+
"""Gets the site page with the specified server relative url.
71+
72+
:param int url: Specifies the server relative url of the site page.
73+
"""
74+
return SitePage(self.context, ServiceOperationPath("GetByUrl", [url], self.resource_path))
75+
76+
def templates(self):
77+
return SitePageMetadataCollection(self.context, SitePage,
78+
ServiceOperationPath("Templates", None, self.resource_path))

office365/sharepoint/publishing/pages/page.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
from office365.runtime.client_result import ClientResult
2+
from office365.runtime.client_value import ClientValue
23
from office365.runtime.paths.resource_path import ResourcePath
34
from office365.runtime.queries.service_operation import ServiceOperationQuery
5+
from office365.runtime.types.collections import StringCollection
46
from office365.sharepoint.publishing.pages.fields_data import SitePageFieldsData
57
from office365.sharepoint.publishing.pages.metadata import SitePageMetadata
68
from office365.sharepoint.translation.status_collection import TranslationStatusCollection
79

810

11+
class SharePagePreviewByEmailFieldsData(ClientValue):
12+
13+
def __init__(self, message=None, recipient_emails=None):
14+
self.message = message
15+
self.recipientEmails = StringCollection(recipient_emails)
16+
17+
@property
18+
def entity_type_name(self):
19+
return "SP.Publishing.SharePagePreviewByEmailFieldsData"
20+
21+
922
class SitePage(SitePageMetadata):
1023
"""Represents a Site Page."""
1124

@@ -28,6 +41,11 @@ def discard_page(self):
2841
self.context.add_query(qry)
2942
return self
3043

44+
def ensure_title_resource(self):
45+
qry = ServiceOperationQuery(self, "EnsureTitleResource")
46+
self.context.add_query(qry)
47+
return self
48+
3149
def save_page(self, title, canvas_content=None, banner_image_url=None, topic_header=None):
3250
"""
3351
Updates the current Site Page with the provided pageStream content.
@@ -59,10 +77,10 @@ def save_draft(self, title, canvas_content=None, banner_image_url=None, topic_he
5977
canvas_content=canvas_content,
6078
banner_image_url=banner_image_url,
6179
topic_header=topic_header)
62-
result = ClientResult(self.context)
63-
qry = ServiceOperationQuery(self, "SaveDraft", None, payload, "sitePage", result)
80+
return_type = ClientResult(self.context, bool())
81+
qry = ServiceOperationQuery(self, "SaveDraft", None, payload, "sitePage", return_type)
6482
self.context.add_query(qry)
65-
return result
83+
return return_type
6684

6785
def save_page_as_draft(self, title, canvas_content=None, banner_image_url=None, topic_header=None):
6886
"""
@@ -78,10 +96,10 @@ def save_page_as_draft(self, title, canvas_content=None, banner_image_url=None,
7896
canvas_content=canvas_content,
7997
banner_image_url=banner_image_url,
8098
topic_header=topic_header)
81-
result = ClientResult(self.context)
82-
qry = ServiceOperationQuery(self, "SavePageAsDraft", None, payload, "pageStream", result)
99+
return_type = ClientResult(self.context, bool())
100+
qry = ServiceOperationQuery(self, "SavePageAsDraft", None, payload, "pageStream", return_type)
83101
self.context.add_query(qry)
84-
return result
102+
return return_type
85103

86104
def save_page_as_template(self):
87105
"""
@@ -124,7 +142,7 @@ def publish(self):
124142
Publishes a major version of the current Site Page. Returns TRUE on success, FALSE otherwise.
125143
126144
"""
127-
result = ClientResult(self.context)
145+
result = ClientResult(self.context, bool())
128146
qry = ServiceOperationQuery(self, "Publish", None, None, None, result)
129147
self.context.add_query(qry)
130148
return result
@@ -146,14 +164,17 @@ def share_page_preview_by_email(self, message, recipient_emails):
146164
:param str message:
147165
:param list[str] recipient_emails:
148166
"""
149-
payload = {
150-
"message": message,
151-
"recipientEmails": recipient_emails
152-
}
167+
payload = SharePagePreviewByEmailFieldsData(message, recipient_emails)
153168
qry = ServiceOperationQuery(self, "SharePagePreviewByEmail", None, payload)
154169
self.context.add_query(qry)
155170
return self
156171

172+
def start_co_auth(self):
173+
return_type = SitePage(self.context, self.resource_path)
174+
qry = ServiceOperationQuery(self, "StartCoAuth", None, None, None, return_type)
175+
self.context.add_query(qry)
176+
return return_type
177+
157178
@property
158179
def canvas_content(self):
159180
"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from office365.sharepoint.publishing.pages.page import SitePage
2+
3+
4+
class SitePage3D(SitePage):
5+
6+
@property
7+
def space_content(self):
8+
return self.properties.get("SpaceContent", None)
9+
10+
@property
11+
def entity_type_name(self):
12+
return "SP.Publishing.SitePage3D"

office365/sharepoint/publishing/pages/service.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def can_create_page(self):
4343
MUST return true if the user has permission to create a site page, otherwise MUST return false.
4444
4545
"""
46-
return_type = ClientResult(self.context)
46+
return_type = ClientResult(self.context, bool())
4747
qry = ServiceOperationQuery(self, "CanCreatePage", None, None, None, return_type)
4848
self.context.add_query(qry)
4949
return return_type
@@ -53,7 +53,7 @@ def can_create_promoted_page(self):
5353
Checks if the current user has permission to create a site page on the site pages document library.
5454
MUST return true if the user has permission to create a site page, otherwise MUST return false.
5555
"""
56-
return_type = ClientResult(self.context)
56+
return_type = ClientResult(self.context, bool())
5757
qry = ServiceOperationQuery(self, "CanCreatePromotedPage", None, None, None, return_type)
5858
self.context.add_query(qry)
5959
return return_type
@@ -82,8 +82,7 @@ def get_time_zone(context, city_name):
8282
return_type = PrimaryCityTime(context)
8383
svc = SitePageService(context)
8484
params = {"cityName": city_name}
85-
qry = ServiceOperationQuery(svc, "GetTimeZone", params, None, None, return_type)
86-
qry.static = True
85+
qry = ServiceOperationQuery(svc, "GetTimeZone", params, None, None, return_type, True)
8786
context.add_query(qry)
8887
return return_type
8988

@@ -124,12 +123,11 @@ def org_assets(context):
124123
125124
:param office365.sharepoint.client_context.ClientContext context: Client context
126125
"""
127-
result = ClientResult(context, OrgAssets())
126+
return_type = ClientResult(context, OrgAssets())
128127
svc = SitePageService(context)
129-
qry = ServiceOperationQuery(svc, "OrgAssets", None, None, None, result)
130-
qry.static = True
128+
qry = ServiceOperationQuery(svc, "OrgAssets", None, None, None, return_type, True)
131129
context.add_query(qry)
132-
return result
130+
return return_type
133131

134132
@staticmethod
135133
def file_picker_tab_options(context):
@@ -155,8 +153,7 @@ def add_image(self, page_name, image_file_name, image_stream):
155153
"""
156154
return_type = File(self.context)
157155
params = {"pageName": page_name, "imageFileName": image_file_name, "imageStream": image_stream}
158-
qry = ServiceOperationQuery(self, "AddImage", params, None, None, return_type)
159-
qry.static = True
156+
qry = ServiceOperationQuery(self, "AddImage", params, None, None, return_type, True)
160157
self.context.add_query(qry)
161158
return return_type
162159

office365/sharepoint/search/administration/tenant_crawl_versions_info_provider.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33

44
class TenantCrawlVersionsInfoProvider(BaseEntity):
55
""""""
6+
7+
@property
8+
def entity_type_name(self):
9+
return "Microsoft.SharePoint.Client.Search.Administration.TenantCrawlVersionsInfoProvider"

office365/sharepoint/search/query/auto_completion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from office365.runtime.client_value import ClientValue
2+
from office365.runtime.client_value_collection import ClientValueCollection
3+
from office365.sharepoint.search.query.auto_completion_match import QueryAutoCompletionMatch
24

35

46
class QueryAutoCompletion(ClientValue):
@@ -12,6 +14,7 @@ def __init__(self, query=None, score=None, source=None):
1214
Source.
1315
:param str source: This element represents the Source used when retrieving the matched results.
1416
"""
17+
self.Matches = ClientValueCollection(QueryAutoCompletionMatch)
1518
self.Query = query
1619
self.Score = score
1720
self.Source = source

tests/sharepoint/test_publishing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from office365.sharepoint.publishing.pages.collection import SitePageCollection
2-
from office365.sharepoint.publishing.pages.service import SitePageService
32
from office365.sharepoint.publishing.pages.page import SitePage
3+
from office365.sharepoint.publishing.pages.service import SitePageService
44
from office365.sharepoint.publishing.video.service_discoverer import VideoServiceDiscoverer
55
from tests.sharepoint.sharepoint_case import SPTestCase
66

@@ -16,12 +16,11 @@ def tearDownClass(cls):
1616
pass
1717

1818
def test1_init_site_page_service(self):
19-
svc = SitePageService(self.client).get().execute_query()
19+
svc = self.client.site_pages.get().execute_query()
2020
self.assertIsNotNone(svc.resource_path)
2121

2222
def test2_get_site_pages(self):
23-
svc = SitePageService(self.client)
24-
pages = svc.pages.get().execute_query()
23+
pages = self.client.site_pages.pages.get().execute_query()
2524
self.assertIsInstance(pages, SitePageCollection)
2625

2726
# def test3_get_time_zone(self):
@@ -64,3 +63,7 @@ def test_11_get_page_diagnostics(self):
6463
result = self.client.page_diagnostics.by_page("/sites/team/SitePages/Home.aspx").execute_query()
6564
self.assertIsNotNone(result.value)
6665

66+
#def test_12_share_page_preview_by_email(self):
67+
# page = self.client.site_pages.pages.get_by_url("/sites/team/SitePages/Home.aspx")
68+
# page.share_page_preview_by_email("This page has been shared with you",
69+
# [test_user_principal_name_alt]).execute_query()

tests/sharepoint/test_search.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test6_search_suggest(self):
4545
result = self.client.search.suggest("guide.docx").execute_query()
4646
self.assertIsInstance(result.value, QuerySuggestionResults)
4747

48-
#def test7_auto_completions(self):
48+
# def test7_auto_completions(self):
4949
# result = self.search.auto_completions("guide").execute_query()
5050
# self.assertIsNotNone(result.value)
5151

@@ -56,9 +56,16 @@ def test8_get_query_configuration(self):
5656
def test9_get_promoted_result_query_rules(self):
5757
result = self.client.search_setting.get_promoted_result_query_rules().execute_query()
5858
self.assertIsNotNone(result.value)
59-
6059

61-
#def test7_get_crawled_urls(self):
60+
# def test7_get_crawled_urls(self):
6261
# doc_crawl_log = DocumentCrawlLog(self.client)
6362
# result = doc_crawl_log.get_crawled_urls().execute_query()
6463
# self.assertIsNotNone(result.value)
64+
65+
#def test_10_auto_completions(self):
66+
# result = self.client.search.auto_completions("guide.docx").execute_query()
67+
# self.assertIsNotNone(result.value)
68+
69+
#def test_11_get_crawled_urls(self):
70+
# result = DocumentCrawlLog(self.client).get_crawled_urls().execute_query()
71+
# self.assertIsNotNone(result.value)

tests/sharepoint/test_team_site.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ def setUpClass(cls):
1616
client = ClientContext(test_site_url).with_credentials(test_user_credentials)
1717
cls.client = client
1818

19-
def test1_create_site(self):
19+
def test1_can_user_create_group(self):
20+
result = self.client.group_site_manager.can_user_create_group().execute_query()
21+
self.assertIsNotNone(result.value)
22+
23+
def test2_create_site(self):
2024
site_name = "TeamSite{0}".format(uuid.uuid4().hex)
2125
site = self.client.create_team_site(site_name, "Team Site", True).execute_query()
2226
self.assertIsNotNone(site.url)
2327
self.__class__.target_site = site
2428

25-
def test2_get_site_status(self):
29+
def test3_get_site_status(self):
2630
site = self.__class__.target_site.get().select(["GroupId"]).execute_query()
2731
result = self.client.group_site_manager.get_status(site.group_id).execute_query()
2832
self.assertIsNotNone(result.value.SiteStatus)
2933
self.assertTrue(result.value.SiteStatus == SiteStatus.Ready)
3034

31-
def test3_get_notebook_url(self):
35+
def test4_get_notebook_url(self):
3236
group_id = self.__class__.target_site.group_id
3337
result = self.client.group_site_manager.notebook(group_id).execute_query()
3438
self.assertIsNotNone(result.value)

0 commit comments

Comments
 (0)