def test3_register_hub_site(self):
     client_admin = ClientContext(test_admin_site_url).with_credentials(
         test_user_credentials)
     tenant = Tenant(client_admin)
     props = tenant.register_hub_site(
         self.__class__.site_response.SiteUrl).execute_query()
     self.assertIsNotNone(props)
Beispiel #2
0
 def test4_unregister_hub_site(self):
     admin_site_url = settings.get('admin_site_url')
     client_admin = ClientContext(admin_site_url).with_credentials(
         self.user_credentials)
     tenant = Tenant(client_admin)
     tenant.unregister_hub_site(
         self.__class__.site_response.SiteUrl).execute_query()
Beispiel #3
0
    def test4_register_hub_site(self):
        client_admin = ClientContext(test_admin_site_url).with_credentials(
            test_user_credentials)
        tenant = Tenant(client_admin)
        props = tenant.register_hub_site(
            self.__class__.site_response.SiteUrl).execute_query()
        self.assertIsNotNone(props.site_id)

        target_site = Site.from_url(
            self.__class__.site_response.SiteUrl).with_credentials(
                test_user_credentials)
        target_site.get().execute_query()
        self.assertTrue(target_site.is_hub_site)
Beispiel #4
0
    def setUpClass(cls):
        credentials = UserCredential(settings['user_credentials']['username'],
                                     settings['user_credentials']['password'])

        cls.client = ClientContext(
            settings.get("admin_site_url")).with_credentials(credentials)
        cls.tenant = Tenant(cls.client)
    def setUpClass(cls):
        tenant = os.environ.get('office365_python_sdk_tenant', 'mediadev8')
        admin_site_url = "https://{0}-admin.sharepoint.com/".format(tenant)
        credentials = UserCredential(settings['user_credentials']['username'],
                                     settings['user_credentials']['password'])

        cls.client = ClientContext(admin_site_url).with_credentials(credentials)
        cls.tenant = Tenant(cls.client)
 def setUpClass(cls):
     client = ClientContext(test_admin_site_url).with_credentials(
         test_user_credentials)
     cls.tenant = Tenant(client)
     cls.client = client
Beispiel #7
0
"""
Since for new tenants, apps using an ACS app-only access token is disabled by default,
you can change the behavior using the below script
"""

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.tenant import Tenant
from tests import test_admin_site_url, test_user_credentials

admin_client = ClientContext(test_admin_site_url).with_credentials(
    test_user_credentials)
tenant = Tenant(admin_client).get().execute_query()
# print(tenant.get_property("DisableCustomAppAuthentication"))
if tenant.get_property("DisableCustomAppAuthentication"):
    tenant.set_property("DisableCustomAppAuthentication",
                        False).update().execute_query()
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.secondary_administrators_info import SecondaryAdministratorsInfo
from office365.sharepoint.tenant.administration.tenant import Tenant
from settings import settings, tenant_prefix

credentials = UserCredential(settings['user_credentials']['username'],
                             settings['user_credentials']['password'])

client = ClientContext(settings.get('url')).with_credentials(credentials)
target_site = client.site.get().execute_query()

admin_client = ClientContext(
    settings.get("admin_site_url")).with_credentials(credentials)
tenant = Tenant(admin_client)

admins = tenant.get_site_secondary_administrators(site_id=target_site.id)
admin_client.execute_query()

existing_admin_names = [admin.loginName for admin in admins]

target_user = target_site.root_web.ensure_user(
    f"mdoe@{tenant_prefix}.onmicrosoft.com").execute_query()
names = existing_admin_names + [target_user.login_name]
tenant.set_site_secondary_administrators(site_id=target_site.id,
                                         names=names).execute_query()

for admin in admins:  # type: SecondaryAdministratorsInfo
    print(admin.loginName)
 def test4_unregister_hub_site(self):
     client_admin = ClientContext(test_admin_site_url).with_credentials(
         test_user_credentials)
     tenant = Tenant(client_admin)
     tenant.unregister_hub_site(
         self.__class__.site_response.SiteUrl).execute_query()
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.site_properties import SiteProperties
from office365.sharepoint.tenant.administration.tenant import Tenant
from tests import test_admin_site_url, test_client_credentials

admin_client = ClientContext(test_admin_site_url).with_credentials(
    test_client_credentials)
tenant = Tenant(admin_client)
result = tenant.get_site_properties_from_sharepoint_by_filters(
    "", 0).execute_query()
for siteProps in result:  # type: SiteProperties
    print(siteProps.url)
import json
from random import randint

from office365.sharepoint.tenant.administration.tenant import Tenant
from tests import test_admin_site_url, test_site_url, test_user_credentials, test_user_principal_name_alt

alias = str(randint(0, 10000))
title = "Custom Site"
site_url = "{0}/sites/{1}".format(test_site_url, alias)

tenant = Tenant.from_url(test_admin_site_url).with_credentials(
    test_user_credentials)

site = tenant.create_site_sync(site_url,
                               test_user_principal_name_alt).execute_query()
print(json.dumps(site.to_json(), indent=4))
tenant.remove_site(site_url).execute_query()  # cleanup
Beispiel #12
0
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.tenant import Tenant
from tests import test_admin_site_url, test_client_credentials

admin_client = ClientContext(test_admin_site_url).with_credentials(
    test_client_credentials)
result = Tenant(admin_client).export_to_csv().execute_query()
print("Sites details have been exported into {0}{1}".format(
    test_admin_site_url, result.value))
import os
from pprint import pprint

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.tenant import Tenant
from tests import test_admin_site_url, test_tenant

cert_settings = {
    'client_id': '51d03106-4726-442c-86db-70b32fa7547f',
    'thumbprint': "61C754D8D9629BE91972B6A0C1999DC678FB0145",
    'cert_path': '{0}/../selfsigncert.pem'.format(os.path.dirname(__file__))
}

admin_client = ClientContext(test_admin_site_url).with_client_certificate(test_tenant, **cert_settings)
tenant_details = Tenant(admin_client).get().execute_query()
pprint(tenant_details.properties)





from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.secondary_administrators_info import SecondaryAdministratorsInfo
from office365.sharepoint.tenant.administration.tenant import Tenant
from settings import settings

credentials = UserCredential(settings['user_credentials']['username'],
                             settings['user_credentials']['password'])


client = ClientContext(settings.get("team_site_url")).with_credentials(credentials)
target_site = client.site.get().execute_query()

admin_client = ClientContext(settings.get("admin_site_url")).with_credentials(credentials)
tenant = Tenant(admin_client)

admins = tenant.get_site_secondary_administrators(site_id=target_site.id)
admin_client.execute_query()

#emails = settings.get("test_accounts")
#tenant.set_site_secondary_administrators(site_id=target_site.id, emails=emails).execute_query()

for admin in admins:  # type: SecondaryAdministratorsInfo
    print(admin.get_property('loginName'))