Skip to content

Commit 610e83c

Browse files
committed
fix: assert target_user.id before passing to get_user_by_id for type safety
1 parent 5223944 commit 610e83c

31 files changed

Lines changed: 110 additions & 121 deletions

File tree

examples/sharepoint/lists/read_items_with_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
list_title = "Site Pages"
1313
site_pages = ctx.web.lists.get_by_title(list_title)
1414
from_datetime = datetime.datetime(2022, 1, 20, 0, 0)
15-
filter_text = "Created gt datetime'{0}'".format(from_datetime.isoformat())
15+
filter_text = f"Created gt datetime'{from_datetime.isoformat()}'"
1616
include_fields = ["Created", "EncodedAbsUrl"]
1717
items = site_pages.items.filter(filter_text).select(include_fields).get().execute_query()
18-
print("Loaded items count: {0}".format(len(items)))
18+
print(f"Loaded items count: {len(items)}")
1919
for item in items:
2020
print(item.properties["EncodedAbsUrl"])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["SP.FileCreationInformation", "SP.ListDataValidationFailure", "SP.CoAuthConfiguration", "SP.FieldGeolocationValue", "SP.ItemOrderUpdateValue", "SP.AgreementWorkFlowResponse", "SP.AccessRequestResponse", "SP.FieldUrlValue", "SP.CustomerKeyInfo", "SP.DashboardItemInfo", "SP.GridInitInfoType", "SP.AutoLabellingWorkInformation", "SP.CustomizedFormsPage", "SP.AgreementMetaData", "SP.KnowledgeHubSiteReference", "SP.CurrencyInformationCollection", "SP.OwnedByMeParams", "SP.SPMoveAndShareFileInfo", "SP.RequestedTranslation", "SP.RecipientLimitsInfo", "SP.HomeSitesDetails", "SP.DestinationLibraryInfo", "SP.ActionSubmit", "SP.SPTeamChannelCapabilities", "SP.ContentTypeEntityData", "SP.AgreementCountryResponse", "SP.CreatableItemInfo", "SP.CreateTemplateResponse", "SP.AgreementSummaryData", "SP.AdaptiveCard", "SP.PortalAndOrgNewsSiteReference", "SP.SiteSuggestionResponse", "SP.ActionSet", "SP.DocumentGenerationInfo", "SP.ListItemComplianceInfo", "SP.MultiGeoCopyParameters", "SP.AttachmentCreationInformation", "SP.CustomerKeyVaultInfo", "SP.ContentTypeId", "SP.ClassificationResult", "SP.AgreementsSolutionEnabledSitesResponse", "SP.SharePointIds", "SP.AgreementPermissionsData", "SP.AgreementLocationData", "SP.DesktopSettings", "SP.ColumnSet", "SP.FieldCalculatedErrorValue", "SP.VivaHomeTitleRegion", "SP.EngageDistributionInfo", "SP.Snippet", "SP.BaseRequestParams", "SP.ApprovalsProperties", "SP.CAAESnippetElement", "SP.BasePermissions", "SP.PublishModernTemplatePayload", "SP.SharedWithUser", "SP.SiteSuggestionItem", "SP.NgspRequestParams", "SP.CreateAgreementFolderInfo", "SP.OrganizationNewsSiteReference", "SP.ActionToggleVisibility", "SP.FontOption", "SP.AppLicense", "SP.SharingLinkData", "SP.EffectiveBasePermissions", "SP.FollowedSitesParams", "SP.SimpleDataRow", "SP.AdaptiveCardColumn", "SP.CustomerKeyStatusInfo", "SP.ChangeToken", "SP.SPAgreementsSite", "SP.CopyMigrationOptions", "SP.ManageChannelCapabilitiesRequest", "SP.SPHSiteReference", "SP.AgreementDocumentsInfo", "SP.BrandCenterConfiguration", "SP.CAFieldValue", "SP.AgreementImportData", "SP.AdaptiveCardAction", "SP.EnqueueJobInformation", "SP.DocumentLocation", "SP.FieldLookupValue", "SP.RestrictAccessControlUpdate", "SP.InputChoiceSet", "SP.PlaceholderV2", "SP.ActionShowCard", "SP.ConfigurationData", "SP.Container", "SP.TargetedSiteDetails", "SP.RelatedItem", "SP.CreatableItemInfoCollection", "SP.SimpleDataTable", "SP.SemanticSearchCrawlerEnqueueItem", "SP.ScriptSafeDomainEntityData", "SP.SiteAISettings", "SP.VivaConnectionsLicense", "SP.CurrencyInformation", "SP.CustomizedFormsPageCollection", "SP.SharingLinkInfo", "SP.FieldUserValue", "SP.TabItem", "SP.InsertFieldResponse", "SP.MobileSettings", "SP.CardElement", "SP.Placeholder", "SP.PublishTemplateV2Payload", "SP.CAAEFieldElement", "SP.CustomActionElement", "SP.AgreementLocation", "SP.FieldValuesWithUrl", "SP.AdaptiveCardImage", "SP.LockFileData", "SP.AgreementDataPair", "SP.FieldRatingScaleQuestionAnswer", "SP.ContentAssemblyModernTemplateColumnsMappingInfo", "SP.AppViewCreationInfo", "SP.CopyMigrationInfo", "SP.AgreementDocument", "SP.UserIdInfo", "SP.CustomActionElementCollection", "SP.ApprovalsCreateRequestParameters", "SP.ActionOpenUrl", "SP.ContentControlInfo", "SP.SiteAISettingsRequest", "SP.GetNextAgreementWorkFlowRequest", "SP.RestrictContentOrgWidePolicyUpdate", "SP.ChangeLogItemQuery", "SP.ContentAssemblyFileInfo", "SP.CreateHVCSItemApprovalRequestParameters", "SP.HomeSiteReference", "SP.AgreementReportBaseData", "SP.CountByDate", "SP.AgreementSearchParameters", "SP.IngestionTaskKey", "SP.PivotItem", "SP.SmartTemplateContentType", "SP.PowerPlatformEnvironment", "SP.ExceptionDetails", "SP.AppSiteContext", "SP.EventReceiverDefinitionCreationInformation", "SP.DashboardItem", "SP.VivaConnectionsUrlConfiguration", "SP.HTMLFieldSecuritySetting", "SP.FieldCreationInformation", "SP.ContentAssemblyFormAnswer", "SP.AppLicenseCollection", "SP.AgreementsSolutionFileContext", "SP.AdditionalAccessStatusResponse", "SP.ActionHttp", "SP.AsyncReadJobInfo", "SP.SiteTemplate", "SP.ContextWebInformation", "SP.Audience", "SP.InputChoice", "SP.DocumentLibraryInformation", "SP.AsyncReadOptions", "SP.ChannelCapabilities", "SP.ContentTypeCreationInformation", "SP.HomeSiteNavConfiguration", "SP.SPAgreementResults", "SP.ChangeQuery", "SP.SharedWithUserCollection", "SP.InputText", "SP.RecentSitesParams", "SP.LibraryDetails", "SP.SuggestedSitesParams", "SP.AppProperties", "SP.FavoritedItemsParams", "SP.RecentFilesParams", "SP.Padding", "SP.AgreementReportFilter", "SP.AppSettingsInTeams", "SP.PublishSnippetPayload", "SP.ResourceVisualization", "SP.ColumnTypeInfo", "SP.MainLinkDetails", "SP.CopyJobProgress", "SP.EncryptionOption", "SP.AlertCreationInformation"]
1+
["SP.AsyncReadJobInfo", "SP.CustomerKeyVaultInfo", "SP.BasePermissions", "SP.FileCollectionAddParameters", "SP.EffectiveBasePermissions", "SP.CustomerKeyStatusInfo", "SP.MainLinkDetails", "SP.ContextWebInformation", "SP.FileVersionBatchDeleteParameters", "SP.PortalAndOrgNewsSiteReference", "SP.ActionShowCard", "SP.MobileSettings", "SP.AdditionalAccessStatusResponse", "SP.ListItemDeleteParameters", "SP.FieldUrlValue", "SP.SPInvitationCreationResult", "SP.CardElement", "SP.UserIdInfo", "SP.VivaHomeTitleRegion", "SP.AgreementSummaryData", "SP.ScriptSafeDomainEntityData", "SP.CurrencyInformationCollection", "SP.RecentFilesParams", "SP.FollowedSitesParams", "SP.ActionSubmit", "SP.ActionOpenUrl", "SP.FontOption", "SP.EventReceiverDefinitionCreationInformation", "SP.AppSiteContext", "SP.DashboardItemInfo", "SP.FieldRatingScaleQuestionAnswer", "SP.LabelAccessControlData", "SP.SiteAISettingsRequest", "SP.FieldGeolocationValue", "SP.ActionToggleVisibility", "SP.PublishTemplateV2Payload", "SP.AgreementDataPair", "SP.FieldCalculatedErrorValue", "SP.CustomerKeyInfo", "SP.CopyMigrationOptions", "SP.CreatableItemInfoCollection", "SP.SPListItemVersionChange", "SP.ChangeLogItemQuery", "SP.DocumentGenerationInfo", "SP.ChangeQuery", "SP.SharePointIds", "SP.GetListItemVersionsParameters", "SP.ActionSet", "SP.InputChoice", "SP.RestrictContentOrgWidePolicyUpdate", "SP.NgspRequestParams", "SP.SharingLinkData", "SP.DocumentLocation", "SP.AgreementReportFilter", "SP.TargetedSiteDetails", "SP.Container", "SP.ListItemCreationInformationUsingPath", "SP.ListDataValidationFailure", "SP.CAFieldValue", "SP.FieldValuesWithUrl", "SP.FontPackageCreationParameters", "SP.IngestionTaskKey", "SP.RequestedTranslation", "SP.SPHSiteReference", "SP.ListItemComplianceInfo", "SP.FolderDeleteParameters", "SP.AdaptiveCardColumn", "SP.ClassificationResult", "SP.AppLicense", "SP.EngageDistributionInfo", "SP.ColumnSet", "SP.SmartTemplateContentType", "SP.Language", "SP.CustomizedFormsPageCollection", "SP.AgreementMetaData", "SP.ContentTypeEntityData", "SP.AgreementLocationData", "SP.DesktopSettings", "SP.ExceptionDetails", "SP.FolderCollectionAddParameters", "SP.ListItemCreationInformation", "SP.LibraryDetails", "SP.ListCreationInformation", "SP.FavoritedItemsParams", "SP.Padding", "SP.CreatableItemInfo", "SP.AgreementDocument", "SP.ApprovalsCreateRequestParameters", "SP.OwnedByMeParams", "SP.CAAEFieldElement", "SP.FileCreationInformation", "SP.AgreementsSolutionFileContext", "SP.PivotItem", "SP.AgreementLocation", "SP.CreateHVCSItemApprovalRequestParameters", "SP.BrandCenterConfiguration", "SP.AgreementDocumentsInfo", "SP.ListItemFormUpdateValue", "SP.CustomizedFormsPage", "SP.SPMoveAndShareFileInfo", "SP.Snippet", "SP.ListItemCollectionPosition", "SP.SemanticSearchCrawlerEnqueueItem", "SP.HomeSiteNavConfiguration", "SP.SPImageItem", "SP.FieldCreationInformation", "SP.ListCollectionPosition", "SP.GetListsParameters", "SP.ResourceVisualization", "SP.ContentAssemblyFileInfo", "SP.ActionHttp", "SP.ColumnTypeInfo", "SP.FieldUserValue", "SP.AppLicenseCollection", "SP.SPAgreementResults", "SP.BaseRequestParams", "SP.SharedWithUser", "SP.AgreementReportBaseData", "SP.AgreementPermissionsData", "SP.CountByDate", "SP.ContentAssemblyModernTemplateColumnsMappingInfo", "SP.EnqueueJobInformation", "SP.Audience", "SP.ListItemUpdateResults", "SP.AlertCreationInformation", "SP.ChangeToken", "SP.ListDataValidationExceptionValue", "SP.HTMLFieldSecuritySetting", "SP.SPAgreementsSite", "SP.DashboardItem", "SP.TabItem", "SP.AsyncReadOptions", "SP.ListForm", "SP.ListDataSource", "SP.PlaceholderV2", "SP.CopyMigrationInfo", "SP.FolderColoringInformation", "SP.CreateAgreementFolderInfo", "SP.ManageChannelCapabilitiesRequest", "SP.RelatedItem", "SP.InputText", "SP.SPRuleUserInfo", "SP.EncryptionOption", "SP.ConfigurationData", "SP.SharingLinkInfo", "SP.CustomActionElementCollection", "SP.PublishModernTemplatePayload", "SP.OrganizationNewsSiteReference", "SP.AgreementCountryResponse", "SP.AppViewCreationInfo", "SP.ContentControlInfo", "SP.AgreementSearchParameters", "SP.VivaConnectionsUrlConfiguration", "SP.SiteSuggestionItem", "SP.FileDeleteParameters", "SP.DestinationLibraryInfo", "SP.CoAuthConfiguration", "SP.DocumentLibraryInformation", "SP.FieldLookupValue", "SP.ContentTypeId", "SP.HomeSitesDetails", "SP.AdaptiveCardImage", "SP.GetNextAgreementWorkFlowRequest", "SP.CurrencyInformation", "SP.RestrictAccessControlUpdate", "SP.ChannelCapabilities", "SP.CopyJobProgress", "SP.AgreementsSolutionEnabledSitesResponse", "SP.ListItemUpdateParameters", "SP.AttachmentCreationInformation", "SP.InsertFieldResponse", "SP.ItemOrderUpdateValue", "SP.Placeholder", "SP.GroupCreationInformation", "SP.SPFocalPoint", "SP.AdaptiveCard", "SP.AutoLabellingWorkInformation", "SP.SimpleDataRow", "SP.SharedWithUserCollection", "SP.SPTeamChannelCapabilities", "SP.CAAESnippetElement", "SP.CreateTemplateResponse", "SP.InputChoiceSet", "SP.SiteTemplate", "SP.SuggestedSitesParams", "SP.MachineLearningSampleMeta", "SP.AgreementWorkFlowResponse", "SP.SPListRule", "SP.PowerPlatformEnvironment", "SP.SiteSuggestionResponse", "SP.MultiGeoCopyParameters", "SP.ListItemVersionCollectionPosition", "SP.KnowledgeHubSiteReference", "SP.HubSiteCreationInformation", "SP.RecipientLimitsInfo", "SP.GridInitInfoType", "SP.LockFileData", "SP.RecentSitesParams", "SP.AccessRequestResponse", "SP.Hashtag", "SP.PublishSnippetPayload", "SP.CustomActionElement", "SP.ApprovalsProperties", "SP.SiteAISettings", "SP.AdaptiveCardAction", "SP.HomeSiteReference", "SP.ContentAssemblyFormAnswer", "SP.VersionPolicySelectionParameters", "SP.ContentTypeCreationInformation", "SP.VivaConnectionsLicense", "SP.AgreementImportData", "SP.AppProperties", "SP.AppSettingsInTeams", "SP.SimpleDataTable"]

