Skip to content

Commit

Permalink
updates for workbooks namespace in OneDrive API
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Jan 8, 2025
1 parent 1d4d0f6 commit f5230e8
Show file tree
Hide file tree
Showing 29 changed files with 341 additions and 22 deletions.
27 changes: 27 additions & 0 deletions examples/sharepoint/files/get_sharing_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Enumerates files along with role assignments
"""

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.listitem import ListItem
from office365.sharepoint.principal.type import PrincipalType
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
doc_lib = ctx.web.default_document_library()
# retrieve all the files from a library
items = (
doc_lib.items.select(["FSObjType", "EncodedAbsUrl", "Id"])
.filter("FSObjType eq 0")
.get_all()
.execute_query()
)

# per every list item (file facet) retrieve role assignments (where role assignment is associated with a principal,
# which could be a user or a group)
for item in items: # type: ListItem
role_assignments = item.role_assignments.expand(["Member"]).get().execute_query()
print("File: {0}".format(item.properties["EncodedAbsUrl"]))
for ra in role_assignments:
if ra.member.principal_type == PrincipalType.SharePointGroup:
print(ra.member)
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def export_to_file(path, content):
"--endpoint",
dest="endpoint",
help="Import metadata endpoint",
default="graph",
default="sharepoint",
)
parser.add_argument(
"-p",
"--path",
dest="path",
default="./metadata/Graph.xml",
default="./metadata/SharePoint.xml",
help="Import metadata endpoint",
)

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


class Approval(Entity):
"""Represents the approval object for decisions associated with a request.
In PIM for groups, the approval object for decisions to approve or deny requests to activate
group membership or ownership."""
30 changes: 30 additions & 0 deletions office365/directory/identitygovernance/privilegedaccess/group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
from office365.directory.identitygovernance.privilegedaccess.approval import Approval
from office365.directory.identitygovernance.privilegedaccess.group_assignment_schedule_instance import (
PrivilegedAccessGroupAssignmentScheduleInstance,
)
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.runtime.paths.resource_path import ResourcePath


class PrivilegedAccessGroup(Entity):
"""The entry point for all resources related to Privileged Identity Management (PIM) for groups."""

@property
def assignment_approvals(self):
""" """
return self.properties.get(
"assignmentApprovals",
EntityCollection(
self.context,
Approval,
ResourcePath("assignmentApprovals", self.resource_path),
),
)

@property
def assignment_schedule_instances(self):
"""The instances of assignment schedules to activate a just-in-time access."""
return self.properties.get(
"assignmentScheduleInstances",
EntityCollection(
self.context,
PrivilegedAccessGroupAssignmentScheduleInstance,
ResourcePath("assignmentScheduleInstances", self.resource_path),
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
UserConsentRequest,
)
from office365.entity_collection import EntityCollection
from office365.runtime.queries.function import FunctionQuery


class UserConsentRequestCollection(EntityCollection[UserConsentRequest]):
Expand All @@ -11,3 +12,12 @@ def __init__(self, context, resource_path=None):
super(UserConsentRequestCollection, self).__init__(
context, UserConsentRequest, resource_path
)

def filter_by_current_user(self, on):
"""Retrieve a collection of userConsentRequest objects for accessing a specified app, for which the current
user is the reviewer."""
return_type = UserConsentRequestCollection(self.context, self.resource_path)
params = {"on": on}
qry = FunctionQuery(self, "filterByCurrentUser", params, return_type)
self.context.add_query(qry)
return return_type
5 changes: 5 additions & 0 deletions office365/onedrive/sitepages/webparts/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.runtime.client_value import ClientValue


class WebPartData(ClientValue):
""""""
9 changes: 9 additions & 0 deletions office365/onedrive/sitepages/webparts/standard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from typing import Optional

from office365.onedrive.sitepages.webparts.data import WebPartData
from office365.onedrive.sitepages.webparts.web_part import WebPart


class StandardWebPart(WebPart):
"""Represents a standard web part instance on a SharePoint page."""

@property
def data(self):
# type: () -> Optional[WebPartData]
"""Data of the webPart."""
return self.properties.get("data", WebPartData())
36 changes: 35 additions & 1 deletion office365/onedrive/workbooks/charts/chart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.onedrive.workbooks.charts.axes import WorkbookChartAxes
from office365.onedrive.workbooks.charts.data_labels import WorkbookChartDataLabels
from office365.onedrive.workbooks.charts.legend import WorkbookChartLegend
from office365.onedrive.workbooks.charts.series.series import WorkbookChartSeries
from office365.onedrive.workbooks.charts.title import WorkbookChartTitle
from office365.runtime.client_result import ClientResult
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.function import FunctionQuery
Expand Down Expand Up @@ -55,14 +59,44 @@ def axes(self):

@property
def data_labels(self):
"""Represents the datalabels on the chart."""
"""Represents the data labels on the chart."""
return self.properties.get(
"dataLabels",
WorkbookChartDataLabels(
self.context, ResourcePath("dataLabels", self.resource_path)
),
)

@property
def legend(self):
"""Represents the legend on the chart."""
return self.properties.get(
"legend",
WorkbookChartLegend(
self.context, ResourcePath("legend", self.resource_path)
),
)

@property
def series(self):
"""Represents chart series."""
return self.properties.get(
"series",
EntityCollection(
self.context,
WorkbookChartSeries,
ResourcePath("series", self.resource_path),
),
)

@property
def title(self):
"""Represents the title on the chart."""
return self.properties.get(
"title",
WorkbookChartTitle(self.context, ResourcePath("title", self.resource_path)),
)

@property
def worksheet(self):
"""The worksheet containing the current chart."""
Expand Down
2 changes: 0 additions & 2 deletions office365/onedrive/workbooks/charts/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@

class WorkbookChartLegend(Entity):
"""Represents the legend in a chart."""

pass
5 changes: 5 additions & 0 deletions office365/onedrive/workbooks/charts/point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class WorkbookChartPoint(Entity):
"""Represents a point of a series in a chart."""
5 changes: 0 additions & 5 deletions office365/onedrive/workbooks/charts/series.py

This file was deleted.

Empty file.
5 changes: 5 additions & 0 deletions office365/onedrive/workbooks/charts/series/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class WorkbookChartSeriesFormat(Entity):
"""Encapsulates the format properties for the chart series"""
31 changes: 31 additions & 0 deletions office365/onedrive/workbooks/charts/series/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.onedrive.workbooks.charts.point import WorkbookChartPoint
from office365.onedrive.workbooks.charts.series.format import WorkbookChartSeriesFormat
from office365.runtime.paths.resource_path import ResourcePath


class WorkbookChartSeries(Entity):
"""Represents a series in a chart."""

@property
def format(self):
"""The formatting of a chart series, which includes fill and line formatting."""
return self.properties.get(
"format",
WorkbookChartSeriesFormat(
self.context, ResourcePath("format", self.resource_path)
),
)

@property
def points(self):
"""A collection of all points in the series."""
return self.properties.get(
"points",
EntityCollection(
self.context,
WorkbookChartPoint,
ResourcePath("points", self.resource_path),
),
)
5 changes: 5 additions & 0 deletions office365/onedrive/workbooks/charts/title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class WorkbookChartTitle(Entity):
"""Represents a chart title object of a chart."""
10 changes: 10 additions & 0 deletions office365/onedrive/workbooks/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
class WorkbookFilter(Entity):
"""Manages the filtering of a table's column."""

