Skip to content

Commit

Permalink
Intune API support & typings updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Feb 3, 2024
1 parent 035b324 commit c777594
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 158 deletions.
4 changes: 2 additions & 2 deletions examples/directory/identity/list_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
https://learn.microsoft.com/en-us/graph/api/identitycontainer-list-identityproviders?view=graph-rest-1.0&tabs=http
"""
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_client_credentials
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient(acquire_token_by_client_credentials)
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
providers = client.identity.identity_providers.get().execute_query()
for idp in providers:
print(idp.display_name)
6 changes: 4 additions & 2 deletions examples/directory/users/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"""

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
users = client.users.get().top(10).execute_query()
for u in users:
print(u.user_principal_name)
8 changes: 5 additions & 3 deletions examples/onedrive/files/get_details.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Retrieve the metadata for a driveItem in a drive by file system path
https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0
"""

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
file_path = "Financial Sample.xlsx"
file_item = client.me.drive.root.get_by_path(file_path).get().execute_query()
print(file_item.web_url)
4 changes: 2 additions & 2 deletions examples/onedrive/files/list_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
https://learn.microsoft.com/en-us/graph/api/driveitem-list-versions?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_client_credentials
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient(acquire_token_by_client_credentials)
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
file_item = (
client.sites.root.drive.root.get_by_path("Financial Sample.xlsx")
.expand(["versions"])
Expand Down
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def export_to_file(path, content):
"--endpoint",
dest="endpoint",
help="Import metadata endpoint",
default="sharepoint",
default="microsoftgraph",
)
parser.add_argument(
"-p",
"--path",
dest="path",
default="./metadata/SharePoint.xml",
default="./metadata/MicrosoftGraph.xml",
help="Import metadata endpoint",
)

Expand Down
181 changes: 173 additions & 8 deletions generator/metadata/MicrosoftGraph.xml

Large diffs are not rendered by default.

82 changes: 77 additions & 5 deletions generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions office365/directory/rolemanagement/resource_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from office365.runtime.client_value import ClientValue
from office365.runtime.types.collections import StringCollection


class ResourceAction(ClientValue):
""" """

def __init__(self):
self.allowedResourceActions = StringCollection()
self.notAllowedResourceActions = StringCollection()
10 changes: 10 additions & 0 deletions office365/directory/rolemanagement/role_permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from office365.directory.rolemanagement.resource_action import ResourceAction
from office365.runtime.client_value import ClientValue
from office365.runtime.client_value_collection import ClientValueCollection


class RolePermission(ClientValue):
""" """

def __init__(self, resourceActions=None):
self.resourceActions = ClientValueCollection(ResourceAction, resourceActions)
12 changes: 12 additions & 0 deletions office365/intune/devices/management/management.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from office365.directory.rolemanagement.role_permission import RolePermission
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.intune.audit.event_collection import AuditEventCollection
Expand All @@ -8,7 +9,10 @@
)
from office365.intune.devices.managed import ManagedDevice
from office365.intune.devices.management.reports.reports import DeviceManagementReports
from office365.runtime.client_result import ClientResult
from office365.runtime.client_value_collection import ClientValueCollection
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.function import FunctionQuery


class DeviceManagement(Entity):
Expand All @@ -18,6 +22,14 @@ class DeviceManagement(Entity):
configuration.
"""

def get_effective_permissions(self, scope=None):
"""Retrieves the effective permissions of the currently authenticated user"""
return_type = ClientResult(self.context, ClientValueCollection(RolePermission))
# params = {"scope": scope}
qry = FunctionQuery(self, "getEffectivePermissions", None, return_type)
self.context.add_query(qry)
return return_type

@property
def audit_events(self):
""""""
Expand Down
9 changes: 6 additions & 3 deletions office365/sharepoint/features/definitions/definition.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from typing import Optional

from office365.sharepoint.entity import Entity


class FeatureDefinition(Entity):
"""Contains the base definition of a feature, including its name, ID, scope, and version."""

def __str__(self):
return self.display_name or self.entity_type_name

@property
def display_name(self):
"""
:rtype: str or None
"""
# type: () -> Optional[str]
return self.properties.get("DisplayName", None)
17 changes: 8 additions & 9 deletions office365/sharepoint/publishing/primary_city_time.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.sharepoint.entity import Entity


