Skip to content

Commit

Permalink
typings enhancements and examples updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Nov 11, 2023
1 parent 7dadd19 commit d4021b0
Show file tree
Hide file tree
Showing 35 changed files with 266 additions and 210 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
site_pages = ctx.site_pages.pages.get().execute_query()
for site_page in site_pages:
print(site_page.file_name)
print(site_page)
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Creates a site
"""

import json
from random import randint

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
alias = create_unique_name("teamsite")
title = "Team Site"
ctx = ClientContext(test_site_url).with_credentials(test_user_credentials)

site = ctx.create_team_site(alias, title).execute_query()
print(site.url)

# cleanup: remove resource
site.delete_object().execute_query()
site.delete_object().execute_query() # cleanup: remove resource
6 changes: 4 additions & 2 deletions examples/sharepoint/sites/download_logo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
Downloads a site logo
"""
import os
import tempfile

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

client = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
site = client.site.get().execute_query()
result = client.group_service.get_group_image(group_id=site.group_id).execute_query()
result = client.site.get_site_logo_ex().execute_query()
download_path = os.path.join(tempfile.mkdtemp(), "SiteLogo.png")
with open(download_path, "wb") as f:
f.write(result.value)
Expand Down
3 changes: 1 addition & 2 deletions examples/sharepoint/sites/get_my_site.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Get current user personal site
Get personal site for current user
"""
from office365.sharepoint.client_context import ClientContext
from tests import test_team_site_url, test_user_credentials
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/sharepoint/teams/list_my.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Get the teams in Microsoft Teams that the current user is a direct member of
"""

import json

