Skip to content

Commit e178726

Browse files
committed
SharePoint API enhancements: portal namespace types & methods
1 parent 930876e commit e178726

File tree

19 files changed

+203
-7
lines changed

19 files changed

+203
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from office365.sharepoint.client_context import ClientContext
2+
from tests import test_client_credentials, test_team_site_url
3+
4+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
5+
6+
w = ctx.web.assign_document_id("MEDIADEVDOC").execute_query()
7+
print("Document IDs has been assigned")

office365/graph_request.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.odata.request import ODataRequest
2+
from office365.runtime.odata.v4.json_format import V4JsonFormat
3+
4+
5+
class GraphRequest(ODataRequest):
6+
7+
def __init__(self):
8+
super(GraphRequest, self).__init__(V4JsonFormat())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class AppCollection(BaseEntity):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.AppServices.AppCollection"

office365/sharepoint/client_context.py

+45-4
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
from office365.runtime.auth.authentication_context import AuthenticationContext
44
from office365.runtime.auth.user_credential import UserCredential
55
from office365.runtime.client_runtime_context import ClientRuntimeContext
6+
from office365.runtime.compat import urlparse, is_absolute_url, get_absolute_url
67
from office365.runtime.http.http_method import HttpMethod
78
from office365.runtime.http.request_options import RequestOptions
8-
from office365.runtime.odata.v3.json_light_format import JsonLightFormat
9-
from office365.runtime.odata.v3.batch_request import ODataBatchV3Request
109
from office365.runtime.odata.request import ODataRequest
10+
from office365.runtime.odata.v3.batch_request import ODataBatchV3Request
11+
from office365.runtime.odata.v3.json_light_format import JsonLightFormat
12+
from office365.runtime.paths.resource_path import ResourcePath
1113
from office365.runtime.queries.delete_entity import DeleteEntityQuery
1214
from office365.runtime.queries.update_entity import UpdateEntityQuery
13-
from office365.runtime.paths.resource_path import ResourcePath
1415
from office365.sharepoint.portal.sites.status import SiteStatus
1516
from office365.sharepoint.publishing.pages.service import SitePageService
1617
from office365.sharepoint.request_user_context import RequestUserContext
1718
from office365.sharepoint.sites.site import Site
1819
from office365.sharepoint.tenant.administration.hubsites.collection import HubSiteCollection
1920
from office365.sharepoint.webs.context_web_information import ContextWebInformation
2021
from office365.sharepoint.webs.web import Web
21-
from office365.runtime.compat import urlparse, is_absolute_url, get_absolute_url
2222

2323

2424
class ClientContext(ClientRuntimeContext):
@@ -322,6 +322,11 @@ def site(self):
322322
self._site = Site(self)
323323
return self._site
324324

325+
@property
326+
def apps(self):
327+
from office365.sharepoint.apps.app_collection import AppCollection
328+
return AppCollection(self, ResourcePath("Apps"))
329+
325330
@property
326331
def me(self):
327332
"""Gets the user context for the present request"""
@@ -404,6 +409,18 @@ def machine_learning(self):
404409
from office365.sharepoint.contentcenter.machinelearning.hub import SPMachineLearningHub
405410
return SPMachineLearningHub(self, ResourcePath("machinelearning"))
406411

412+
@property
413+
def org_news(self):
414+
"""Alias to OrgNewsSite"""
415+
from office365.sharepoint.portal.organization_news import OrganizationNews
416+
return OrganizationNews(self, ResourcePath("OrgNews"))
417+
418+
@property
419+
def org_news_site(self):
420+
"""Alias to OrgNewsSite"""
421+
from office365.sharepoint.orgnewssite.api import OrgNewsSiteApi
422+
return OrgNewsSiteApi(self, ResourcePath("OrgNewsSite"))
423+
407424
@property
408425
def search_setting(self):
409426
"""Alias to SearchSetting"""
@@ -433,6 +450,24 @@ def site_manager(self):
433450
from office365.sharepoint.portal.sites.manager import SPSiteManager
434451
return SPSiteManager(self, ResourcePath("spSiteManager"))
435452

