Skip to content

Commit

Permalink
SharePoint new types and model update
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Sep 22, 2024
1 parent 7674550 commit 70e6fe8
Show file tree
Hide file tree
Showing 52 changed files with 641 additions and 74 deletions.
9 changes: 7 additions & 2 deletions examples/directory/users/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
users = client.users.get().filter("startswith(displayName, 'testuser')").top(1).execute_query()
users = (
client.users.get()
.filter("startswith(displayName, 'testuser')")
.top(1)
.execute_query()
)

for u in users:
u.set_property('officeLocation', "18/2111").update().execute_query()
u.set_property("officeLocation", "18/2111").update().execute_query()
11 changes: 7 additions & 4 deletions examples/directory/users/update_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
users = client.users.get().filter("startswith(displayName, 'testuser')").top(50).execute_query()
users = (
client.users.get()
.filter("startswith(displayName, 'testuser')")
.top(50)
.execute_query()
)

for u in users:
u.set_property('officeLocation', "18/2111").update()
u.set_property("officeLocation", "18/2111").update()

client.execute_batch()


41 changes: 11 additions & 30 deletions examples/sharepoint/tenant/get_my_sites.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
from office365.runtime.client_request_exception import ClientRequestException
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.tenant import Tenant
from tests import test_admin_credentials, test_admin_site_url, test_user_principal_name

admin_client = ClientContext(test_admin_site_url).with_credentials(
test_admin_credentials
)
tenant = Tenant(admin_client)
result = tenant.get_site_properties_from_sharepoint_by_filters("").execute_query()
"""
Gets my sites
"""

from office365.sharepoint.client_context import ClientContext
from tests import test_site_url, test_user_credentials

def try_get_user_permissions(site_url, user_name):
ctx = ClientContext(site_url).with_credentials(test_admin_credentials)
try:
ctx.web.get_user_effective_permissions(user_name).execute_query()
# todo: determine user permissions from result
return True
except ClientRequestException as e:
if e.response.status_code == 404:
return False
else:
raise ValueError(e.response.text)

client = ClientContext(test_site_url).with_credentials(test_user_credentials)

for siteProps in result:
print("Current site url: {0}".format(siteProps.url))
if try_get_user_permissions(siteProps.url, test_user_principal_name) is True:
print(
"Site url {0} {1} user has access to".format(
siteProps.url, test_user_principal_name
)
)
result = client.search.query("contentclass:STS_Site").execute_query()
results = result.value.PrimaryQueryResult.RelevantResults
for row in results.Table.Rows:
site_url = row.Cells["Path"]
print(site_url)
5 changes: 5 additions & 0 deletions office365/sharepoint/apps/access_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.sharepoint.entity import Entity


class AccessRequests(Entity):
""" """
20 changes: 18 additions & 2 deletions office365/sharepoint/lists/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from office365.sharepoint.lists.creatables_info import CreatablesInfo
from office365.sharepoint.lists.data_source import ListDataSource
from office365.sharepoint.lists.rule import SPListRule
from office365.sharepoint.lists.version_policy_manager import VersionPolicyManager
from office365.sharepoint.navigation.configured_metadata_items import (
ConfiguredMetadataNavigationItemCollection,
)
Expand Down Expand Up @@ -131,8 +132,8 @@ def _save_schema():
"FileSystemObjectType",
]
)
# .expand(["File", "Folder"])
.get().paged(page_loaded=_export_items)
.get()
.paged(page_loaded=_export_items)
)

self.ensure_properties(["SchemaXml", "RootFolder"], _save_schema)
Expand Down Expand Up @@ -1128,6 +1129,16 @@ def user_custom_actions(self):
),
)

@property
def version_policies(self):
""" """
return self.properties.get(
"VersionPolicies",
VersionPolicyManager(
self.context, ResourcePath("VersionPolicies", self.resource_path)
),
)