from office365.sharepoint.client_context import ClientContext
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion examples/sharepoint/webs/get_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
client = ClientContext(test_site_url).with_credentials(test_client_credentials)
role_defs = client.web.role_definitions.get().execute_query()
for role_def in role_defs:
print(role_def.name)
print(role_def)
161 changes: 128 additions & 33 deletions generator/metadata/MicrosoftGraph.xml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions office365/communications/presences/presence.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.communications.presences.status_message import PresenceStatusMessage
from office365.entity import Entity
from office365.outlook.mail.item_body import ItemBody
Expand Down Expand Up @@ -88,22 +90,20 @@ def set_user_preferred_presence(

@property
def activity(self):
# type: () -> Optional[str]
"""
The supplemental information to a user's availability.
Possible values are Available, Away, BeRightBack, Busy, DoNotDisturb, InACall, InAConferenceCall, Inactive,
InAMeeting, Offline, OffWork, OutOfOffice, PresenceUnknown, Presenting, UrgentInterruptionsOnly.
:rtype: str or None
"""
return self.properties.get("activity", None)

@property
def availability(self):
# type: () -> Optional[str]
"""
The base presence information for a user.
Possible values are Available, AvailableIdle, Away, BeRightBack, Busy, BusyIdle, DoNotDisturb, Offline,
PresenceUnknown
:rtype: str or None
"""
return self.properties.get("availability", None)
13 changes: 6 additions & 7 deletions office365/directory/administrative_unit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.directory.extensions.extension import Extension
from office365.directory.object import DirectoryObject
from office365.entity_collection import EntityCollection
Expand All @@ -14,10 +16,8 @@ class AdministrativeUnit(DirectoryObject):

@property
def display_name(self):
"""
Display name for the administrative unit
:rtype: str or None
"""
# type: () -> Optional[str]
"""Display name for the administrative unit"""
return self.properties.get("displayName", None)

@property
Expand All @@ -36,9 +36,8 @@ def members(self):

@property
def extensions(self):
"""
The collection of open extensions defined for this administrative unit.
"""
# type: () -> EntityCollection[Extension]
"""The collection of open extensions defined for this administrative unit."""
return self.properties.get(
"extensions",
EntityCollection(
Expand Down
14 changes: 4 additions & 10 deletions office365/directory/users/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,37 +624,31 @@ def insights(self):

@property
def photo(self):
"""
The user's profile photo. Read-only.
"""
"""The user's profile photo. Read-only."""
return self.properties.get(
"photo",
ProfilePhoto(self.context, ResourcePath("photo", self.resource_path)),
)

@property
def manager(self):
"""
The user or contact that is this user's manager
"""
"""The user or contact that is this user's manager"""
return self.properties.get(
"manager",
DirectoryObject(self.context, ResourcePath("manager", self.resource_path)),
)

@property
def preferred_language(self):
# type: () -> Optional[str]
"""
The preferred language for the user. Should follow ISO 639-1 Code; for example en-US.
:rtype: str or None
"""
return self.properties.get("preferredLanguage", None)

@property
def mailbox_settings(self):
"""
Get the user's mailboxSettings.
"""
"""Get the user's mailboxSettings."""
return self.properties.get("mailboxSettings", MailboxSettings())

@property
Expand Down
10 changes: 6 additions & 4 deletions office365/intune/devices/enrollment/configuration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import datetime
from typing import Optional

from office365.entity import Entity


class DeviceEnrollmentConfiguration(Entity):
"""The Base Class of Device Enrollment Configuration"""

def __str__(self):
return self.display_name

@property
def created_datetime(self):
"""
Expand All @@ -15,10 +19,8 @@ def created_datetime(self):

@property
def display_name(self):
"""
The display name of the device enrollment configuration
:rtype: str
"""
# type: () -> Optional[str]
"""The display name of the device enrollment configuration"""
return self.properties.get("displayName", None)

def get_property(self, name, default_value=None):
Expand Down
21 changes: 9 additions & 12 deletions office365/intune/devices/managed.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.intune.devices.category import DeviceCategory
Expand All @@ -17,12 +19,12 @@ def locate_device(self):

@property
def activation_lock_bypass_code(self):
# type: () -> Optional[str]
"""
The code that allows the Activation Lock on managed device to be bypassed. Default,
is Null (Non-Default property) for this property when returned as part of managedDevice entity in LIST call.
To retrieve actual values GET call needs to be made, with device id and included in select parameter.
Supports: $select. $Search is not supported. Read-only. This property is read-only.
:rtype: str
"""
return self.properties.get("activationLockBypassCode", None)

Expand All @@ -38,25 +40,20 @@ def device_category(self):

@property
def manufacturer(self):
"""
Manufacturer of the device.
:rtype: str
"""
# type: () -> Optional[str]
"""Manufacturer of the device."""
return self.properties.get("manufacturer", None)

@property
def operating_system(self):
"""
Manufacturer of the device.
:rtype: str
"""
# type: () -> Optional[str]
"""Manufacturer of the device."""
return self.properties.get("operatingSystem", None)

@property
def device_compliance_policy_states(self):
"""
Device compliance policy states for this device
"""
# type: () -> EntityCollection[DeviceCompliancePolicyState]
"""Device compliance policy states for this device"""
return self.properties.get(
"deviceCompliancePolicyStates",
EntityCollection(
Expand Down
4 changes: 1 addition & 3 deletions office365/onedrive/columns/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ def is_deletable(self):
@property
def is_reorderable(self):
# type: () -> Optional[bool]
"""
Indicates whether values in the column can be reordered. Read-only.
"""
"""Indicates whether values in the column can be reordered."""
return self.properties.get("isReorderable", None)

@property
Expand Down
11 changes: 3 additions & 8 deletions office365/onedrive/termstore/groups/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
from office365.onedrive.termstore.groups.group import Group


class GroupCollection(EntityCollection):
class GroupCollection(EntityCollection[Group]):
def __init__(self, context, resource_path=None):
super(GroupCollection, self).__init__(context, Group, resource_path)

def add(self, display_name):
"""
Create a new group object in a term store.
:param str display_name: Name of the group to be created.
:rtype: Group
"""
props = {"displayName": display_name}
return super(GroupCollection, self).add(**props)

def get_by_name(self, name):
"""Returns the group with the specified name.
:param str name: Group name
:rtype: Group
"""
# type: (str) -> Group
"""Returns the group with the specified name."""
return self.single("displayName eq '{0}'".format(name))
7 changes: 1 addition & 6 deletions office365/onedrive/termstore/sets/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ def __init__(self, context, resource_path=None, parent_group=None):
self._parent_group = parent_group

def get_by_name(self, name):
"""
Returns the TermSet specified by its name.
:param str name: Term set name
:rtype: Set
"""
"""Returns the TermSet specified by its name."""
return self.single("displayName eq '{0}'".format(name))

def add(self, name, parent_group=None):
Expand Down
9 changes: 5 additions & 4 deletions office365/onenote/resources/resource.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import AnyStr, Optional

from office365.onenote.entity_base_model import OnenoteEntityBaseModel
from office365.runtime.client_result import ClientResult
from office365.runtime.queries.function import FunctionQuery
Expand All @@ -7,6 +9,7 @@ class OnenoteResource(OnenoteEntityBaseModel):
"""An image or other file resource on a OneNote page."""

def get_content(self):
# type: () -> ClientResult[AnyStr]
"""Retrieve the binary data of a file or image resource object."""
return_type = ClientResult(self.context)
qry = FunctionQuery(self, "content", None, return_type)
Expand All @@ -15,8 +18,6 @@ def get_content(self):

@property
def content_url(self):
"""The URL for downloading the content
:rtype: str or None
"""
# type: () -> Optional[str]
"""The URL for downloading the content"""
return self.properties.get("contentUrl", None)
6 changes: 4 additions & 2 deletions office365/runtime/client_object_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def single(self, expression):
"""
return_type = self.create_typed_object()
self.add_child(return_type)
key = return_type.property_ref_name

def _after_loaded(col):
# type: (ClientObjectCollection) -> None
Expand All @@ -233,7 +232,10 @@ def _after_loaded(col):
elif len(col) > 1:
message = "Ambiguous match found for filter: {0}".format(expression)
raise ValueError(message)
return_type.set_property(key, col[0].get_property(key), False)
[
return_type.set_property(k, v, False)
for k, v in col[0].properties.items()
]

self.filter(expression).top(2)
self.context.load(self, after_loaded=_after_loaded)
Expand Down
4 changes: 2 additions & 2 deletions office365/runtime/paths/service_operation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from office365.runtime.odata.url_builder import ODataUrlBuilder
from office365.runtime.paths.builder import ODataPathBuilder
from office365.runtime.paths.resource_path import ResourcePath


Expand All @@ -16,7 +16,7 @@ def __init__(self, name, parameters=None, parent=None):

@property
def segment(self):
return ODataUrlBuilder.build_segment(self)
return ODataPathBuilder.build_segment(self)

@property
def parameters(self):
Expand Down
4 changes: 4 additions & 0 deletions office365/sharepoint/files/versions/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def get_by_id(self, version_id):
ServiceOperationPath("getById", [version_id], self.resource_path),
)

def get_by_label(self, label):
"""Gets the file version with the specified Label."""
return self.single("VersionLabel eq '{0}'".format(label))

def delete_all(self):
"""Deletes all the file version objects in the collection."""
qry = ServiceOperationQuery(self, "DeleteAll")
Expand Down
2 changes: 1 addition & 1 deletion office365/sharepoint/files/versions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_property(self, name, default_value=None):
def set_property(self, key, value, persist_changes=True):
super(FileVersion, self).set_property(key, value, persist_changes)
if self._resource_path is None:
if key == "ID":
if key == self.property_ref_name:
self._resource_path = KeyPath(
value, self.parent_collection.resource_path
)
Expand Down
Loading

0 comments on commit d4021b0

Please sign in to comment.