office365/directory/audit/directory.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from office365.directory.audit.target_resource import TargetResource
66
from office365.entity import Entity
77
from office365.runtime.client_value_collection import ClientValueCollection
8+
from office365.runtime.types.odata_property import odata
89

910

1011
class DirectoryAudit(Entity):
@@ -13,6 +14,7 @@ class DirectoryAudit(Entity):
1314
def __repr__(self):
1415
return self.activity_display_name or self.entity_type_name
1516

17+
@odata(name="activityDateTime")
1618
@property
1719
def activity_datetime(self) -> datetime:
1820
"""Indicates the date and time the activity was performed."""
@@ -49,6 +51,7 @@ def correlation_id(self) -> Optional[str]:
4951
"""
5052
return self.properties.get("correlationId", None)
5153

54+
@odata(name="initiatedBy")
5255
@property
5356
def initiated_by(self):
5457
"""
@@ -87,6 +90,7 @@ def result_reason(self) -> Optional[str]:
8790
"""
8891
return self.properties.get("resultReason", None)
8992

93+
@odata(name="targetResources")
9094
@property
9195
def target_resources(self) -> ClientValueCollection[TargetResource]:
9296
"""
@@ -95,13 +99,3 @@ def target_resources(self) -> ClientValueCollection[TargetResource]:
9599
and $filter (startswith) for displayName.
96100
"""
97101
return self.properties.get("targetResources", ClientValueCollection(TargetResource))
98-
99-
def get_property(self, name, default_value=None):
100-
if default_value is None:
101-
property_mapping = {
102-
"activityDateTime": self.activity_datetime,
103-
"initiatedBy": self.initiated_by,
104-
"targetResources": self.target_resources,
105-
}
106-
default_value = property_mapping.get(name, None)
107-
return super().get_property(name, default_value)

office365/directory/audit/log_root.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from office365.entity import Entity
77
from office365.entity_collection import EntityCollection
88
from office365.runtime.paths.resource_path import ResourcePath
9+
from office365.runtime.types.odata_property import odata
910

1011

1112
class AuditLogRoot(Entity):
1213
"""Contains different types of audit logs. This resources returns a singleton auditLog resource.
1314
It doesn't contain any usable properties.
1415
"""
1516

17+
@odata(name="directoryAudits")
1618
@property
1719
def directory_audits(self) -> EntityCollection[DirectoryAudit]:
1820
"""
@@ -57,9 +59,3 @@ def provisioning(self) -> EntityCollection[ProvisioningObjectSummary]:
5759
ResourcePath("provisioning", self.resource_path),
5860
),
5961
)
60-
61-
def get_property(self, name, default_value=None):
62-
if default_value is None:
63-
property_mapping = {"directoryAudits": self.directory_audits}
64-
default_value = property_mapping.get(name, None)
65-
return super().get_property(name, default_value)