@property
def custom_action_elements(self):
return self.properties.get(
Expand Down Expand Up @@ -1408,6 +1419,7 @@ def get_property(self, name, default_value=None):
"RootFolder": self.root_folder,
"TitleResource": self.title_resource,
"UserCustomActions": self.user_custom_actions,
"VersionPolicies": self.version_policies,
}
default_value = property_mapping.get(name, None)
return super(List, self).get_property(name, default_value)
Expand All @@ -1420,4 +1432,8 @@ def set_property(self, name, value, persist_changes=True):
self._resource_path = self.parent_collection.get_by_id(
value
).resource_path
elif name == "Url":
self._resource_path = ServiceOperationPath(
"getList", [value], self.context.web.resource_path
)
return self
5 changes: 5 additions & 0 deletions office365/sharepoint/lists/version_policy_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.sharepoint.entity import Entity


class VersionPolicyManager(Entity):
""" """
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.entity_collection import EntityCollection
from office365.sharepoint.userprofiles.sharedwithme.document import SharedWithMeDocument


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

@staticmethod
def get_shared_with_group_docs(context, group_id=None):
"""
Gets a shared documents for a group.
:param office365.sharepoint.client_context.ClientContext context: SharePoint context
:param str group_id:
"""
return_type = EntityCollection(context, SharedWithMeDocument)
payload = {"groupId": group_id}
qry = ServiceOperationQuery(
DocumentsSharedWithGroup(context),
"GetSharedWithGroupDocs",
None,
payload,
None,
return_type,
True,
)
context.add_query(qry)
return return_type

@property
def entity_type_name(self):
return "Microsoft.SharePoint.Portal.UserProfiles.DocumentsSharedWithGroup"
return "Microsoft.SharePoint.Portal.UserProfiles.group_id"
8 changes: 8 additions & 0 deletions office365/sharepoint/publishing/pages/coauth_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from office365.runtime.client_value import ClientValue


class SitePageCoAuthState(ClientValue):