def apply_bottom_items_filter(self, count=None):
"""Perform a sort operation.
:param str count: The number of items to apply the filter to.
"""
payload = {"count": count}
qry = ServiceOperationQuery(self, "applyBottomItemsFilter", None, payload)
self.context.add_query(qry)
return self

def clear(self):
"""Clear the filter on the given column."""
qry = ServiceOperationQuery(self, "clear")
Expand Down
6 changes: 3 additions & 3 deletions office365/onedrive/workbooks/filter_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
class WorkbookFilterCriteria(ClientValue):
"""Represents the filtering criteria applied to a column."""

def __init__(self, color=None, dynamicCriteria=None, operator=None, values=None):
def __init__(self, color=None, dynamic_criteria=None, operator=None, values=None):
"""
:param str color: The color applied to the cell.
:param str dynamicCriteria: A dynamic formula specified in a custom filter.
:param str dynamic_criteria: A dynamic formula specified in a custom filter.
:param str operator: An operator in a cell; for example, =, >, <, <=, or <>.
:param list values: The values that appear in the cell.
"""
self.color = color
self.dynamicCriteria = dynamicCriteria
self.dynamicCriteria = dynamic_criteria
self.operator = operator
self.values = values
12 changes: 11 additions & 1 deletion office365/onedrive/workbooks/ranges/fill.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from typing import Optional

