-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
directory namespace improvements & refactorings
- Loading branch information
Showing
41 changed files
with
463 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
How to grant and revoke delegated permissions for an app using Microsoft Graph. | ||
Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API | ||
on behalf of a signed-in user. | ||
https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions | ||
""" | ||
|
||
from office365.graph_client import GraphClient | ||
from tests import ( | ||
test_client_id, | ||
test_tenant, | ||
test_client_secret, | ||
) | ||
|
||
# client = GraphClient.with_token_interactive( | ||
# test_tenant, test_client_id, test_admin_principal_name | ||
# ) | ||
|
||
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret) | ||
|
||
|
||
resource = ( | ||
client.service_principals.get_by_name("Microsoft Graph") | ||
) | ||
|
||
result = resource.get_application_permissions(test_client_id).execute_query() | ||
for app_role in result.value: | ||
print(app_role) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,3 @@ | ||
from office365.sharepoint.fields.creation_information import FieldCreationInformation | ||
from office365.sharepoint.fields.type import FieldType | ||
from office365.sharepoint.lists.creation_information import ListCreationInformation | ||
from office365.sharepoint.lists.list import List | ||
from office365.sharepoint.lists.template_type import ListTemplateType | ||
from office365.sharepoint.webs.web import Web | ||
from tests import create_unique_name | ||
|
||
|
||
def upload_sample_file(context, path): | ||
""" | ||
:type context: office365.sharepoint.client_context.ClientContext | ||
:type path: str | ||
""" | ||
folder = context.web.default_document_library().root_folder | ||
with open(path, "rb") as f: | ||
file = folder.files.upload(f).execute_query() | ||
return file | ||
|
||
|
||
def create_sample_tasks_list(web): | ||
# type: (Web) -> List | ||
list_title = "Company Tasks" | ||
|
||
list_title = create_unique_name("Tasks N") | ||
list_create_info = ListCreationInformation( | ||
list_title, None, ListTemplateType.TasksWithTimelineAndHierarchy | ||
) | ||
|
||
return_type = web.lists.add(list_create_info).execute_query() | ||
field_info = FieldCreationInformation("Manager", FieldType.User) | ||
return_type.fields.add(field_info).execute_query() | ||
return return_type | ||
|
||
|
||
def configure(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from office365.communications.callrecords.call_record import CallRecord | ||
from office365.communications.callrecords.direct_routing_log_row import ( | ||
DirectRoutingLogRow, | ||
) | ||
from office365.entity_collection import EntityCollection | ||
from office365.runtime.client_result import ClientResult | ||
from office365.runtime.client_value_collection import ClientValueCollection | ||
from office365.runtime.queries.function import FunctionQuery | ||
|
||
|
||
class CallRecordCollection(EntityCollection[CallRecord]): | ||
def __init__(self, context, resource_path=None): | ||
super(CallRecordCollection, self).__init__(context, CallRecord, resource_path) | ||
|
||
def get_direct_routing_calls(self, from_datetime=None, to_datetime=None): | ||
""" | ||
Get a log of direct routing calls as a collection of directRoutingLogRow entries. | ||
:param datetime from_datetime: Start of time range to query. | ||
:param datetime to_datetime: End of time range to query | ||
""" | ||
if to_datetime is None: | ||
to_datetime = datetime.now() | ||
|
||
if from_datetime is None: | ||
from_datetime = to_datetime - timedelta(days=30) | ||
|
||
return_type = ClientResult( | ||
self.context, ClientValueCollection(DirectRoutingLogRow) | ||
) | ||
payload = {"fromDateTime": from_datetime.strftime('%Y-%m-%d'), "toDateTime": to_datetime.strftime('%Y-%m-%d')} | ||
qry = FunctionQuery(self, "getDirectRoutingCalls", payload, return_type) | ||
|
||
def _patch_request(request): | ||
request.url = request.url.replace("'", "") | ||
|
||
self.context.add_query(qry).before_query_execute(_patch_request) | ||
return return_type |
5 changes: 5 additions & 0 deletions
5
office365/communications/callrecords/direct_routing_log_row.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from office365.runtime.client_value import ClientValue | ||
|
||
|
||
class DirectRoutingLogRow(ClientValue): | ||
"""Represents a row of data in the direct routing call log. Each row maps to one call.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
office365/directory/applications/required_resource_access.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from office365.directory.applications.resource_access import ResourceAccess | ||
from office365.runtime.client_value import ClientValue | ||
from office365.runtime.client_value_collection import ClientValueCollection | ||
|
||
|
||
class RequiredResourceAccess(ClientValue): | ||
"""Specifies the set of OAuth 2.0 permission scopes and app roles under the specified resource that an | ||
application requires access to. The application may request the specified OAuth 2.0 permission scopes or app | ||
roles through the requiredResourceAccess property, which is a collection of requiredResourceAccess objects. | ||
""" | ||
|
||
def __init__(self, resource_access=None, resource_app_id=None): | ||
""" | ||
:param list[ResourceAccess] resource_access: The list of OAuth2.0 permission scopes and app roles that | ||
the application requires from the specified resource. | ||
:param str resource_app_id: The unique identifier for the resource that the application requires access to. | ||
This should be equal to the appId declared on the target resource application. | ||
""" | ||
self.resourceAccess = ClientValueCollection(ResourceAccess, resource_access) | ||
self.resourceAppId = resource_app_id | ||
|
||
|
||
def __repr__(self): | ||
return self.resourceAppId or self.entity_type_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from office365.runtime.client_value import ClientValue | ||
|
||
|
||
class ResourceAccess(ClientValue): | ||
""" Object used to specify an OAuth 2.0 permission scope or an app role that an application requires, | ||
through the resourceAccess property of the requiredResourceAccess resource type. """ | ||
|
||
def __init__(self, id_=None, type_=None): | ||
""" | ||
:param str id_: The unique identifier of an app role or delegated permission exposed by the resource | ||
application. For delegated permissions, this should match the id property of one of the delegated | ||
permissions in the oauth2PermissionScopes collection of the resource application's service principal. | ||
For app roles (application permissions), this should match the id property of an app role in the appRoles | ||
collection of the resource application's service principal. | ||
:param str type_: Specifies whether the id property references a delegated permission or an app role | ||
(application permission). The possible values are: Scope (for delegated permissions) or Role (for app roles). | ||
""" | ||
self.id = id_ | ||
self.type = type_ | ||
|
||
def __repr__(self): | ||
return "ResourceAccess(id={!r}, type={!r})".format(self.id, self.type) | ||
|
||
@property | ||
def type_name(self): | ||
return "Delegated" if self.type == "Scope" else "Application" |
Oops, something went wrong.