office365/directory/extensions/logicapptriggerendpointconfiguration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

3-
from office365.directory.extensions.custom.customextensionendpointconfiguration import CustomExtensionEndpointConfiguration
3+
from office365.directory.extensions.custom.customextensionendpointconfiguration import (
4+
CustomExtensionEndpointConfiguration,
5+
)
46

57

68
class LogicAppTriggerEndpointConfiguration(CustomExtensionEndpointConfiguration):

office365/directory/identities/userflows/b2x/user_flow.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from office365.directory.identities.userflows.user_flow import IdentityUserFlow
1111
from office365.entity_collection import EntityCollection
1212
from office365.runtime.paths.resource_path import ResourcePath
13+
from office365.runtime.types.odata_property import odata
1314

1415

1516
class B2XIdentityUserFlow(IdentityUserFlow):
@@ -21,6 +22,7 @@ class B2XIdentityUserFlow(IdentityUserFlow):
2122
use to authenticate, along with which attributes are collected as part of the sign up process.
2223
"""
2324

25+
@odata(name="identityProviders")
2426
@property
2527
def identity_providers(self) -> EntityCollection[IdentityProvider]:
2628
"""TThe identity providers included in the user flow."""
@@ -47,6 +49,7 @@ def languages(self) -> EntityCollection[UserFlowLanguageConfiguration]:
4749
),
4850
)
4951

52+
@odata(name="userAttributeAssignments")
5053
@property
5154
def user_attribute_assignments(
5255
self,
@@ -67,12 +70,3 @@ def user_flow_type(self) -> Optional[str]:
6770
the value can only be signUpOrSignIn and cannot be modified after creation.
6871
"""
6972
return self.properties.get("userFlowType", None)
70-
71-
def get_property(self, name, default_value=None):
72-
if default_value is None:
73-
property_mapping = {
74-
"identityProviders": self.identity_providers,
75-
"userAttributeAssignments": self.user_attribute_assignments,
76-
}
77-
default_value = property_mapping.get(name, None)
78-
return super().get_property(name, default_value)

