Skip to content

Commit cf62fa6

Browse files
committed
miscellaneous: add new types and methods for SharePoint API
1 parent 09ecb30 commit cf62fa6

39 files changed

+750
-31
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Find consent grants for app permissions
3+
"""
4+
5+
from office365.graph_client import GraphClient
6+
from tests import test_client_id, test_client_secret, test_tenant
7+
8+
client = GraphClient(tenant=test_tenant).with_client_secret(
9+
test_client_id, test_client_secret
10+
)
11+
12+
13+
col = client.service_principals.get().execute_query()
14+
for sp in col:
15+
print("--- ", sp.display_name, " ---")
16+
17+
grants = sp.oauth2_permission_grants.get().execute_query()
18+
if len(grants) > 0:
19+
print("Delegated Permissions (User Consent)")
20+
for grant in grants:
21+
consent_info = grant.consent_type
22+
if grant.consent_type != "AllPrincipals":
23+
user = client.users[grant.principal_id].get().execute_query()
24+
consent_info += " (" + user.user_principal_name + ")"
25+
print(consent_info, ": ", grant.scope)
26+
27+
app_roles = sp.app_role_assignments.get().execute_query()
28+
if len(app_roles) > 0:
29+
print("Application Permissions (Admin Consent)")
30+
for app_role in app_roles:
31+
resource_sp = (
32+
client.service_principals[app_role.resource_id].get().execute_query()
33+
)
34+
print(app_role.resource_display_name, ": ", resource_sp.app_roles)

examples/sharepoint/sharing/share_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
print(json.dumps(result.value.to_json(), indent=4))
2929
link_url = result.value.sharingLinkInfo.Url
3030

31-
print("Verifyng sharing link ...")
31+
print("Verifying sharing link ...")
3232
result = Web.get_sharing_link_kind(ctx, link_url).execute_query()
3333
print(sharing_messages.get(result.value, "Unknown sharing link"))
3434

@@ -39,6 +39,6 @@
3939
print("Unsharing a file link...")
4040
remote_file.unshare_link(SharingLinkKind.AnonymousView).execute_query()
4141

42-
# Get a file sharing info
42+
# Get file sharing info
4343
info = remote_file.get_sharing_information().execute_query()
4444
print("AnonymousViewLink:", info.properties.get("AnonymousViewLink"))

office365/directory/protection/information.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,60 @@
1111
class InformationProtection(Entity):
1212
"""Exposes methods that you can use to get Microsoft Purview Information Protection labels and label policies."""
1313

14+
def create_email_file_assessment(
15+
self, recipient_email, content_data, expected_assessment, category
16+
):
17+
"""Create an email assessment request
18+
19+
:param str recipient_email: The mail recipient whose policies are used to assess the mail.
20+
:param str content_data: Base64 encoded file content. The file content can't fetch back because it isn't stored.
21+
:param str expected_assessment: The expected assessment from submitter. Possible values are: block, unblock.
22+
:param str category: The threat category. Possible values are: spam, phishing, malware.
23+
"""
24+
25+
from office365.directory.protection.threatassessment.requests.email_file import (
26+
EmailFileAssessmentRequest,
27+
)
28+
29+
return_type = EmailFileAssessmentRequest(self.context)
30+
return_type.set_property("recipientEmail", recipient_email)
31+
return_type.set_property("contentData", content_data)
32+
return_type.set_property("expectedAssessment", expected_assessment)
33+
return_type.set_property("category", category)
34+
self.threat_assessment_requests.add_child(return_type)
35+
qry = CreateEntityQuery(
36+
self.threat_assessment_requests, return_type, return_type
37+
)
38+
self.context.add_query(qry)
39+
return return_type
40+
41+
def create_file_assessment(
42+
self, file_name, content_data, expected_assessment, category
43+
):
44+
"""Create a new threat assessment request.
45+
46+
:param str file_name: File name
47+
:param str content_data: Base64 encoded file content. The file content can't fetch back because it isn't stored.
48+
:param str expected_assessment: The expected assessment from submitter. Possible values are: block, unblock.
49+
:param str category: The threat category. Possible values are: spam, phishing, malware.
50+
"""
51+
52+
from office365.directory.protection.threatassessment.requests.file import (
53+
FileAssessmentRequest,
54+
)
55+
56+
return_type = FileAssessmentRequest(self.context)
57+
return_type.set_property("fileName", file_name)
58+
return_type.set_property("contentData", content_data)
59+
return_type.set_property("expectedAssessment", expected_assessment)
60+
return_type.set_property("category", category)
61+
self.threat_assessment_requests.add_child(return_type)
62+
qry = CreateEntityQuery(
63+
self.threat_assessment_requests, return_type, return_type
64+
)
65+
self.context.add_query(qry)
66+
return return_type
67+
1468
def create_url_assessment(self, url, expected_assessment, category):
1569
"""Create a new threat assessment request."""
1670
from office365.directory.protection.threatassessment.requests.url import (
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from office365.directory.protection.threatassessment.requests.request import (
2+
ThreatAssessmentRequest,
3+
)
4+
5+
6+
class FileAssessmentRequest(ThreatAssessmentRequest):
7+
"""Used to create and retrieve a file threat assessment, derived from threatAssessmentRequest.
8+
9+
The file can be a text file or Word document or binary file received in an email attachment.
10+
"""

office365/sharepoint/activities/client_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
class ActivityClientResponse(ClientValue):
55
""""""
66

7-
def __init__(self, id_, message=None, serverId=None, status=None):
7+
def __init__(self, id_, message=None, server_id=None, status=None):
88
# type: (str, str, str, int) -> None
99
""" """
1010
self.id = id_
1111
self.message = message
12-
self.serverId = serverId
12+
self.serverId = server_id
1313
self.status = status
1414

1515
@property

office365/sharepoint/client_context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ def client_people_picker(self):
417417

418418
return ClientPeoplePickerWebServiceInterface(self)
419419

420+
@property
421+
def component_context_info(self):
422+
"""ComponentContextInfo alias"""
423+
424+
from office365.sharepoint.clientsidecomponent.component_context_info import (
425+
ComponentContextInfo,
426+
)
427+
428+
return ComponentContextInfo(self, ResourcePath("ComponentContextInfo"))
429+
420430
@property
421431
def consumer_permissions(self):
422432
"""Consumer permissions alias"""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.entity import Entity
2+
3+
4+
class PreserveDocumentSubmitter(Entity):
5+
""" """

office365/sharepoint/compliance/store_proxy.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313

1414
class SPPolicyStoreProxy(Entity):
15+
""" """
16+
1517
@staticmethod
1618
def check_site_is_deletable_by_id(context, site_id, return_type=None):
1719
# type: (ClientContext, str, Optional[ClientResult[bool]]) -> ClientResult[bool]
@@ -84,6 +86,79 @@ def get_dynamic_scope_binding_by_site_id(self, site_id):
8486
self.context.add_query(qry)
8587
return return_type
8688

89+
@staticmethod
90+
def get_list_compliance_tag(context, list_url, return_type=None):
91+
""" """
92+
if return_type is None:
93+
return_type = ClientResult(context, ComplianceTag())
94+
payload = {"listUrl": list_url}
95+
qry = ServiceOperationQuery(
96+
SPPolicyStoreProxy(context),
97+
"GetListComplianceTag",
98+
None,
99+
payload,
100+
None,
101+
return_type,
102+
True,
103+
)
104+
context.add_query(qry)
105+
return return_type
106+
107+
@staticmethod
108+
def set_list_compliance_tag(
109+
context,
110+
list_url,
111+
compliance_tag_value,
112+
block_delete=None,
113+
block_edit=None,
114+
sync_to_items=None,
115+
):
116+
""" """
117+
payload = {
118+
"listUrl": list_url,
119+
"complianceTagValue": compliance_tag_value,
120+
"blockDelete": block_delete,
121+
"blockEdit": block_edit,
122+
"syncToItems": sync_to_items,
123+
}
124+
binding_type = SPPolicyStoreProxy(context)
125+
qry = ServiceOperationQuery(
126+
binding_type,
127+
"SetListComplianceTag",
128+
None,
129+
payload,
130+
None,
131+
None,
132+
True,
133+
)
134+
context.add_query(qry)
135+
return binding_type
136+
137+
@staticmethod
138+
def lock_record_item(
139+
context, list_url, item_id, refresh_labeled_time, return_type=None
140+
):
141+
""" """
142+
if return_type is None:
143+
return_type = ClientResult(context, int())
144+
payload = {
145+
"listUrl": list_url,
146+
"itemId": item_id,
147+
"refreshLabeledTime": refresh_labeled_time,
148+
}
149+
150+
qry = ServiceOperationQuery(
151+
SPPolicyStoreProxy(context),
152+
"LockRecordItem",
153+
None,
154+
payload,
155+
None,
156+
return_type,
157+
True,
158+
)
159+
context.add_query(qry)
160+
return return_type
161+
87162
@property
88163
def entity_type_name(self):
89164
return "SP.CompliancePolicy.SPPolicyStoreProxy"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.sharepoint.entity import Entity
2+
3+
4+
class MigrationCompleteStateApi(Entity):
5+
""""""
6+
7+
@property
8+
def entity_type_name(self):
9+
return "Microsoft.SharePoint.Convergence.MigrationCompleteStateApi"

office365/sharepoint/files/collection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from office365.sharepoint.entity_collection import EntityCollection
1212
from office365.sharepoint.files.creation_information import FileCreationInformation
1313
from office365.sharepoint.files.file import File
14+
from office365.sharepoint.files.publish.status import FileStatus
1415
from office365.sharepoint.types.resource_path import ResourcePath as SPResPath
1516

1617
if TYPE_CHECKING:
@@ -24,6 +25,15 @@ def __init__(self, context, resource_path=None, parent=None):
2425
# type: (ClientContext, ResourcePath, Folder) -> None
2526
super(FileCollection, self).__init__(context, File, resource_path, parent)
2627

28+
def get_published_file(self, base_file_path):
29+
""" """
30+
return_type = FileStatus(self.context)
31+
qry = ServiceOperationQuery(
32+
self, "GetPublishedFile", [base_file_path], None, None, return_type
33+
)
34+
self.context.add_query(qry)
35+
return return_type
36+
2737
def upload(self, path_or_file, file_name=None):
2838
# type: (str|IO, str) -> File
2939
"""Uploads a file into folder.

0 commit comments

Comments
 (0)