Skip to content

Commit

Permalink
examples update
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Aug 17, 2024
1 parent 8213d73 commit 8b39315
Show file tree
Hide file tree
Showing 19 changed files with 283 additions and 9 deletions.
6 changes: 4 additions & 2 deletions examples/sharepoint/files/download_from_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from office365.sharepoint.files.file import File
from tests import test_client_credentials, test_site_url

abs_file_url = "{site_url}/sites/team/Shared Documents/big_buck_bunny.mp4".format(
site_url=test_site_url
abs_file_url = (
"{site_url}/sites/team/Shared Documents/archive/big_buck_bunny.mp4".format(
site_url=test_site_url
)
)

with tempfile.TemporaryDirectory() as local_path:
Expand Down
2 changes: 1 addition & 1 deletion examples/sharepoint/files/upload_large.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def print_upload_progress(offset):
local_path = "../../../tests/data/big_buck_bunny.mp4"
with open(local_path, "rb") as f:
uploaded_file = target_folder.files.create_upload_session(
f, size_chunk, print_upload_progress, "big_buck_bunny_v2.mp4"
f, size_chunk, print_upload_progress
).execute_query()

print("File {0} has been uploaded successfully".format(uploaded_file.serverRelativeUrl))
16 changes: 16 additions & 0 deletions examples/sharepoint/permissions/get_for_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Returns the user permissions for the file.
"""

from pprint import pprint

from office365.sharepoint.client_context import ClientContext
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
file_url = "SitePages/Home.aspx"
file = ctx.web.get_file_by_server_relative_url(file_url)
result = file.listItemAllFields.get_user_effective_permissions(
ctx.web.current_user
).execute_query()
pprint(result.value.permission_levels)
Empty file.
File renamed without changes.
119 changes: 117 additions & 2 deletions generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.entity import Entity


class AuthenticationEventListener(Entity):
"""
Defines a listener to evaluate when an authentication event happens in an authentication experience.
An authenticationListener is abstract and is the base class of the various types of listeners you can evaluate
during an authentication event.
"""
18 changes: 18 additions & 0 deletions office365/directory/identities/container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from office365.directory.authentication.conditions.event_listener import (
AuthenticationEventListener,
)
from office365.directory.identities.api_connector import IdentityApiConnector
from office365.directory.identities.conditional_access_root import ConditionalAccessRoot
from office365.directory.identities.providers.base_collection import (
Expand All @@ -18,6 +21,7 @@ class IdentityContainer(Entity):

@property
def api_connectors(self):
# type: () -> EntityCollection[IdentityApiConnector]
"""Represents entry point for API connectors."""
return self.properties.get(
"apiConnectors",
Expand All @@ -28,6 +32,19 @@ def api_connectors(self):
),
)

@property
def authentication_event_listeners(self):
# type: () -> EntityCollection[AuthenticationEventListener]
"""Get the collection of authenticationListener resources supported by the onSignupStart event."""
return self.properties.get(
"authenticationEventListeners",
EntityCollection(
self.context,
AuthenticationEventListener,
ResourcePath("authenticationEventListeners", self.resource_path),
),
)

@property
def conditional_access(self):
"""The entry point for the Conditional Access (CA) object model."""
Expand Down Expand Up @@ -76,6 +93,7 @@ def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"apiConnectors": self.api_connectors,
"authenticationEventListeners": self.authentication_event_listeners,
"b2xUserFlows": self.b2x_user_flows,
"conditionalAccess": self.conditional_access,
"identityProviders": self.identity_providers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@

class UserSimulationDetails(ClientValue):
"""Represents a user of a tenant and their online actions in an attack simulation and training campaign."""

def __init__(self, assigned_trainings_count=None):
"""
:param int assigned_trainings_count: Number of trainings assigned to a user in an attack simulation
and training campaign.
"""
self.assignedTrainingsCount = assigned_trainings_count
8 changes: 8 additions & 0 deletions office365/sharepoint/sites/version_policy_manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from typing import Optional

from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity


class SiteVersionPolicyManager(Entity):
""""""

@property
def major_version_limit(self):
# type: () -> Optional[int]
""" """
return self.properties.get("MajorVersionLimit", None)

def set_auto_expiration(self):
""""""
qry = ServiceOperationQuery(self, "SetAutoExpiration")
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.runtime.client_value import ClientValue


class TenantAdminPolicyDefinition(ClientValue):
""" """
10 changes: 9 additions & 1 deletion office365/sharepoint/tenant/administration/settings_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from office365.runtime.types.collections import StringCollection
from office365.sharepoint.entity import Entity
from office365.sharepoint.tenant.administration.smtp_server import SmtpServer
from office365.sharepoint.tenant.administration.types import DisableGroupify
from office365.sharepoint.tenant.administration.types import (
AutoQuotaEnabled,
DisableGroupify,
)


class TenantAdminSettingsService(Entity):
Expand All @@ -25,6 +28,11 @@ def get_tenant_sharing_status(self):
self.context.add_query(qry)
return return_type

@property
def auto_quota_enabled(self):
""""""
return self.properties.get("AutoQuotaEnabled", AutoQuotaEnabled())

@property
def available_managed_paths_for_site_creation(self):
""""""
Expand Down
45 changes: 45 additions & 0 deletions office365/sharepoint/tenant/administration/sites/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,50 @@ def _update_ex():
self._ensure_site_path(_update_ex)
return return_type

@property
def allow_downloading_non_web_viewable_files(self):
# type: () -> Optional[bool]
"""Specifies if non web viewable files can be downloaded."""
return self.properties.get("AllowDownloadingNonWebViewableFiles", None)

@property
def allow_editing(self):
# type: () -> Optional[bool]
"""Prevents users from editing Office files in the browser and copying and pasting Office file contents
out of the browser window."""
return self.properties.get("AllowEditing", None)

@property
def allow_self_service_upgrade(self):
# type: () -> Optional[bool]
"""Whether version to version upgrade is allowed on this site."""
return self.properties.get("AllowSelfServiceUpgrade", None)

@property
def anonymous_link_expiration_in_days(self):
# type: () -> Optional[int]
"""Specifies all anonymous/anyone links that have been created
(or will be created) will expire after the set number of days."""
return self.properties.get("AnonymousLinkExpirationInDays", None)

@property
def apply_to_existing_document_libraries(self):
# type: () -> Optional[bool]
"""Create a job to apply the version history limits setting to existing document libraries."""
return self.properties.get("ApplyToExistingDocumentLibraries", None)

@property
def apply_to_new_document_libraries(self):
# type: () -> Optional[bool]
"""Gets site version policy for new document libraries."""
return self.properties.get("ApplyToNewDocumentLibraries", None)

@property
def archived_by(self):
# type: () -> Optional[str]
"""Gets site version policy for new document libraries."""
return self.properties.get("ArchivedBy", None)

@property
def deny_add_and_customize_pages(self):
# type: () -> Optional[int]
Expand All @@ -69,6 +113,7 @@ def deny_add_and_customize_pages(self, value):
@property
def owner_login_name(self):
# type: () -> Optional[str]
""" """
return self.properties.get("OwnerLoginName", None)

@property
Expand Down
14 changes: 14 additions & 0 deletions office365/sharepoint/tenant/administration/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
from office365.sharepoint.tenant.administration.insights.top_files_sharing import (
TopFilesSharingInsights,
)
from office365.sharepoint.tenant.administration.policies.definition import (
TenantAdminPolicyDefinition,
)
from office365.sharepoint.tenant.administration.powerapps.environment import (
PowerAppsEnvironment,
)
Expand Down Expand Up @@ -69,6 +72,7 @@
from office365.sharepoint.tenant.administration.syntex.billing_context import (
SyntexBillingContext,
)
from office365.sharepoint.tenant.administration.types import CreatePolicyRequest
from office365.sharepoint.tenant.administration.webs.templates.collection import (
SPOTenantWebTemplateCollection,
)
Expand Down Expand Up @@ -522,6 +526,16 @@ def unregister_hub_site(self, site_url):
self.context.add_query(qry)
return self

def create_policy_definition(self):
""" """
return_type = ClientResult(self.context, TenantAdminPolicyDefinition())
payload = {"policyInputParameters": CreatePolicyRequest()}
qry = ServiceOperationQuery(
self, "CreatePolicyDefinition", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type

def create_site(self, url, owner, title=None):
"""Queues a site collection for creation with the specified properties.
Expand Down
18 changes: 17 additions & 1 deletion office365/sharepoint/tenant/administration/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@


class DisableGroupify(ClientValue):
""""""
""" """


class AutoQuotaEnabled(ClientValue):
""" """

def __init__(self, is_read_only=None, value=None):
self.IsReadOnly = is_read_only
self.Value = value


class CreatePolicyRequest(ClientValue):
""" """

def __init__(self, is_preview_run=None, policy_custom_name=None):
self.isPreviewRun = is_preview_run
self.policyCustomName = policy_custom_name
6 changes: 6 additions & 0 deletions office365/sharepoint/webs/regional_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def locale_id(self):
"""Gets the locale identifier in use on the server."""
return self.properties.get("LocaleId", None)

@property
def negative_sign(self):
# type: () -> Optional[str]
""" """
return self.properties.get("NegativeSign", None)

@property
def work_days(self):
# type: () -> Optional[int]
Expand Down
4 changes: 2 additions & 2 deletions office365/teams/members/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class TeamMemberSettings(ClientValue):
"""Settings to configure whether members can perform certain actions, for example, create channels and add bots,
in the team."""

def __init__(self):
def __init__(self, allow_create_update_channels=None):
super(TeamMemberSettings, self).__init__()
self.allowCreateUpdateChannels = True
self.allowCreateUpdateChannels = allow_create_update_channels
self.allowDeleteChannels = True
self.allowAddRemoveApps = True
self.allowCreateUpdateRemoveTabs = True
Expand Down
5 changes: 5 additions & 0 deletions tests/sharepoint/test_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,8 @@ def test_25_get_power_apps_environments(self):
def test_27_get_get_spo_all_web_templates(self):
result = self.tenant.get_spo_all_web_templates().execute_query()
self.assertIsNotNone(result)

def test_28_get_get_collaboration_insights_data(self):
# Note: You need a SharePoint Advanced Management license to perform this action
result = self.tenant.get_collaboration_insights_data().execute_query()
self.assertIsNotNone(result.value)

0 comments on commit 8b39315

Please sign in to comment.