Expand All @@ -6,21 +8,18 @@ class PrimaryCityTime(Entity):

@property
def location(self):
"""
:rtype: str or None
"""
# type: () -> Optional[str]
""" """
return self.properties.get("Location", None)

@property
def time(self):
"""
:rtype: str or None
"""
# type: () -> Optional[str]
""""""
return self.properties.get("Time", None)

@property
def utc_offset(self):
"""
:rtype: str or None
"""
# type: () -> Optional[str]
""""""
return self.properties.get("UtcOffset", None)
70 changes: 24 additions & 46 deletions office365/sharepoint/sharing/object_sharing_settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.runtime.paths.resource_path import ResourcePath
from office365.sharepoint.entity import Entity
from office365.sharepoint.sharing.object_sharing_information import (
Expand All @@ -18,84 +20,64 @@ class ObjectSharingSettings(Entity):

@property
def web_url(self):
"""
The URL pointing to the containing SP.Web object.
:rtype: str
"""
# type: () -> Optional[str]
"""The URL pointing to the containing SP.Web object."""
return self.properties.get("WebUrl", None)

@property
def access_request_mode(self):
"""
Boolean indicating whether the sharing context operates under the access request mode.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether the sharing context operates under the access request mode."""
return self.properties.get("AccessRequestMode", None)

@property
def block_people_picker_and_sharing(self):
"""
Boolean indicating whether the current user can use the People Picker to do any sharing.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether the current user can use the People Picker to do any sharing."""
return self.properties.get("BlockPeoplePickerAndSharing", None)

@property
def can_current_user_manage_organization_readonly_link(self):
"""
Boolean indicating whether the current user can create or disable an organization View link.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether the current user can create or disable an organization View link."""
return self.properties.get("CanCurrentUserManageOrganizationReadonlyLink", None)

@property
def can_current_user_manage_organization_read_write_link(self):
"""
Boolean indicating whether the current user can create or disable an organization Edit link.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether the current user can create or disable an organization Edit link."""
return self.properties.get(
"CanCurrentUserManageOrganizationReadWriteLink", None
)

@property
def can_current_user_manage_readonly_link(self):
"""
Boolean indicating whether the current user can create or disable an anonymous View link.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether the current user can create or disable an anonymous View link."""
return self.properties.get("CanCurrentUserManageReadonlyLink", None)

@property
def can_send_email(self):
"""
Boolean indicating whether email invitations can be sent.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether email invitations can be sent."""
return self.properties.get("CanSendEmail", None)

@property
def can_send_link(self):
"""
Boolean indicating whether the current user can make use of Share-By-Link.
:rtype: bool
"""
# type: () -> Optional[bool]
"""Boolean indicating whether the current user can make use of Share-By-Link."""
return self.properties.get("CanSendLink", None)

@property
def is_user_site_admin(self):
"""
Boolean that indicates whether or not the current user is a site collection administrator.
:return: bool
"""
# type: () -> Optional[bool]
"""Boolean that indicates whether or not the current user is a site collection administrator"""
return self.properties.get("IsUserSiteAdmin", None)

@property
def list_id(self):
"""
The unique ID of the parent list (if applicable).
:rtype: str
"""
# type: () -> Optional[str]
"""The unique ID of the parent list (if applicable)."""
return self.properties.get("ListId", None)

@property
Expand All @@ -120,9 +102,7 @@ def object_sharing_information(self):

@property
def sharepoint_settings(self):
"""
An object that contains the SharePoint UI specific sharing settings.
"""
"""An object that contains the SharePoint UI specific sharing settings."""
return self.properties.get(
"SharePointSettings",
SharePointSharingSettings(
Expand All @@ -132,9 +112,7 @@ def sharepoint_settings(self):

@property
def sharing_permissions(self):
"""
A list of SharingPermissionInformation objects that can be used to share.
"""
"""A list of SharingPermissionInformation objects that can be used to share."""
return self.properties.get(
"SharingPermissions",
SharingPermissionInformation(
Expand Down

0 comments on commit c777594

Please sign in to comment.