453+
@property
454+
def home_service(self):
455+
"""Alias to SharePointHomeServiceContextBuilder."""
456+
from office365.sharepoint.portal.home.service_context_builder import SharePointHomeServiceContextBuilder
457+
return SharePointHomeServiceContextBuilder(self, ResourcePath("sphomeservice"))
458+
459+
@property
460+
def home_site(self):
461+
"""Alias to SPHSite."""
462+
from office365.sharepoint.sites.sph_site import SPHSite
463+
return SPHSite(self, ResourcePath("SPHSite"))
464+
465+
@property
466+
def publications(self):
467+
from office365.sharepoint.base_entity_collection import BaseEntityCollection
468+
from office365.sharepoint.contentcenter.machinelearning.publication import SPMachineLearningPublication
469+
return BaseEntityCollection(self, SPMachineLearningPublication, ResourcePath("publications"))
470+
436471
@property
437472
def social_following_manager(self):
438473
from office365.sharepoint.social.following.manager import SocialFollowingManager
@@ -462,6 +497,12 @@ def tenant_settings(self):
462497
from office365.sharepoint.tenant.settings import TenantSettings
463498
return TenantSettings.current(self)
464499

500+
@property
501+
def work_items(self):
502+
from office365.sharepoint.contentcenter.machinelearning.work_item_collection import \
503+
SPMachineLearningWorkItemCollection
504+
return SPMachineLearningWorkItemCollection(self, ResourcePath("workitems"))
505+
465506
@property
466507
def tenant(self):
467508
from office365.sharepoint.tenant.administration.tenant import Tenant

office365/sharepoint/contentcenter/machinelearning/publication.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33

44
class SPMachineLearningPublication(BaseEntity):
5-
pass
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.Office.Server.ContentCenter.SPMachineLearningPublication"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.sharepoint.base_entity_collection import BaseEntityCollection
2+
from office365.sharepoint.contentcenter.machinelearning.work_item import SPMachineLearningWorkItem
3+
4+
5+
class SPMachineLearningWorkItemCollection(BaseEntityCollection):
6+
7+
def __init__(self, context, resource_path=None):
8+
super(SPMachineLearningWorkItemCollection, self).__init__(context, SPMachineLearningWorkItem, resource_path)

office365/sharepoint/listhome/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class FavoriteLists(BaseEntity):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "SP.FavoriteLists"

