|
1 | 1 | from office365.runtime.clientValueCollection import ClientValueCollection
|
2 | 2 | from office365.runtime.client_query import UpdateEntityQuery, DeleteEntityQuery
|
| 3 | +from office365.runtime.client_result import ClientResult |
3 | 4 | from office365.runtime.resource_path import ResourcePath
|
4 | 5 | from office365.runtime.resource_path_service_operation import ResourcePathServiceOperation
|
5 | 6 | from office365.runtime.queries.serviceOperationQuery import ServiceOperationQuery
|
6 | 7 | from office365.sharepoint.fields.fieldLookupValue import FieldLookupValue
|
7 | 8 | from office365.sharepoint.fields.fieldMultiLookupValue import FieldMultiLookupValue
|
8 | 9 | from office365.sharepoint.permissions.securable_object import SecurableObject
|
| 10 | +from office365.sharepoint.sharing.externalSharingSiteOption import ExternalSharingSiteOption |
| 11 | +from office365.sharepoint.sharing.objectSharingInformation import ObjectSharingInformation |
| 12 | +from office365.sharepoint.sharing.sharingResult import SharingResult |
| 13 | +from office365.sharepoint.ui.applicationpages.clientPeoplePickerQueryParameters import ClientPeoplePickerQueryParameters |
| 14 | +from office365.sharepoint.ui.applicationpages.clientPeoplePickerWebServiceInterface import \ |
| 15 | + ClientPeoplePickerWebServiceInterface |
9 | 16 |
|
10 | 17 |
|
11 | 18 | class ListItem(SecurableObject):
|
12 | 19 | """ListItem resource"""
|
13 | 20 |
|
| 21 | + def share(self, user_principal_name, |
| 22 | + shareOption=ExternalSharingSiteOption.View, |
| 23 | + sendEmail=True, emailSubject=None, emailBody=None): |
| 24 | + """ |
| 25 | + Share a ListItem (file or folder facet) |
| 26 | +
|
| 27 | + :param str user_principal_name: User identifier |
| 28 | + :param ExternalSharingSiteOption shareOption: The sharing type of permission to grant on the object. |
| 29 | + :param bool sendEmail: A flag to determine if an email notification SHOULD be sent (if email is configured). |
| 30 | + :param str emailSubject: The email subject. |
| 31 | + :param str emailBody: The email subject. |
| 32 | + :return: SharingResult |
| 33 | + """ |
| 34 | + |
| 35 | + result = ClientResult(SharingResult(self.context)) |
| 36 | + file_result = ClientResult(str) |
| 37 | + |
| 38 | + role_values = { |
| 39 | + ExternalSharingSiteOption.View: "role:1073741826", |
| 40 | + ExternalSharingSiteOption.Edit: "role:1073741827", |
| 41 | + } |
| 42 | + |
| 43 | + def _property_resolved(target_item): |
| 44 | + file_result.value = target_item.get_property("EncodedAbsUrl") |
| 45 | + |
| 46 | + def _picker_value_resolved(picker_value): |
| 47 | + from office365.sharepoint.webs.web import Web |
| 48 | + result.value = Web.share_object(self.context, file_result.value, picker_value, role_values[shareOption], |
| 49 | + 0, |
| 50 | + False, sendEmail, False, emailSubject, emailBody) |
| 51 | + |
| 52 | + self.ensure_property("EncodedAbsUrl", _property_resolved) |
| 53 | + params = ClientPeoplePickerQueryParameters(user_principal_name) |
| 54 | + ClientPeoplePickerWebServiceInterface.client_people_picker_resolve_user(self.context, |
| 55 | + params, _picker_value_resolved) |
| 56 | + return result.value |
| 57 | + |
| 58 | + def unshare(self): |
| 59 | + """ |
| 60 | + Share a ListItem (file or folder facet) |
| 61 | + """ |
| 62 | + result = ClientResult(SharingResult(self.context)) |
| 63 | + |
| 64 | + def _property_resolved(target_item): |
| 65 | + abs_url = target_item.get_property("EncodedAbsUrl") |
| 66 | + from office365.sharepoint.webs.web import Web |
| 67 | + result.value = Web.unshare_object(self.context, abs_url) |
| 68 | + |
| 69 | + self.ensure_property("EncodedAbsUrl", _property_resolved) |
| 70 | + return result.value |
| 71 | + |
| 72 | + def get_sharing_information(self): |
| 73 | + result = ClientResult(ObjectSharingInformation(self.context)) |
| 74 | + |
| 75 | + def _item_resolved(return_type): |
| 76 | + result.value = ObjectSharingInformation.get_list_item_sharing_information( |
| 77 | + self.context, return_type.parentList.properties["Id"], return_type.properties["Id"]) |
| 78 | + |
| 79 | + self.ensure_property(["Id", "ParentList"], _item_resolved) |
| 80 | + return result.value |
| 81 | + |
14 | 82 | def update(self):
|
15 | 83 | """Update the list item."""
|
16 | 84 | self.ensure_type_name(self.parentList)
|
@@ -89,8 +157,6 @@ def set_property(self, name, value, persist_changes=True):
|
89 | 157 | if name == "Id" and self._parent_collection:
|
90 | 158 | self._resource_path = ResourcePathServiceOperation(
|
91 | 159 | "getItemById", [value], self._parent_collection.resource_path.parent)
|
92 |
| - elif name == "GUID": |
93 |
| - self._resource_path = ResourcePathServiceOperation("GetFileById", [value], self.context.web.resource_path) |
94 | 160 |
|
95 | 161 | def ensure_type_name(self, target_list):
|
96 | 162 | """
|
|
0 commit comments