office365/directory/identitygovernance/workflow/custom_callout_extension.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Optional
22

33
from office365.directory.extensions.custom.clientconfiguration import CustomExtensionClientConfiguration
4-
from office365.directory.extensions.custom.customextensionendpointconfiguration import CustomExtensionEndpointConfiguration
4+
from office365.directory.extensions.custom.customextensionendpointconfiguration import (
5+
CustomExtensionEndpointConfiguration,
6+
)
57
from office365.directory.identitygovernance.customextensionauthenticationconfiguration import (
68
CustomExtensionAuthenticationConfiguration,
79
)

office365/directory/security/security.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from office365.runtime.client_result import ClientResult
2020
from office365.runtime.paths.resource_path import ResourcePath
2121
from office365.runtime.queries.service_operation import ServiceOperationQuery
22+
from office365.runtime.types.odata_property import odata
2223

2324

2425
class Security(Entity):
@@ -47,6 +48,7 @@ def alerts(self) -> AlertCollection:
4748
AlertCollection(self.context, ResourcePath("alerts", self.resource_path)),
4849
)
4950

51+
@odata(name="alerts_v2")
5052
@property
5153
def alerts_v2(self) -> EntityCollection[Alert]:
5254
"""A collection of alerts in Microsoft 365 Defender."""
@@ -60,6 +62,7 @@ def cases(self) -> CasesRoot:
6062
""""""
6163
return self.properties.get("cases", CasesRoot(self.context, ResourcePath("cases", self.resource_path)))
6264

