Skip to content

Commit

Permalink
typings enhancements, new examples (get folder author)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Nov 19, 2023
1 parent c217252 commit b9d91e0
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 168 deletions.
17 changes: 8 additions & 9 deletions examples/sharepoint/folders/get_system_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
folder_url = "Shared Documents/Archive"

list_title = "Docs"
folder_path = "Archive" # folder relative path
folder_item = (
ctx.web.get_folder_by_server_relative_url(folder_url)
.list_item_all_fields.get()
.execute_query()
)
author = (
ctx.web.site_users.get_by_id(folder_item.get_property("AuthorId"))
ctx.web.lists.get_by_title(list_title)
.get_item_by_url(folder_path)
.select(["Author/Title"])
.expand(["Author"])
.get()
.execute_query()
)
print(author)

print(folder_item.properties.get("Author"))
24 changes: 24 additions & 0 deletions examples/sharepoint/lists/assessment/broken_tax_field_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Demonstrates how to perform list/library assessment if taxonomy field value association is broken
to term set or not.
To prevent this exception to occur:
'-2146232832, Microsoft.SharePoint.SPFieldValidationException', 'The given guid does not exist in the term store'
"""
from office365.runtime.client_request_exception import ClientRequestException
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.taxonomy.field import TaxonomyField
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
lib = ctx.web.default_document_library()
fields = lib.fields.get().execute_query()
for field in fields:
if not isinstance(field, TaxonomyField):
continue
try:
items = lib.items.select([field.internal_name]).top(1).get().execute_query()
print(field.internal_name)
except ClientRequestException:
print(field.is_term_set_valid)
print("Error: {0}".format(field.internal_name))
93 changes: 69 additions & 24 deletions generator/metadata/SharePoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8226,6 +8226,9 @@
<FunctionImport Name="Active" ReturnType="Collection(SP.Publishing.AnnouncementsData)" IsSideEffecting="false" IsBindable="true">
<Parameter Name="this" Type="SP.Publishing.AnnouncementsController"/>
</FunctionImport>
<FunctionImport Name="Channel" ReturnType="Collection(SP.Publishing.ChannelAnnouncement)" IsSideEffecting="false" IsBindable="true">
<Parameter Name="this" Type="SP.Publishing.AnnouncementsController"/>
</FunctionImport>
<FunctionImport Name="SP_Publishing_CampaignPublicationCollection" ReturnType="Collection(SP.Publishing.CampaignPublication)" IsComposable="true" EntitySet="SitePageMetadatas"/>
<FunctionImport Name="BoostNews" IsBindable="true">
<Parameter Name="this" Type="SP.Publishing.CampaignPublication"/>
Expand Down Expand Up @@ -10619,6 +10622,9 @@
<Parameter Name="id" Type="Edm.Guid" Nullable="false"/>
<Parameter Name="store" Type="Edm.Int32" Nullable="false"/>
</FunctionImport>
<FunctionImport Name="Microsoft_SharePoint_Utilities_WebTemplateExtensions_SiteScriptUtility_GetSiteScriptPackageFile" ReturnType="Edm.Stream">
<Parameter Name="id" Type="Edm.Guid" Nullable="false"/>
</FunctionImport>
<FunctionImport Name="Microsoft_SharePoint_Utilities_WebTemplateExtensions_SiteScriptUtility_GetSiteScripts" ReturnType="Collection(Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptMetadata)">
<Parameter Name="store" Type="Edm.Int32" Nullable="false"/>
</FunctionImport>
Expand Down Expand Up @@ -14006,7 +14012,6 @@
<Parameter Name="uploadId" Type="Edm.Guid" Nullable="false"/>
<Parameter Name="fileOffset" Type="Edm.Int64" Nullable="false"/>
<Parameter Name="stream" Type="Edm.Stream"/>
<Parameter Name="sandboxId" Type="Edm.Guid" Nullable="false"/>
</FunctionImport>
<FunctionImport Name="FinishUploadWithChecksum" ReturnType="SP.File" IsBindable="true" EntitySet="Files12">
<Parameter Name="this" Type="SP.File"/>
Expand Down Expand Up @@ -15990,6 +15995,10 @@
<Parameter Name="this" Type="Microsoft.Online.SharePoint.TenantAdministration.Tenant"/>
<Parameter Name="reportId" Type="Edm.Int32" Nullable="false"/>
</FunctionImport>
<FunctionImport Name="DeleteSPOContainerTypeById" IsBindable="true">
<Parameter Name="this" Type="Microsoft.Online.SharePoint.TenantAdministration.Tenant"/>
<Parameter Name="containerTypeId" Type="Edm.Guid" Nullable="false"/>
</FunctionImport>
<FunctionImport Name="DisableCollaborationInsightsDataCollection" IsBindable="true">
<Parameter Name="this" Type="Microsoft.Online.SharePoint.TenantAdministration.Tenant"/>
</FunctionImport>
Expand Down Expand Up @@ -19424,6 +19433,18 @@
<Annotations Target="SP.Publishing.AcronymInformation">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.AnnouncementAuthor">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.AnnouncementAuthor/Email">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.AnnouncementAuthor/ID">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.AnnouncementAuthor/Name">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.CallToAction/Text">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
Expand Down Expand Up @@ -19562,6 +19583,33 @@
<Annotations Target="SP.Publishing.CampaignPublicationMailDraftData/GroupUpn">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/Author">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/CallToAction">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/ChannelName">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/Icon">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/ID">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/Message">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/PublishStartDate">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.ChannelAnnouncement/Title">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.Publishing.CopyToParams">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
Expand Down Expand Up @@ -25251,6 +25299,9 @@
<Annotations Target="SP.ApiData/Microsoft_SharePoint_Utilities_WebTemplateExtensions_SiteScriptUtility_GetSiteScriptMetadata(Edm.Guid, Edm.Int32)">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.ApiData/Microsoft_SharePoint_Utilities_WebTemplateExtensions_SiteScriptUtility_GetSiteScriptPackageFile(Edm.Guid)">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
<Annotations Target="SP.ApiData/Microsoft_SharePoint_Utilities_WebTemplateExtensions_SiteScriptUtility_GetSiteScripts(Edm.Int32)">
<ValueAnnotation Term="Com.Microsoft.VisualStudio.CodeGen.IsBeta" Bool="true"/>
</Annotations>
Expand Down Expand Up @@ -30776,6 +30827,11 @@
<Property Name="Lcid" Type="Edm.Int32" Nullable="false"/>
<Property Name="Text" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="AnnouncementAuthor">
<Property Name="Email" Type="Edm.String"/>
<Property Name="ID" Type="Edm.String"/>
<Property Name="Name" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="AnnouncementsData">
<Property Name="CallToAction" Type="SP.Publishing.CallToAction"/>
<Property Name="Dismissable" Type="Edm.Boolean" Nullable="false"/>
Expand Down Expand Up @@ -30845,6 +30901,17 @@
<Property Name="DraftId" Type="Edm.String"/>
<Property Name="GroupUpn" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="ChannelAnnouncement">
<Property Name="Author" Type="SP.Publishing.AnnouncementAuthor"/>
<Property Name="CallToAction" Type="SP.Publishing.CallToAction"/>
<Property Name="ChannelName" Type="Edm.String"/>
<Property Name="Icon" Type="SP.Publishing.Icon"/>
<Property Name="ID" Type="Edm.Int64" Nullable="false"/>
<Property Name="IsRead" Type="Edm.Boolean" Nullable="false"/>
<Property Name="Message" Type="Edm.String"/>
<Property Name="PublishStartDate" Type="Edm.String"/>
<Property Name="Title" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="CopyToParams">
<Property Name="AsNews" Type="Edm.Boolean" Nullable="false"/>
<Property Name="AsPrivateAuthoringPage" Type="Edm.Boolean" Nullable="false"/>
Expand Down Expand Up @@ -35608,6 +35675,7 @@
</ComplexType>
<ComplexType Name="SPContainerProperties">
<Property Name="AllowEditing" Type="Edm.Boolean" Nullable="false"/>
<Property Name="AuthenticationContextName" Type="Edm.String"/>
<Property Name="BlockDownloadPolicy" Type="Edm.Boolean" Nullable="false"/>
<Property Name="ConditionalAccessPolicy" Type="Edm.Int32" Nullable="false"/>
<Property Name="ContainerApiUrl" Type="Edm.String"/>
Expand Down Expand Up @@ -38100,12 +38168,6 @@
<PropertyRef Name="AddressbarLinkPermission"/>
</Key>
<Property Name="AddressbarLinkPermission" Type="Edm.Int32" Nullable="false"/>
<Property Name="AIBuilderDefaultPowerAppsEnvironment" Type="Edm.String"/>
<Property Name="AIBuilderEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="AIBuilderEnabledInContentCenter" Type="Edm.Int32" Nullable="false"/>
<Property Name="AIBuilderSiteInfoList" Type="Collection(Microsoft.Online.SharePoint.TenantAdministration.SiteInfoForSitePicker)"/>
<Property Name="AIBuilderSiteList" Type="Collection(Edm.Guid)" Nullable="false"/>
<Property Name="AIBuilderSiteListFileName" Type="Edm.String"/>
<Property Name="AllowAnonymousMeetingParticipantsToAccessWhiteboards" Type="Edm.Int32" Nullable="false"/>
<Property Name="AllowCommentsTextOnEmailEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="AllowDownloadingNonWebViewableFiles" Type="Edm.Boolean" Nullable="false"/>
Expand Down Expand Up @@ -38175,10 +38237,6 @@
<Property Name="DisableSpacesActivation" Type="Edm.Boolean" Nullable="false"/>
<Property Name="DisableVivaConnectionsAnalytics" Type="Edm.Boolean" Nullable="false"/>
<Property Name="DisplayStartASiteOption" Type="Edm.Boolean" Nullable="false"/>
<Property Name="DocumentUnderstandingEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="DocumentUnderstandingSiteInfoList" Type="Collection(Microsoft.Online.SharePoint.TenantAdministration.SiteInfoForSitePicker)"/>
<Property Name="DocumentUnderstandingSiteList" Type="Collection(Edm.Guid)" Nullable="false"/>
<Property Name="DocumentUnderstandingSiteListFileName" Type="Edm.String"/>
<Property Name="EmailAttestationEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="EmailAttestationReAuthDays" Type="Edm.Int32" Nullable="false"/>
<Property Name="EmailAttestationRequired" Type="Edm.Boolean" Nullable="false"/>
Expand Down Expand Up @@ -38235,15 +38293,6 @@
<Property Name="NotificationsInSharePointEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="NotifyOwnersWhenInvitationsAccepted" Type="Edm.Boolean" Nullable="false"/>
<Property Name="NotifyOwnersWhenItemsReshared" Type="Edm.Boolean" Nullable="false"/>
<Property Name="OCRAdminSiteInfoList" Type="Collection(Microsoft.Online.SharePoint.TenantAdministration.SiteInfoForSitePicker)"/>
<Property Name="OCRAdminSiteList" Type="Collection(Edm.Guid)" Nullable="false"/>
<Property Name="OCRAdminSiteListFileName" Type="Edm.String"/>
<Property Name="OCRComplianceSiteInfoList" Type="Collection(Microsoft.Online.SharePoint.TenantAdministration.SiteInfoForSitePicker)"/>
<Property Name="OCRComplianceSiteList" Type="Collection(Edm.Guid)" Nullable="false"/>
<Property Name="OCRComplianceSiteListFileName" Type="Edm.String"/>
<Property Name="OCRModeForAdminSites" Type="Edm.Int32" Nullable="false"/>
<Property Name="OCRModeForComplianceODBs" Type="Edm.Int32" Nullable="false"/>
<Property Name="OCRModeForComplianceSites" Type="Edm.Int32" Nullable="false"/>
<Property Name="ODBAccessRequests" Type="Edm.Int32" Nullable="false"/>
<Property Name="ODBMembersCanShare" Type="Edm.Int32" Nullable="false"/>
<Property Name="ODBSensitivityRefreshWindowInHours" Type="Edm.Int32" Nullable="false"/>
Expand All @@ -38260,10 +38309,6 @@
<Property Name="OneDriveRequestFilesLinkEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="OneDriveRequestFilesLinkExpirationInDays" Type="Edm.Int32" Nullable="false"/>
<Property Name="OwnerAnonymousNotification" Type="Edm.Boolean" Nullable="false"/>
<Property Name="PrebuiltEnabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="PrebuiltSiteInfoList" Type="Collection(Microsoft.Online.SharePoint.TenantAdministration.SiteInfoForSitePicker)"/>
<Property Name="PrebuiltSiteList" Type="Collection(Edm.Guid)" Nullable="false"/>
<Property Name="PrebuiltSiteListFileName" Type="Edm.String"/>
<Property Name="PreventExternalUsersFromResharing" Type="Edm.Boolean" Nullable="false"/>
<Property Name="ProvisionSharedWithEveryoneFolder" Type="Edm.Boolean" Nullable="false"/>
<Property Name="PublicCdnAllowedFileTypes" Type="Edm.String"/>
Expand Down
8 changes: 2 additions & 6 deletions office365/onedrive/permissions/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def _add():

def delete(self, roles, identity):
# type: (list[str], Application|User|Group|Device) -> Permission
"""
Deletes the permission.
"""
"""Deletes the permission."""

def _delete(col):
pass
Expand All @@ -85,9 +83,7 @@ def _identity_loaded():
return self

def delete_all(self):
"""
Remove all access to resource
"""
"""Remove all access to resource"""

def _after_loaded(return_type):
# type: (PermissionCollection) -> None
Expand Down
3 changes: 1 addition & 2 deletions office365/runtime/client_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def get(self):
def is_property_available(self, name):
# type: (str) -> bool
"""Returns a Boolean value that indicates whether the specified property has been retrieved or set.
:param str name: A property name
"""
if name in self.properties:
Expand All @@ -116,7 +115,7 @@ def select(self, names):

def remove_from_parent_collection(self):
if self._parent_collection is None:
return
return self
self._parent_collection.remove_child(self)
return self

Expand Down
30 changes: 15 additions & 15 deletions office365/runtime/client_object_collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Generic, Iterator, List, Optional, Type, TypeVar
from typing import Any, Callable, Generic, Iterator, List, Optional, Type, TypeVar

from typing_extensions import Self

Expand Down Expand Up @@ -110,7 +110,6 @@ def filter(self, expression):
# type: (str) -> Self
"""
Allows clients to filter a collection of resources that are addressed by a request URL
:param str expression: Filter expression, for example: 'Id eq 123'
"""
self.query_options.filter = expression
Expand All @@ -134,24 +133,26 @@ def skip(self, value):

def top(self, value):
# type: (int) -> Self
"""
Specifies the number of items in the queried collection to be included in the result
"""
"""Specifies the number of items in the queried collection to be included in the result"""
self.query_options.top = value
return self

def paged(self, page_size=None, page_loaded=None):
# type: (int, Callable[[Self], None]) -> Self
"""
Retrieves via server-driven paging mode
"""
"""Retrieves via server-driven paging mode"""
self._paged_mode = True
if callable(page_loaded):
self._page_loaded += page_loaded
if page_size:
self.top(page_size)
return self

def after_execute(self, action, *args, **kwargs):
# type: (Callable[[Self, Any, Any], None], Any, Any) -> Self
super(ClientObjectCollection, self).after_execute(action, *args, **kwargs)
self._page_loaded += action
return self

def get(self):
# type: () -> Self

Expand Down Expand Up @@ -196,22 +197,22 @@ def _construct_request(request):
def first(self, expression):
# type: (str) -> T
"""Return the first Entity instance that matches current query
:param str expression: Filter expression
"""
return_type = self.create_typed_object()
self.add_child(return_type)
key = return_type.property_ref_name

def _after_loaded(col):
# type: (ClientObjectCollection) -> None
if len(col) < 1:
message = "Not found for filter: {0}".format(self.query_options.filter)
raise ValueError(message)
return_type.set_property(key, col[0].get_property(key))
[
return_type.set_property(k, v, False)
for k, v in col[0].properties.items()
]

self.filter(expression).top(1)
self.context.load(self, [key], after_loaded=_after_loaded)
self.get().filter(expression).top(1).after_execute(_after_loaded)
return return_type

def single(self, expression):
Expand All @@ -237,8 +238,7 @@ def _after_loaded(col):
for k, v in col[0].properties.items()
]

self.filter(expression).top(2)
self.context.load(self, after_loaded=_after_loaded)
self.get().filter(expression).top(2).after_execute(_after_loaded)
return return_type

@property
Expand Down
Loading

0 comments on commit b9d91e0

Please sign in to comment.