from office365.entity import Entity


class WorkbookRangeFill(Entity):
"""Represents the background of a range object."""
"""HTML color code representing the color of the border line. Can either be of the form #RRGGBB,
for example "FFA500", or be a named HTML color, for example "orange"."""

@property
def color(self):
# type: () -> Optional[str]
"""Gets or sets the width of all columns within the range. If the column widths aren't uniform,
null will be returned."""
return self.properties.get("color", None)
9 changes: 9 additions & 0 deletions office365/onedrive/workbooks/ranges/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def insert(self, shift):
self.context.add_query(qry)
return return_type

def last_row(self):
"""
Get the last row within the range. For example, the last row of B2:D5 is B5:D5.
"""
return_type = WorkbookRange(self.context)
qry = FunctionQuery(self, "lastRow", return_type=return_type)
self.context.add_query(qry)
return return_type

def visible_view(self):
"""Get the range visible from a filtered range."""
return_type = WorkbookRangeView(self.context)
Expand Down
14 changes: 14 additions & 0 deletions office365/onedrive/workbooks/ranges/view.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.runtime.paths.resource_path import ResourcePath
Expand All @@ -6,6 +8,18 @@
class WorkbookRangeView(Entity):
"""Represents a set of visible cells of the parent range."""

@property
def cell_addresses(self):
# type: () -> Optional[dict]
"""The cell addresses."""
return self.properties.get("cellAddresses", None)

@property
def column_count(self):
# type: () -> Optional[int]
"""The number of visible columns."""
return self.properties.get("columnCount", None)

@property
def rows(self):
# type: () -> EntityCollection[WorkbookRangeView]
Expand Down
11 changes: 8 additions & 3 deletions office365/onedrive/workbooks/sort_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ class WorkbookSortField(ClientValue):
"""Represents a condition in a sorting operation."""

def __init__(
self, ascending=None, color=None, dataOption=None, icon=WorkbookIcon(), key=None
self,
ascending=None,
color=None,
data_option=None,
icon=WorkbookIcon(),
key=None,
):
"""
:param bool ascending: Represents whether the sorting is done in an ascending fashion.
:param str color: Represents the color that is the target of the condition if the sorting is on font
or cell color.
:param str dataOption: Represents additional sorting options for this field.
:param str data_option: Represents additional sorting options for this field.
Possible values are: Normal, TextAsNumber.
:param WorkbookIcon icon: Represents the icon that is the target of the condition if the sorting
is on the cell's icon.
Expand All @@ -21,6 +26,6 @@ def __init__(
"""
self.ascending = ascending
self.color = color
self.dataOption = dataOption
self.dataOption = data_option
self.icon = icon
self.key = key
20 changes: 20 additions & 0 deletions office365/onedrive/workbooks/tables/sort.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from office365.entity import Entity
from office365.onedrive.workbooks.sort_field import WorkbookSortField
from office365.runtime.client_value_collection import ClientValueCollection
from office365.runtime.queries.service_operation import ServiceOperationQuery


class WorkbookTableSort(Entity):
"""Manages sorting operations on Table objects."""

def apply(self, fields, match_case=None, method=None):
"""Perform a sort operation.
:param list[WorkbookSortField] fields: The list of conditions to sort on.
:param bool match_case: Indicates whether to match the case of the items being sorted.
:param str method: The ordering method used for Chinese characters.
The possible values are: PinYin, StrokeCount.
"""
payload = {
"fields": ClientValueCollection(WorkbookSortField, fields),
"matchCase": match_case,
"method": method,
}
qry = ServiceOperationQuery(self, "apply", None, payload)
self.context.add_query(qry)
return self
Loading

0 comments on commit f5230e8

Please sign in to comment.