65+
@odata(name="attackSimulation")
6366
@property
6467
def attack_simulation(self) -> AttackSimulationRoot:
6568
""""""
@@ -85,6 +88,7 @@ def labels(self) -> LabelsRoot:
8588
LabelsRoot(self.context, ResourcePath("labels", self.resource_path)),
8689
)
8790

91+
@odata(name="subjectRightsRequests")
8892
@property
8993
def subject_rights_requests(self) -> EntityCollection[SubjectRightsRequest]:
9094
"""Get a list of the subjectRightsRequest objects and their properties."""
@@ -97,6 +101,7 @@ def subject_rights_requests(self) -> EntityCollection[SubjectRightsRequest]:
97101
),
98102
)
99103

104+
@odata(name="secureScoreControlProfiles")
100105
@property
101106
def secure_score_control_profiles(
102107
self,
@@ -119,6 +124,7 @@ def triggers(self) -> TriggersRoot:
119124
TriggersRoot(self.context, ResourcePath("triggers", self.resource_path)),
120125
)
121126

127+
@odata(name="triggerTypes")
122128
@property
123129
def trigger_types(self) -> TriggerTypesRoot:
124130
""""""
@@ -127,6 +133,7 @@ def trigger_types(self) -> TriggerTypesRoot:
127133
TriggerTypesRoot(self.context, ResourcePath("triggerTypes", self.resource_path)),
128134
)
129135

136+
@odata(name="threatIntelligence")
130137
@property
131138
def threat_intelligence(self) -> ThreatIntelligence:
132139
""""""
@@ -135,19 +142,6 @@ def threat_intelligence(self) -> ThreatIntelligence:
135142
ThreatIntelligence(self.context, ResourcePath("threatIntelligence", self.resource_path)),
136143
)
137144

138-
def get_property(self, name, default_value=None):
139-
if default_value is None:
140-
property_mapping = {
141-
"alerts_v2": self.alerts_v2,
142-
"attackSimulation": self.attack_simulation,
143-
"subjectRightsRequests": self.subject_rights_requests,
144-
"secureScoreControlProfiles": self.secure_score_control_profiles,
145-
"triggerTypes": self.trigger_types,
146-
"threatIntelligence": self.threat_intelligence,
147-
}
148-
default_value = property_mapping.get(name, None)
149-
return super().get_property(name, default_value)
150-
151145
@property
152146
def entity_type_name(self) -> str:
153147
return "microsoft.graph.security.alert"

0 commit comments

Comments
 (0)