office365/sharepoint/listhome/item.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ListHomeItem(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.SharePoint.ListHome.ListHomeItem"

office365/sharepoint/orgnewssite/__init__.py

Whitespace-only changes.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from office365.runtime.client_result import ClientResult
2+
from office365.runtime.paths.resource_path import ResourcePath
3+
from office365.runtime.queries.service_operation import ServiceOperationQuery
4+
from office365.sharepoint.base_entity import BaseEntity
5+
from office365.sharepoint.orgnewssite.info import OrgNewsSiteInfo
6+
7+
8+
class OrgNewsSiteApi(BaseEntity):
9+
10+
def __init__(self, context, resource_path=None):
11+
if resource_path is None:
12+
resource_path = ResourcePath("Microsoft.SharePoint.OrgNewsSite.OrgNewsSiteApi")
13+
super(OrgNewsSiteApi, self).__init__(context, resource_path)
14+
15+
def details(self):
16+
return_type = ClientResult(self.context, OrgNewsSiteInfo())
17+
qry = ServiceOperationQuery(self, "Details", None, None, None, return_type)
18+
self.context.add_query(qry)
19+
return return_type
20+
21+
@property
22+
def entity_type_name(self):
23+
return "Microsoft.SharePoint.OrgNewsSite.OrgNewsSiteApi"
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class OrgNewsSiteInfo(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.SharePoint.OrgNewsSite.OrgNewsSiteInfo"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class SharePointHomePageContext(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "Microsoft.SharePoint.Portal.Home.SharePointHomePageContext"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from office365.runtime.queries.service_operation import ServiceOperationQuery
2+
from office365.sharepoint.base_entity import BaseEntity
3+
from office365.sharepoint.portal.home.service_context import SharePointHomeServiceContext
4+
5+
6+
class SharePointHomeServiceContextBuilder(BaseEntity):
7+
8+
def get_context(self):
9+
return_type = SharePointHomeServiceContext(self.context)
10+
qry = ServiceOperationQuery(self, "Context", None, None, None, return_type)
11+
self.context.add_query(qry)
12+
return None
13+
14+
@property
15+
def entity_type_name(self):
16+
return "Microsoft.SharePoint.Portal.SharePointHomeServiceContextBuilder"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from office365.runtime.client_result import ClientResult
2+
from office365.runtime.client_value import ClientValue
3+
from office365.runtime.client_value_collection import ClientValueCollection
4+
from office365.runtime.queries.service_operation import ServiceOperationQuery
5+
from office365.sharepoint.base_entity import BaseEntity
6+
7+
8+
class OrganizationNewsSiteReference(ClientValue):
9+
pass
10+
11+
12+
class OrganizationNews(BaseEntity):
13+
14+
def sites_reference(self):
15+
return_type = ClientResult(self.context, ClientValueCollection(OrganizationNewsSiteReference))
16+
qry = ServiceOperationQuery(self, "SitesReference", None, None, None, return_type)
17+
self.context.add_query(qry)
18+
return return_type

office365/sharepoint/sites/sph_site.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
class SPHSite(BaseEntity):
99

10-
def __init__(self, context):
10+
def __init__(self, context, resource_path=None):
1111
"""
1212
A home site represents a SharePoint communication site.
1313
It brings together news, events, embedded video and conversations, and other resources to deliver an engaging
1414
experience that reflects your organization's voice, priorities, and brand.
1515
It also allows your users to search for content (such as sites, news, and files) across your organization
1616
"""
17-
super(SPHSite, self).__init__(context, ResourcePath("SP.SPHSite"))
17+
if resource_path is None:
18+
resource_path = ResourcePath("SP.SPHSite")
19+
super(SPHSite, self).__init__(context, resource_path)
1820

1921
def details(self):
2022
return_type = ClientResult(self.context, SPHSiteReference())

office365/sharepoint/webs/web.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# coding=utf-8
2+
23
from office365.runtime.client_result import ClientResult
34
from office365.runtime.client_value_collection import ClientValueCollection
45
from office365.runtime.queries.service_operation import ServiceOperationQuery
@@ -1279,6 +1280,19 @@ def set_global_nav_settings(self, title, source):
12791280
self.context.add_query(qry)
12801281
return self
12811282

1283+
def assign_document_id(self, site_prefix):
1284+
"""
1285+
Assign Document IDs
1286+
1287+
:param str site_prefix: Specify whether IDs will be automatically assigned to all documents in the
1288+
Site Collection. Additionally, you can specify a set of 4-12 characters that will be used at the beginning
1289+
of all IDs assigned for documents in this Site Collection, to help ensure that items in different
1290+
Site Collections will never get the same ID. Note: A timer job will be scheduled to assign IDs to
1291+
documents already in the Site Collection.
1292+
"""
1293+
props = {"docid_msft_hier_siteprefix": site_prefix, "docid_enabled": "1"}
1294+
return self.set_property("AllProperties", props).update()
1295+
12821296
@property
12831297
def activities(self):
12841298
return self.properties.get("Activities",

tests/sharepoint/test_comminication_site.py

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def test4_is_valid_home_site(self):
3434
result = self.__class__.target_site.is_valid_home_site().execute_query()
3535
self.assertIsNotNone(result.value)
3636

37+
#def test5_get_home_details(self):
38+
# result = self.client.home_site.details().execute_query()
39+
# self.assertIsNotNone(result.value)
40+
3741
def test7_register_hub_site(self):
3842
tenant = Tenant.from_url(test_admin_site_url).with_credentials(test_user_credentials)
3943
props = tenant.register_hub_site(self.__class__.target_site.url).execute_query()

tests/sharepoint/test_org_news.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from tests.sharepoint.sharepoint_case import SPTestCase
2+
3+
4+
class TestOrgNews(SPTestCase):
5+
6+
def test_1_get_org_news(self):
7+
result = self.client.org_news.get().execute_query()
8+
self.assertIsNotNone(result.resource_path)
9+
10+
def test2_sites_reference(self):
11+
result = self.client.org_news.sites_reference().execute_query()
12+
self.assertIsNotNone(result.value)

0 commit comments

Comments
 (0)