Skip to content

Commit f5230e8

Browse files
committed
updates for workbooks namespace in OneDrive API
1 parent 1d4d0f6 commit f5230e8

File tree

29 files changed

+341
-22
lines changed

29 files changed

+341
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Enumerates files along with role assignments
3+
"""
4+
5+
from office365.sharepoint.client_context import ClientContext
6+
from office365.sharepoint.listitems.listitem import ListItem
7+
from office365.sharepoint.principal.type import PrincipalType
8+
from tests import test_client_credentials, test_team_site_url
9+
10+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
11+
doc_lib = ctx.web.default_document_library()
12+
# retrieve all the files from a library
13+
items = (
14+
doc_lib.items.select(["FSObjType", "EncodedAbsUrl", "Id"])
15+
.filter("FSObjType eq 0")
16+
.get_all()
17+
.execute_query()
18+
)
19+
20+
# per every list item (file facet) retrieve role assignments (where role assignment is associated with a principal,
21+
# which could be a user or a group)
22+
for item in items: # type: ListItem
23+
role_assignments = item.role_assignments.expand(["Member"]).get().execute_query()
24+
print("File: {0}".format(item.properties["EncodedAbsUrl"]))
25+
for ra in role_assignments:
26+
if ra.member.principal_type == PrincipalType.SharePointGroup:
27+
print(ra.member)

generator/import_metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def export_to_file(path, content):
2626
"--endpoint",
2727
dest="endpoint",
2828
help="Import metadata endpoint",
29-
default="graph",
29+
default="sharepoint",
3030
)
3131
parser.add_argument(
3232
"-p",
3333
"--path",
3434
dest="path",
35-
default="./metadata/Graph.xml",
35+
default="./metadata/SharePoint.xml",
3636
help="Import metadata endpoint",
3737
)
3838

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.entity import Entity
2+
3+
4+
class Approval(Entity):
5+
"""Represents the approval object for decisions associated with a request.
6+
7+
In PIM for groups, the approval object for decisions to approve or deny requests to activate
8+
group membership or ownership."""
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1+
from office365.directory.identitygovernance.privilegedaccess.approval import Approval
2+
from office365.directory.identitygovernance.privilegedaccess.group_assignment_schedule_instance import (
3+
PrivilegedAccessGroupAssignmentScheduleInstance,
4+
)
15
from office365.entity import Entity
6+
from office365.entity_collection import EntityCollection
7+
from office365.runtime.paths.resource_path import ResourcePath
28

39

410
class PrivilegedAccessGroup(Entity):
511
"""The entry point for all resources related to Privileged Identity Management (PIM) for groups."""
12+
13+
@property
14+
def assignment_approvals(self):
15+
""" """
16+
return self.properties.get(
17+
"assignmentApprovals",
18+
EntityCollection(
19+
self.context,
20+
Approval,
21+
ResourcePath("assignmentApprovals", self.resource_path),
22+
),
23+
)
24+
25+
@property
26+
def assignment_schedule_instances(self):
27+
"""The instances of assignment schedules to activate a just-in-time access."""
28+
return self.properties.get(
29+
"assignmentScheduleInstances",
30+
EntityCollection(
31+
self.context,
32+
PrivilegedAccessGroupAssignmentScheduleInstance,
33+
ResourcePath("assignmentScheduleInstances", self.resource_path),
34+
),
35+
)

office365/directory/identitygovernance/userconsent/request_collection.py

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
UserConsentRequest,
33
)
44
from office365.entity_collection import EntityCollection
5+
from office365.runtime.queries.function import FunctionQuery
56

67

78
class UserConsentRequestCollection(EntityCollection[UserConsentRequest]):
@@ -11,3 +12,12 @@ def __init__(self, context, resource_path=None):
1112
super(UserConsentRequestCollection, self).__init__(
1213
context, UserConsentRequest, resource_path
1314
)
15+
16+
def filter_by_current_user(self, on):
17+
"""Retrieve a collection of userConsentRequest objects for accessing a specified app, for which the current
18+
user is the reviewer."""
19+
return_type = UserConsentRequestCollection(self.context, self.resource_path)
20+
params = {"on": on}
21+
qry = FunctionQuery(self, "filterByCurrentUser", params, return_type)
22+
self.context.add_query(qry)
23+
return return_type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class WebPartData(ClientValue):
5+
""""""
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
from typing import Optional
2+
3+
from office365.onedrive.sitepages.webparts.data import WebPartData
14
from office365.onedrive.sitepages.webparts.web_part import WebPart
25

36

47
class StandardWebPart(WebPart):
58
"""Represents a standard web part instance on a SharePoint page."""
9+
10+
@property
11+
def data(self):
12+
# type: () -> Optional[WebPartData]
13+
"""Data of the webPart."""
14+
return self.properties.get("data", WebPartData())

office365/onedrive/workbooks/charts/chart.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from office365.entity import Entity
2+
from office365.entity_collection import EntityCollection
23
from office365.onedrive.workbooks.charts.axes import WorkbookChartAxes
34
from office365.onedrive.workbooks.charts.data_labels import WorkbookChartDataLabels
5+
from office365.onedrive.workbooks.charts.legend import WorkbookChartLegend
6+
from office365.onedrive.workbooks.charts.series.series import WorkbookChartSeries
7+
from office365.onedrive.workbooks.charts.title import WorkbookChartTitle
48
from office365.runtime.client_result import ClientResult
59
from office365.runtime.paths.resource_path import ResourcePath
610
from office365.runtime.queries.function import FunctionQuery
@@ -55,14 +59,44 @@ def axes(self):
5559

5660
@property
5761
def data_labels(self):
58-
"""Represents the datalabels on the chart."""
62+
"""Represents the data labels on the chart."""
5963
return self.properties.get(
6064
"dataLabels",
6165
WorkbookChartDataLabels(
6266
self.context, ResourcePath("dataLabels", self.resource_path)
6367
),
6468
)
6569

70+
@property
71+
def legend(self):
72+
"""Represents the legend on the chart."""
73+
return self.properties.get(
74+
"legend",
75+
WorkbookChartLegend(
76+
self.context, ResourcePath("legend", self.resource_path)
77+
),
78+
)
79+
80+
@property
81+
def series(self):
82+
"""Represents chart series."""
83+
return self.properties.get(
84+
"series",
85+
EntityCollection(
86+
self.context,
87+
WorkbookChartSeries,
88+
ResourcePath("series", self.resource_path),
89+
),
90+
)
91+
92+
@property
93+
def title(self):
94+
"""Represents the title on the chart."""
95+
return self.properties.get(
96+
"title",
97+
WorkbookChartTitle(self.context, ResourcePath("title", self.resource_path)),
98+
)
99+
66100
@property
67101
def worksheet(self):
68102
"""The worksheet containing the current chart."""

office365/onedrive/workbooks/charts/legend.py

-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33

44
class WorkbookChartLegend(Entity):
55
"""Represents the legend in a chart."""
6-
7-
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class WorkbookChartPoint(Entity):
5+
"""Represents a point of a series in a chart."""

office365/onedrive/workbooks/charts/series.py

-5
This file was deleted.

office365/onedrive/workbooks/charts/series/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class WorkbookChartSeriesFormat(Entity):
5+
"""Encapsulates the format properties for the chart series"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from office365.entity import Entity
2+
from office365.entity_collection import EntityCollection
3+
from office365.onedrive.workbooks.charts.point import WorkbookChartPoint
4+
from office365.onedrive.workbooks.charts.series.format import WorkbookChartSeriesFormat
5+
from office365.runtime.paths.resource_path import ResourcePath
6+
7+
8+
class WorkbookChartSeries(Entity):
9+
"""Represents a series in a chart."""
10+
11+
@property
12+
def format(self):
13+
"""The formatting of a chart series, which includes fill and line formatting."""
14+
return self.properties.get(
15+
"format",
16+
WorkbookChartSeriesFormat(
17+
self.context, ResourcePath("format", self.resource_path)
18+
),
19+
)
20+
21+
@property
22+
def points(self):
23+
"""A collection of all points in the series."""
24+
return self.properties.get(
25+
"points",
26+
EntityCollection(
27+
self.context,
28+
WorkbookChartPoint,
29+
ResourcePath("points", self.resource_path),
30+
),
31+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class WorkbookChartTitle(Entity):
5+
"""Represents a chart title object of a chart."""

office365/onedrive/workbooks/filter.py

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
class WorkbookFilter(Entity):
99
"""Manages the filtering of a table's column."""
1010

11+
def apply_bottom_items_filter(self, count=None):
12+
"""Perform a sort operation.
13+
14+
:param str count: The number of items to apply the filter to.
15+
"""
16+
payload = {"count": count}
17+
qry = ServiceOperationQuery(self, "applyBottomItemsFilter", None, payload)
18+
self.context.add_query(qry)
19+
return self
20+
1121
def clear(self):
1222
"""Clear the filter on the given column."""
1323
qry = ServiceOperationQuery(self, "clear")

office365/onedrive/workbooks/filter_criteria.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
class WorkbookFilterCriteria(ClientValue):
55
"""Represents the filtering criteria applied to a column."""
66

7-
def __init__(self, color=None, dynamicCriteria=None, operator=None, values=None):
7+
def __init__(self, color=None, dynamic_criteria=None, operator=None, values=None):
88
"""
99
:param str color: The color applied to the cell.
10-
:param str dynamicCriteria: A dynamic formula specified in a custom filter.
10+
:param str dynamic_criteria: A dynamic formula specified in a custom filter.
1111
:param str operator: An operator in a cell; for example, =, >, <, <=, or <>.
1212
:param list values: The values that appear in the cell.
1313
"""
1414
self.color = color
15-
self.dynamicCriteria = dynamicCriteria
15+
self.dynamicCriteria = dynamic_criteria
1616
self.operator = operator
1717
self.values = values
+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
24

35

46
class WorkbookRangeFill(Entity):
5-
"""Represents the background of a range object."""
7+
"""HTML color code representing the color of the border line. Can either be of the form #RRGGBB,
8+
for example "FFA500", or be a named HTML color, for example "orange"."""
9+
10+
@property
11+
def color(self):
12+
# type: () -> Optional[str]
13+
"""Gets or sets the width of all columns within the range. If the column widths aren't uniform,
14+
null will be returned."""
15+
return self.properties.get("color", None)

office365/onedrive/workbooks/ranges/range.py

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ def insert(self, shift):
5454
self.context.add_query(qry)
5555
return return_type
5656

57+
def last_row(self):
58+
"""
59+
Get the last row within the range. For example, the last row of B2:D5 is B5:D5.
60+
"""
61+
return_type = WorkbookRange(self.context)
62+
qry = FunctionQuery(self, "lastRow", return_type=return_type)
63+
self.context.add_query(qry)
64+
return return_type
65+
5766
def visible_view(self):
5867
"""Get the range visible from a filtered range."""
5968
return_type = WorkbookRangeView(self.context)

office365/onedrive/workbooks/ranges/view.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
24
from office365.entity_collection import EntityCollection
35
from office365.runtime.paths.resource_path import ResourcePath
@@ -6,6 +8,18 @@
68
class WorkbookRangeView(Entity):
79
"""Represents a set of visible cells of the parent range."""
810

11+
@property
12+
def cell_addresses(self):
13+
# type: () -> Optional[dict]
14+
"""The cell addresses."""
15+
return self.properties.get("cellAddresses", None)
16+
17+
@property
18+
def column_count(self):
19+
# type: () -> Optional[int]
20+
"""The number of visible columns."""
21+
return self.properties.get("columnCount", None)
22+
923
@property
1024
def rows(self):
1125
# type: () -> EntityCollection[WorkbookRangeView]

office365/onedrive/workbooks/sort_field.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ class WorkbookSortField(ClientValue):
66
"""Represents a condition in a sorting operation."""
77

88
def __init__(
9-
self, ascending=None, color=None, dataOption=None, icon=WorkbookIcon(), key=None
9+
self,
10+
ascending=None,
11+
color=None,
12+
data_option=None,
13+
icon=WorkbookIcon(),
14+
key=None,
1015
):
1116
"""
1217
:param bool ascending: Represents whether the sorting is done in an ascending fashion.
1318
:param str color: Represents the color that is the target of the condition if the sorting is on font
1419
or cell color.
15-
:param str dataOption: Represents additional sorting options for this field.
20+
:param str data_option: Represents additional sorting options for this field.
1621
Possible values are: Normal, TextAsNumber.
1722
:param WorkbookIcon icon: Represents the icon that is the target of the condition if the sorting
1823
is on the cell's icon.
@@ -21,6 +26,6 @@ def __init__(
2126
"""
2227
self.ascending = ascending
2328
self.color = color
24-
self.dataOption = dataOption
29+
self.dataOption = data_option
2530
self.icon = icon
2631
self.key = key
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
from office365.entity import Entity
2+
from office365.onedrive.workbooks.sort_field import WorkbookSortField
3+
from office365.runtime.client_value_collection import ClientValueCollection
4+
from office365.runtime.queries.service_operation import ServiceOperationQuery
25

36

47
class WorkbookTableSort(Entity):
58
"""Manages sorting operations on Table objects."""
9+
10+
def apply(self, fields, match_case=None, method=None):
11+
"""Perform a sort operation.
12+
13+
:param list[WorkbookSortField] fields: The list of conditions to sort on.
14+
:param bool match_case: Indicates whether to match the case of the items being sorted.
15+
:param str method: The ordering method used for Chinese characters.
16+
The possible values are: PinYin, StrokeCount.
17+
"""
18+
payload = {
19+
"fields": ClientValueCollection(WorkbookSortField, fields),
20+
"matchCase": match_case,
21+
"method": method,
22+
}
23+
qry = ServiceOperationQuery(self, "apply", None, payload)
24+
self.context.add_query(qry)
25+
return self

0 commit comments

Comments
 (0)