@property
def entity_type_name(self):
return "SP.Publishing.SitePageCoAuthState"
11 changes: 11 additions & 0 deletions office365/sharepoint/publishing/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.runtime.types.collections import StringCollection
from office365.sharepoint.publishing.pages.coauth_state import SitePageCoAuthState
from office365.sharepoint.publishing.pages.fields_data import SitePageFieldsData
from office365.sharepoint.publishing.pages.metadata import SitePageMetadata
from office365.sharepoint.translation.status_collection import (
Expand Down Expand Up @@ -135,6 +136,16 @@ def save_page_as_template(self):
self.context.add_query(qry)
return return_type

def save_page_co_auth(self, page_stream):
""" """
return_type = ClientResult(self.context, SitePageCoAuthState())
payload = {"pageStream": page_stream}
qry = ServiceOperationQuery(
self, "SavePageCoAuth", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type

def demote_from_news(self):
"""
Updates the promoted state of the site page to 0. On success MUST return true.
Expand Down
9 changes: 9 additions & 0 deletions office365/sharepoint/publishing/pages/stream_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.runtime.client_value import ClientValue


class SitePageStreamContent(ClientValue):
""" """

@property
def entity_type_name(self):
return "SP.Publishing.SitePageStreamContent"
8 changes: 8 additions & 0 deletions office365/sharepoint/publishing/pages/stream_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from office365.runtime.client_value import ClientValue


class SitePageStreamData(ClientValue):

@property
def entity_type_name(self):
return "SP.Publishing.SitePageStreamData"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from office365.sharepoint.entity import Entity


class NonQuotaBackfillApi(Entity):

@property
def entity_type_name(self):
return "Microsoft.SharePoint.QuotaManagement.Consumer.NonQuotaBackfillApi"
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from office365.runtime.client_result import ClientResult
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity


class SiteContentProcessingInfoProvider(Entity):

def get_azure_container_token(self):
return_type = ClientResult(self.context, str())
qry = ServiceOperationQuery(
self, "GetAzureContainerToken", None, None, None, return_type
)
self.context.add_query(qry)
return return_type

@property
def entity_type_name(self):
return "Microsoft.SharePoint.Client.Search.Administration.SiteContentProcessingInfoProvider"
1 change: 1 addition & 0 deletions office365/sharepoint/search/ranking_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def add_judgment(self, user_query, url, label_id):
return self

def normalize_result_url(self, url):
# type: (str) -> ClientResult[str]
"""
A URL string after normalization. The input and output URL strings MUST resolve to the same document.
Expand Down
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions office365/sharepoint/search/reports/abandonedqueries/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.runtime.client_value import ClientValue


class ReportAbandonedQueriesItem(ClientValue):
pass
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions office365/sharepoint/search/reports/top_queries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from office365.runtime.client_value_collection import ClientValueCollection
from office365.sharepoint.search.reports.base import ReportBase
from office365.sharepoint.search.reports.topqueries.item import ReportTopQueriesItem


class ReportTopQueries(ReportBase):

def __init__(self, reports=None):
super(ReportTopQueries, self).__init__()
self.Reports = ClientValueCollection(ReportTopQueriesItem, reports)

@property
def entity_type_name(self):
return "Microsoft.Office.Server.Search.REST.ReportTopQueries"
Empty file.
9 changes: 9 additions & 0 deletions office365/sharepoint/search/reports/topqueries/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.runtime.client_value import ClientValue


class ReportTopQueriesData(ClientValue):
""" """

@property
def entity_type_name(self):
return "Microsoft.Office.Server.Search.REST.ReportTopQueriesData"
15 changes: 15 additions & 0 deletions office365/sharepoint/search/reports/topqueries/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from office365.runtime.client_value import ClientValue
from office365.runtime.client_value_collection import ClientValueCollection
from office365.sharepoint.search.reports.topqueries.data import ReportTopQueriesData


class ReportTopQueriesItem(ClientValue):
""" """

def __init__(self, date=None, report=None):
self.Date = date
self.Report = ClientValueCollection(ReportTopQueriesData, report)

@property
def entity_type_name(self):
return "Microsoft.Office.Server.Search.REST.ReportTopQueriesItem"
9 changes: 9 additions & 0 deletions office365/sharepoint/search/scs_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.runtime.client_value import ClientValue


class ScsEndpoint(ClientValue):
""" """

@property
def entity_type_name(self):
return "Microsoft.Office.Server.Search.REST.ScsEndpoint"
25 changes: 25 additions & 0 deletions office365/sharepoint/sites/version_policy_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.lists.version_policy_manager import VersionPolicyManager


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

@property
def version_policies(self):
return self.properties.get(
"VersionPolicies",
VersionPolicyManager(
self.context, ResourcePath("VersionPolicies", self.resource_path)
),
)

def inherit_tenant_settings(self):
""" """
qry = ServiceOperationQuery(self, "InheritTenantSettings")
self.context.add_query(qry)
return self

def set_auto_expiration(self):
""""""
qry = ServiceOperationQuery(self, "SetAutoExpiration")
self.context.add_query(qry)
return self

def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"VersionPolicies": self.version_policies,
}
default_value = property_mapping.get(name, None)
return super(SiteVersionPolicyManager, self).get_property(name, default_value)
17 changes: 17 additions & 0 deletions office365/sharepoint/sitescripts/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ def create_list_design(context, info):
context.add_query(qry)
return return_type

@staticmethod
def get_list_designs(context, store=None):
"""
Gets a list designs.
:param office365.sharepoint.client_context.ClientContext context: SharePoint context
:param str store:
"""
return_type = ClientResult(context, SiteDesignMetadata())
utility = SiteScriptUtility(context)
payload = {"store": store}
qry = ServiceOperationQuery(
utility, "GetListDesigns", None, payload, None, return_type, True
)
context.add_query(qry)
return return_type

@staticmethod
def add_site_design_task(context, web_url, site_design_id):
"""
Expand Down
Empty file.
Loading

0 comments on commit 70e6fe8

Please sign in to comment.