Skip to content

Commit

Permalink
Incidents namespace new types, fields namespace improvements in Share…
Browse files Browse the repository at this point in the history
…Point API
  • Loading branch information
vgrem committed Jul 28, 2023
1 parent bfcd8d3 commit 5fbd62f
Show file tree
Hide file tree
Showing 33 changed files with 387 additions and 61 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Steps to access:

Example: [connect_with_client_certificate.py](examples/sharepoint/connect_with_client_certificate.py)

#### 4. interactive
#### 4. Interactive

to login interactively i.e. via a local browser

Expand All @@ -108,11 +108,12 @@ Steps to access:
Example: [connect_interactive.py](examples/sharepoint/connect_interactive.py)

Usage:
```python
ctx = ClientContext(site_url).with_interactive(tenant_name_or_id, client_id)
me = ctx.web.current_user.get().execute_query()
print(me.login_name)
```
```python
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext(site_url).with_interactive(tenant_name_or_id, client_id)
me = ctx.web.current_user.get().execute_query()
print(me.login_name)
```

### Examples

Expand Down
16 changes: 16 additions & 0 deletions examples/sharepoint/fields/create_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Demonstrates how to create lookup field
"""
from office365.sharepoint.client_context import ClientContext
from tests import test_team_site_url, test_client_credentials, create_unique_name

field_name = create_unique_name("MultilookupField")
client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
lookup_list = client.web.default_document_library()

lookup_field = client.web.fields.add_lookup_field(title=field_name,
lookup_list=lookup_list,
lookup_field_name='Title',
allow_multiple_values=True).execute_query()
print(f"Field {lookup_field.internal_name} has been created")
lookup_field.delete_object().execute_query()
9 changes: 6 additions & 3 deletions examples/sharepoint/listitems/create_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Demonstrates how to create multiple list items via batch mode
Demonstrates how to create multiple list items via batch request
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.lists.template_type import ListTemplateType
Expand All @@ -8,8 +8,11 @@
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
list_tasks = ctx.web.add_list(create_unique_name("Tasks"), ListTemplateType.Tasks).execute_query()

num_of_items = 200
task_items = [list_tasks.add_item({"Title": create_unique_name("Task")}) for idx in range(0, num_of_items)]
num_of_items = 2
item_props = {
"Title": create_unique_name("Task")
}
task_items = [list_tasks.add_item(item_props) for idx in range(0, num_of_items)]
ctx.execute_batch()
print("{0} task items created".format(len(task_items)))

Expand Down
30 changes: 23 additions & 7 deletions generator/metadata/MicrosoftGraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20296,6 +20296,7 @@
<Property Name="country" Type="Edm.String"/>
<Property Name="createdDateTime" Type="Edm.DateTimeOffset"/>
<Property Name="creationType" Type="Edm.String"/>
<Property Name="customSecurityAttributes" Type="graph.customSecurityAttributeValue"/>
<Property Name="department" Type="Edm.String"/>
<Property Name="displayName" Type="Edm.String"/>
<Property Name="employeeHireDate" Type="Edm.DateTimeOffset"/>
Expand Down Expand Up @@ -20425,6 +20426,7 @@
<ComplexType Name="authorizationInfo">
<Property Name="certificateUserIds" Type="Collection(Edm.String)"/>
</ComplexType>
<ComplexType Name="customSecurityAttributeValue" OpenType="true"/>
<ComplexType Name="employeeOrgData">
<Property Name="costCenter" Type="Edm.String"/>
<Property Name="division" Type="Edm.String"/>
Expand Down Expand Up @@ -20902,6 +20904,7 @@
<Property Name="allowAttendeeToEnableMic" Type="Edm.Boolean"/>
<Property Name="allowedPresenters" Type="graph.onlineMeetingPresenters"/>
<Property Name="allowMeetingChat" Type="graph.meetingChatMode"/>
<Property Name="allowParticipantsToChangeName" Type="Edm.Boolean"/>
<Property Name="allowTeamworkReactions" Type="Edm.Boolean"/>
<Property Name="attendeeReport" Type="Edm.Stream"/>
<Property Name="audioConferencing" Type="graph.audioConferencing"/>
Expand Down Expand Up @@ -20953,6 +20956,7 @@
<NavigationProperty Name="lastMessagePreview" Type="graph.chatMessageInfo" ContainsTarget="true"/>
<NavigationProperty Name="members" Type="Collection(graph.conversationMember)" ContainsTarget="true"/>
<NavigationProperty Name="messages" Type="Collection(graph.chatMessage)" ContainsTarget="true"/>
<NavigationProperty Name="permissionGrants" Type="Collection(graph.resourceSpecificPermissionGrant)" ContainsTarget="true"/>
<NavigationProperty Name="pinnedMessages" Type="Collection(graph.pinnedChatMessageInfo)" ContainsTarget="true"/>
<NavigationProperty Name="tabs" Type="Collection(graph.teamsTab)" ContainsTarget="true"/>
</EntityType>
Expand All @@ -20979,6 +20983,7 @@
<NavigationProperty Name="installedApps" Type="Collection(graph.teamsAppInstallation)" ContainsTarget="true"/>
<NavigationProperty Name="members" Type="Collection(graph.conversationMember)" ContainsTarget="true"/>
<NavigationProperty Name="operations" Type="Collection(graph.teamsAsyncOperation)" ContainsTarget="true"/>
<NavigationProperty Name="permissionGrants" Type="Collection(graph.resourceSpecificPermissionGrant)" ContainsTarget="true"/>
<NavigationProperty Name="photo" Type="graph.profilePhoto" ContainsTarget="true"/>
<NavigationProperty Name="primaryChannel" Type="graph.channel" ContainsTarget="true"/>
<NavigationProperty Name="tags" Type="Collection(graph.teamworkTag)" ContainsTarget="true"/>
Expand Down Expand Up @@ -21224,6 +21229,7 @@
</EntityType>
<EntityType Name="printUsageByPrinter" BaseType="graph.printUsage">
<Property Name="printerId" Type="Edm.String" Nullable="false"/>
<Property Name="printerName" Type="Edm.String"/>
</EntityType>
<EntityType Name="printUsageByUser" BaseType="graph.printUsage">
<Property Name="userPrincipalName" Type="Edm.String" Nullable="false"/>
Expand Down Expand Up @@ -21268,6 +21274,7 @@
<Property Name="appOwnerOrganizationId" Type="Edm.Guid"/>
<Property Name="appRoleAssignmentRequired" Type="Edm.Boolean" Nullable="false"/>
<Property Name="appRoles" Type="Collection(graph.appRole)" Nullable="false"/>
<Property Name="customSecurityAttributes" Type="graph.customSecurityAttributeValue"/>
<Property Name="description" Type="Edm.String"/>
<Property Name="disabledByMicrosoftStatus" Type="Edm.String"/>
<Property Name="displayName" Type="Edm.String"/>
Expand Down Expand Up @@ -22060,6 +22067,13 @@
<Property Name="targetResourceId" Type="Edm.String"/>
<Property Name="targetResourceLocation" Type="Edm.String"/>
</EntityType>
<EntityType Name="resourceSpecificPermissionGrant" BaseType="graph.directoryObject">
<Property Name="clientAppId" Type="Edm.String"/>
<Property Name="clientId" Type="Edm.String"/>
<Property Name="permission" Type="Edm.String"/>
<Property Name="permissionType" Type="Edm.String"/>
<Property Name="resourceAppId" Type="Edm.String"/>
</EntityType>
<EntityType Name="teamworkTag" BaseType="graph.entity">
<Property Name="description" Type="Edm.String"/>
<Property Name="displayName" Type="Edm.String"/>
Expand Down Expand Up @@ -22103,13 +22117,6 @@
<ComplexType Name="licenseProcessingState">
<Property Name="state" Type="Edm.String"/>
</ComplexType>
<EntityType Name="resourceSpecificPermissionGrant" BaseType="graph.directoryObject">
<Property Name="clientAppId" Type="Edm.String"/>
<Property Name="clientId" Type="Edm.String"/>
<Property Name="permission" Type="Edm.String"/>
<Property Name="permissionType" Type="Edm.String"/>
<Property Name="resourceAppId" Type="Edm.String"/>
</EntityType>
<EntityType Name="groupSetting" BaseType="graph.entity" OpenType="true">
<Property Name="displayName" Type="Edm.String"/>
<Property Name="templateId" Type="Edm.String"/>
Expand Down Expand Up @@ -29301,6 +29308,7 @@
<Property Name="createdDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
<Property Name="id" Type="Edm.String" Nullable="false"/>
<Property Name="printerId" Type="Edm.String"/>
<Property Name="printerName" Type="Edm.String"/>
<Property Name="processingState" Type="graph.printJobProcessingState" Nullable="false"/>
</ComplexType>
<ComplexType Name="integerRange">
Expand Down Expand Up @@ -35980,12 +35988,20 @@
<Parameter Name="templateParameters" Type="Collection(graph.keyValuePair)"/>
<Parameter Name="recipients" Type="Collection(graph.teamworkNotificationRecipient)"/>
</Action>
<Action Name="setReaction" IsBound="true">
<Parameter Name="bindingParameter" Type="graph.chatMessage"/>
<Parameter Name="reactionType" Type="Edm.String" Unicode="false"/>
</Action>
<Action Name="softDelete" IsBound="true">
<Parameter Name="bindingParameter" Type="graph.chatMessage"/>
</Action>
<Action Name="undoSoftDelete" IsBound="true">
<Parameter Name="bindingParameter" Type="graph.chatMessage"/>
</Action>
<Action Name="unsetReaction" IsBound="true">
<Parameter Name="bindingParameter" Type="graph.chatMessage"/>
<Parameter Name="reactionType" Type="Edm.String" Unicode="false"/>
</Action>
<Action Name="upgrade" IsBound="true">
<Parameter Name="bindingParameter" Type="graph.teamsAppInstallation"/>
<Parameter Name="consentedPermissionSet" Type="graph.teamsAppPermissionSet"/>
Expand Down
4 changes: 4 additions & 0 deletions office365/directory/licenses/service_plan_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ def __init__(self, _id=None, name=None, provisioning_status=None, applies_to=Non
self.servicePlanName = name
self.provisioningStatus = provisioning_status
self.appliesTo = applies_to

def __repr__(self):
return self.servicePlanName

26 changes: 26 additions & 0 deletions office365/directory/licenses/subscribed_sku.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from office365.directory.licenses.service_plan_info import ServicePlanInfo
from office365.directory.licenses.units_detail import LicenseUnitsDetail
from office365.entity import Entity
from office365.runtime.client_value_collection import ClientValueCollection

Expand All @@ -9,10 +10,20 @@ class SubscribedSku(Entity):
@property
def account_id(self):
"""
The unique ID of the account this SKU belongs to.
:rtype: str
"""
return self.properties.get("accountId", None)

@property
def applies_to(self):
"""
The target class for this SKU. Only SKUs with target class User are assignable.
Possible values are: "User", "Company".
:rtype: str
"""
return self.properties.get("appliesTo", None)

@property
def sku_id(self):
"""
Expand All @@ -21,6 +32,20 @@ def sku_id(self):
"""
return self.properties.get("skuId", None)

@property
def sku_part_number(self):
"""
The SKU part number; for example: "AAD_PREMIUM" or "RMSBASIC".
To get a list of commercial subscriptions that an organization has acquired, see List subscribedSkus.
:rtype: str
"""
return self.properties.get("skuPartNumber", None)

@property
def prepaid_units(self):
"""Information about the number and status of prepaid licenses."""
return self.properties.get("prepaidUnits", LicenseUnitsDetail())

@property
def service_plans(self):
"""Information about the service plans that are available with the SKU. Not nullable"""
Expand All @@ -29,6 +54,7 @@ def service_plans(self):
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"prepaidUnits": self.prepaid_units,
"servicePlans": self.service_plans
}
default_value = property_mapping.get(name, None)
Expand Down
11 changes: 11 additions & 0 deletions office365/directory/licenses/units_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from office365.runtime.client_value import ClientValue


class LicenseUnitsDetail(ClientValue):
""""""

def __init__(self, enabled=None):
"""
:param int enabled: The number of units that are enabled for the active subscription of the service SKU.
"""
self.enabled = enabled
9 changes: 9 additions & 0 deletions office365/directory/policies/authentication_flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.entity import Entity


class AuthenticationFlowsPolicy(Entity):
"""
Represents the policy configuration of self-service sign-up experience at a tenant level that lets external
users request to sign up for approval. It contains information, such as the identifier, display name, and
description, and indicates whether self-service sign-up is enabled for the policy.
"""
10 changes: 10 additions & 0 deletions office365/directory/policies/authentication_strength.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from office365.entity import Entity


class AuthenticationStrengthPolicy(Entity):
"""
A collection of settings that define specific combinations of authentication methods and metadata.
The authentication strength policy, when applied to a given scenario using Azure AD Conditional Access,
defines which authentication methods must be used to authenticate in that scenario. An authentication strength
may be built-in or custom (defined by the tenant) and may or may not fulfill the requirements to grant an MFA claim.
"""
25 changes: 23 additions & 2 deletions office365/directory/policies/root.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from office365.directory.policies.app_management import AppManagementPolicy
from office365.directory.policies.authentication_flows import AuthenticationFlowsPolicy
from office365.directory.policies.authentication_methods import AuthenticationMethodsPolicy
from office365.directory.policies.authentication_strength import AuthenticationStrengthPolicy
from office365.directory.policies.permission_grant import PermissionGrantPolicy
from office365.directory.policies.authorization import AuthorizationPolicy
from office365.directory.policies.conditional_access import ConditionalAccessPolicy
Expand All @@ -21,6 +24,22 @@ def authentication_methods_policy(self):
ResourcePath("authenticationMethodsPolicy",
self.resource_path)))

def authentication_strength_policies(self):
"""
The authentication method combinations that are to be used in scenarios defined by Azure AD Conditional Access.
"""
return self.properties.get('authenticationStrengthPolicies',
EntityCollection(self.context, AuthenticationStrengthPolicy,
ResourcePath("authenticationStrengthPolicies", self.resource_path)))

@property
def authentication_flows_policy(self):
""" The policy configuration of the self-service sign-up experience of external users."""
return self.properties.get('authenticationFlowsPolicy',
AuthenticationFlowsPolicy(self.context,
ResourcePath("authenticationFlowsPolicy",
self.resource_path)))

@property
def authorization_policy(self):
"""The policy that controls Azure AD authorization settings."""
Expand All @@ -33,8 +52,8 @@ def app_management_policies(self):
"""The policies that enforce app management restrictions for specific applications and service principals,
overriding the defaultAppManagementPolicy."""
return self.properties.get('appManagementPolicies',
AuthorizationPolicy(self.context,
ResourcePath("appManagementPolicies", self.resource_path)))
EntityCollection(self.context, AppManagementPolicy,
ResourcePath("appManagementPolicies", self.resource_path)))

@property
def permission_grant_policies(self):
Expand All @@ -57,6 +76,8 @@ def conditional_access_policies(self):
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"authenticationStrengthPolicies": self.authentication_strength_policies,
"authenticationFlowsPolicy": self.authentication_flows_policy,
"appManagementPolicies": self.app_management_policies,
"authenticationMethodsPolicy": self.authentication_methods_policy,
"authorizationPolicy": self.authorization_policy,
Expand Down
19 changes: 19 additions & 0 deletions office365/directory/rolemanagement/unified_role_assignment.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
from office365.directory.rolemanagement.unified_role_definition import UnifiedRoleDefinition
from office365.entity import Entity
from office365.runtime.paths.resource_path import ResourcePath


class UnifiedRoleAssignment(Entity):
"""
A role assignment is used to grant access to resources. It represents a role definition assigned to a principal
(for example, a user or a role-assignable group) at a particular scope.
"""

@property
def role_definition(self):
"""
The roleDefinition the assignment is for. Supports $expand. roleDefinition.Id will be auto expanded.
"""
return self.properties.get('roleDefinition',
UnifiedRoleDefinition(self.context,
ResourcePath("roleDefinition", self.resource_path)))

def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"roleDefinition": self.role_definition,
}
default_value = property_mapping.get(name, None)
return super(UnifiedRoleAssignment, self).get_property(name, default_value)
5 changes: 5 additions & 0 deletions office365/directory/security/attacksimulations/automation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class SimulationAutomation(Entity):
"""Represents simulation automation created to run on a tenant."""
27 changes: 27 additions & 0 deletions office365/directory/security/attacksimulations/root.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
from office365.directory.security.attacksimulations.automation import SimulationAutomation
from office365.directory.security.attacksimulations.simulation import Simulation
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.runtime.paths.resource_path import ResourcePath


class AttackSimulationRoot(Entity):
"""Represents an abstract type that provides the ability to launch a realistic phishing attack that organizations
can learn from."""

@property
def simulations(self):
"""Represents an attack simulation training campaign in a tenant."""
return self.properties.get('simulations',
EntityCollection(self.context, Simulation,
ResourcePath("simulations", self.resource_path)))

@property
def simulation_automations(self):
"""Represents simulation automation created to run on a tenant."""
return self.properties.get('simulationAutomations',
EntityCollection(self.context, SimulationAutomation,
ResourcePath("simulationAutomations", self.resource_path)))

def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"simulationAutomations": self.simulation_automations,
}
default_value = property_mapping.get(name, None)
return super(AttackSimulationRoot, self).get_property(name, default_value)

Loading

0 comments on commit 5fbd62f

Please sign in to comment.